mirror of
https://github.com/kou029w/_.git
synced 2025-01-31 06:18:07 +00:00
35 lines
941 B
TypeScript
35 lines
941 B
TypeScript
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)
|
|
})
|