Ask Your Question
3

How can I use Auth0 and Supertest to receive a status code of 204 instead of 200?

asked 2022-01-10 11:00:00 +0000

scrum gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2022-06-15 10:00:00 +0000

ladyg gravatar image

To receive a status code of 204 instead of 200 using Auth0 and Supertest, you can modify your test case to include an assertion that checks for the status code. Here's an example:

const request = require('supertest');
const app = require('../app');

describe('GET /users', () => {
  it('returns a 204 status code', (done) => {
    request(app)
      .get('/users')
      .set('Authorization', 'Bearer YOUR_AUTH0_ACCESS_TOKEN')
      .expect(204)
      .end((err, res) => {
        if (err) return done(err);
        done();
      });
  });
});

In this example, we're sending a GET request to the /users endpoint with an Auth0 access token. We're also expecting a status code of 204 in the response. If the status code is not 204, Supertest will throw an error and the test will fail.

Make sure to replace YOURAUTH0ACCESS_TOKEN with an actual access token from your Auth0 application.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2022-01-10 11:00:00 +0000

Seen: 9 times

Last updated: Jun 15 '22