eletrotupi / tcc/ api/tests/middleware/request-id.test.ts38004a30fcf3fc21f8954a0179705ede8a78a57e
615 B | 21 lines Raw
1
import { describe, it, expect } from 'vitest'
2
import request from 'supertest'
3
import { createApp } from '@app/createApp'
4

5
const app = createApp()
6

7
describe('request id', () => {
8
  it('echoes an inbound X-Request-Id back on the response', async () => {
9
    const res = await request(app)
10
      .get('/moods')
11
      .set('X-Request-Id', 'test-request-id')
12

13
    expect(res.headers['x-request-id']).toBe('test-request-id')
14
  })
15

16
  it('generates a request id when the client does not send one', async () => {
17
    const res = await request(app).get('/moods')
18

19
    expect(res.headers['x-request-id']).toBeTruthy()
20
  })
21
})