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

40 lines
1023 B
Handlebars
Raw Permalink Normal View History

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