27 lines
870 B
TypeScript
27 lines
870 B
TypeScript
import { afterAll, afterEach, beforeAll, describe, expect, test, vi } from 'vitest'
|
|
import { serverOf } from '../src/server'
|
|
import * as TodoRepo from '../src/repo/todo'
|
|
|
|
describe('Todo API Testing', () => {
|
|
const server = serverOf()
|
|
|
|
afterEach(() => {
|
|
vi.resetAllMocks()
|
|
})
|
|
|
|
test('Given an empty array return from repo function, When send a GET request to /api/v1/todos, Then it should response an empty array', async () => {
|
|
// assert: stub the repo function to return an empty array
|
|
vi.spyOn(TodoRepo, 'findAllTodos').mockImplementation(async () => [])
|
|
|
|
// act: send a GET request to /api/v1/todos
|
|
const response = await server.inject({
|
|
method: 'GET',
|
|
url: '/api/v1/todos'
|
|
})
|
|
|
|
// assert: response should be an empty array
|
|
const todos = JSON.parse(response.body)['todos']
|
|
expect(todos).toStrictEqual([])
|
|
})
|
|
})
|