500 error and not details when running jest supertest with express

1.2k views Asked by At

I'm trying to add jest acceptance testing into an API repo (currently there are jest unit tests). The app is serverless aws. I'm working on getting a rough working p.o.c. API test against a staging url and I've put together this test file but it isn't working as expected and I don't have details to go on. I'd like to know how to return more details for a failure or what I'm missing to get it to hit the route as expected.

I'm returning 500 errors, but no real extra details. If I input an empty/invalid jwt token - still returns 500. If I remove the expect(response.status).toEqual(200); it "passes" but the console.log("blah blah blah here" + response); fails to show the response (or the "blah blah blah" for that matter). How can I return more details to see what I may be missing? Or adjust my request so it successfully hits that route and returns a better response?

My auth_impersonation p.o.c. test

import { agent as request } from 'supertest';
import express = require('express');

describe('Impersonate SE merchant', () => {
  let app: express.Application = express();
  let jwtToken = 'string I'm putting in manually for now';

  it('returns a valid access token', async () => {
// within it block attempts here (below)

    const response = await request(app)
      .get('full staging url string here')
      .auth(jwtToken, {type: 'bearer'}); 
      console.log("blah blah blah here" + response);
    // expect(response.status).toEqual(200);
  })
});

Here's how the request looks in postman where the route works enter image description here

Another go of the postman request, headers enter image description here

0

There are 0 answers