1
0
Fork 0
mirror of https://github.com/kou029w/_.git synced 2025-01-31 06:18:07 +00:00
_/frourio/server/test/server.test.ts

36 lines
941 B
TypeScript
Raw Normal View History

2020-11-19 16:16:33 +09:00
import controller from '$/api/tasks/controller'
import { getTasks } from '$/service/tasks'
test('dependency injection into controller', async () => {
let printedMessage = ''
const injectedController = controller.inject({
getTasks: getTasks.inject({
prisma: {
task: {
findMany: () =>
Promise.resolve([
{ id: 0, label: 'task1', done: false },
{ id: 1, label: 'task2', done: false },
{ id: 2, label: 'task3', done: true },
{ id: 3, label: 'task4', done: true },
{ id: 4, label: 'task5', done: false }
])
}
}
}),
print: (text: string) => {
printedMessage = text
}
})()
const limit = 3
const message = 'test message'
const res = await injectedController.get({
query: { limit, message }
})
expect(res.body).toHaveLength(limit)
expect(printedMessage).toBe(message)
})