-
Notifications
You must be signed in to change notification settings - Fork 19
/
app.test.js
51 lines (39 loc) · 1.23 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
// app.test.js
const request = require('supertest');
const axios = require('axios');
const BookingsStore = require('./bookingsStore');
let app;
let mockStore;
jest.mock('axios');
jest.mock('./bookingsStore');
beforeEach(() => {
// Mock the BookingsStore methods
BookingsStore.prototype.getUserBookings = jest.fn();
BookingsStore.prototype.addBooking = jest.fn();
// Create an instance of BookingsStore
mockStore = new BookingsStore();
// Clear axios mocks
axios.get.mockClear();
app = require('./app')(mockStore);
});
test('GET /bookings returns bookings for user', async () => {
const mockBookings = [
{
ticket_number:"RIN74XEJWG",
seat:"18A",
flight:{
number:"KA0288",
route_id:"LHR-BOM",
scheduled_arrival:"2024-02-13T09:30:00Z",
scheduled_departure:"2024-02-13T18:40:00Z"
}
}
];
mockStore.getUserBookings.mockReturnValue(mockBookings);
const jwt='eyJ0eXAiOiJKV1QiLCJhbGciOiJub25lIn0.eyJ1c2VybmFtZSI6ImRmcmVlc2UifQ'
const res = await request(app)
.get('/bookings').set('Authorization', `Bearer ${jwt}`);
expect(res.statusCode).toEqual(200);
expect(res.body).toEqual(mockBookings);
expect(mockStore.getUserBookings).toHaveBeenCalledTimes(1);
});