-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.test.js
54 lines (45 loc) · 1.73 KB
/
app.test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
const mockGetGiftsResp1 = [{"mockGiftId1": "abc1"}];
const mockGetGiftsResp2 = [{"mockGiftId2": "abc2"}];
const mockGetGiftsV1 = jest.fn((req, res) => res.json(mockGetGiftsResp1));
const mockGetGiftsV2 = jest.fn((req, res) => res.json(mockGetGiftsResp2));
jest.mock('./src/middlewares/authMiddleware',() => (req, res, next) => next());
jest.mock('./src/controllers/v1/giftControllers', () => ({
getGifts: mockGetGiftsV1,
}));
jest.mock('./src/controllers/v2/giftControllers', () => ({
getGifts: mockGetGiftsV2,
}));
const request = require('supertest');
const app = require('./app');
describe('should have app()', () => {
beforeEach(() => {
mockGetGiftsV1.mockClear();
mockGetGiftsV2.mockClear();
})
it('exports a route /v1/gifts', () => {
return request(app)
.get('/v1/gifts')
.set('x-apigateway-event','1231')
.set('x-apigateway-context','1231')
.expect('Content-Type', /json/)
.expect(200)
.then(response => {
expect(mockGetGiftsV1).toHaveBeenCalledTimes(1);
expect(mockGetGiftsV2).toHaveBeenCalledTimes(0);
expect(response.body).toEqual(mockGetGiftsResp1);
})
})
it('exports a route /v2/gifts', () => {
return request(app)
.get('/v2/gifts')
.set('x-apigateway-event','1231')
.set('x-apigateway-context','1231')
.expect('Content-Type', /json/)
.expect(200)
.then(response => {
expect(mockGetGiftsV2).toHaveBeenCalledTimes(1);
expect(mockGetGiftsV1).toHaveBeenCalledTimes(0);
expect(response.body).toEqual(mockGetGiftsResp2);
})
})
})