init
This commit is contained in:
26
backend/test/todo.spec.ts
Normal file
26
backend/test/todo.spec.ts
Normal file
@@ -0,0 +1,26 @@
|
||||
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([])
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user