2
1
mirror of https://github.com/Thream/api.git synced 2024-07-06 21:00:11 +02:00
api/generators/service/service.test.ts.hbs

40 lines
1023 B
Handlebars

import test from 'node:test'
import assert from 'node:assert/strict'
import sinon from 'sinon'
import { application } from '#src/application.js'
{{#if shouldBeAuthenticated}}
import { authenticateUserTest } from '#src/__test__/utils/authenticateUserTest.js'
{{/if}}
import prisma from '#src/tools/database/prisma.js'
await test('{{httpMethod}} {{url}}', async (t) => {
t.afterEach(() => {
sinon.restore()
})
await t.test('succeeds', async () => {
{{#if shouldBeAuthenticated}}
const { accessToken } = await authenticateUserTest()
{{/if}}
sinon.stub(prisma, 'channel').value({
findFirst: async () => {
return null
}
})
const response = await application.inject({
method: '{{httpMethod}}',
url: '{{url}}',
{{#if shouldBeAuthenticated}}
headers: {
authorization: `Bearer ${accessToken}`
},
{{/if}}
payload: {}
})
// const responseJson = response.json()
assert.strictEqual(response.statusCode, 200)
})
})