32 lines
1.3 KiB
JavaScript
32 lines
1.3 KiB
JavaScript
|
|
import { describe, it, expect } from 'vitest'
|
||
|
|
import { server, http, HttpResponse } from './test-setup'
|
||
|
|
import { getCurrentShoppingList, getShoppingList, requestMeal, unrequestMeal, purchaseShoppingList } from '@/api/sdk'
|
||
|
|
|
||
|
|
describe('shopping api (typed client)', () => {
|
||
|
|
it('gets current shopping list', async () => {
|
||
|
|
server.use(http.get('*/api/v1/shopping/current', () => HttpResponse.json({ outstandingItems: [] })))
|
||
|
|
const list = await getCurrentShoppingList()
|
||
|
|
expect(list).toBeTruthy()
|
||
|
|
})
|
||
|
|
|
||
|
|
it('gets a purchased shopping list by id', async () => {
|
||
|
|
server.use(http.get('*/api/v1/shopping/:id', () => HttpResponse.json({ list: { id: 99, items: [] } })))
|
||
|
|
const list = await getShoppingList(99)
|
||
|
|
expect(list.id).toBe(99)
|
||
|
|
})
|
||
|
|
|
||
|
|
it('requests and unrequests a meal', async () => {
|
||
|
|
server.use(http.post('*/api/v1/shopping/current/meals/me', () => HttpResponse.json([{ id: 1 }])))
|
||
|
|
await requestMeal(44)
|
||
|
|
|
||
|
|
server.use(http.delete('*/api/v1/shopping/current/meals/:id', () => new HttpResponse(null, { status: 204 })))
|
||
|
|
await unrequestMeal(44)
|
||
|
|
})
|
||
|
|
|
||
|
|
it('purchases a list', async () => {
|
||
|
|
server.use(http.post('*/api/v1/shopping', () => HttpResponse.json({ list: { id: 1, items: [] } })))
|
||
|
|
const list = await purchaseShoppingList([{ type: 'existing', id: 1, personId: 42 }])
|
||
|
|
expect(list.id).toBe(1)
|
||
|
|
})
|
||
|
|
})
|