This repository has been archived on 2024-10-29. You can view files and clone it, but cannot push or open issues or pull requests.
api/generators/service/service.test.ts.hbs

40 lines
1023 B
Handlebars
Raw 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
})
})