Skip to content

Commit e615e03

Browse files
authored
Merge pull request #188 from utaipei-sa/urb-88-get-items-test
Add test for GET /reserve/items
2 parents ac3a75b + d149bf1 commit e615e03

1 file changed

Lines changed: 43 additions & 0 deletions

File tree

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import express from 'express'
2+
import request from 'supertest'
3+
import { jest, describe, it, expect, beforeEach } from '@jest/globals'
4+
import router from '../../../routes/reserve/get_items.js'
5+
import ItemRepository from '../../../repositories/item_repository.js'
6+
7+
const app = express()
8+
app.use(express.json())
9+
app.use('/reserve', router)
10+
11+
describe('GET /reserve/items', () => {
12+
beforeEach(() => {
13+
jest.restoreAllMocks()
14+
})
15+
16+
it('should return all items data in DB', async () => {
17+
const mockItems = [
18+
{
19+
_id: '67399cd504b112e42be95b18',
20+
name: {
21+
'zh-tw': '塑膠椅',
22+
en: 'Plastic Chairs'
23+
},
24+
quantity: 30,
25+
exception_time: []
26+
},
27+
{
28+
_id: '67399cd504b112e42be95b19',
29+
name: {
30+
'zh-tw': '長桌',
31+
en: 'Tables'
32+
},
33+
quantity: 2,
34+
exception_time: []
35+
}
36+
]
37+
jest.spyOn(ItemRepository, 'getAllItems').mockResolvedValue(mockItems)
38+
39+
const response = await request(app).get('/reserve/items')
40+
expect(response.status).toBe(200)
41+
expect(response.body).toEqual({ data: mockItems })
42+
})
43+
})

0 commit comments

Comments
 (0)