38 lines
1.2 KiB
TypeScript
38 lines
1.2 KiB
TypeScript
import 'reflect-metadata';
|
|
import assert from 'node:assert/strict';
|
|
import { test } from 'node:test';
|
|
import { Test } from '@nestjs/testing';
|
|
import { AppModule } from '../src/app.module';
|
|
import { configureApplication } from '../src/app.setup';
|
|
|
|
test('服务可以启动并通过带版本前缀的 HTTP 健康检查', async (context) => {
|
|
const testingModule = await Test.createTestingModule({
|
|
imports: [AppModule],
|
|
}).compile();
|
|
const app = testingModule.createNestApplication({ logger: false });
|
|
context.after(async () => {
|
|
await app.close();
|
|
});
|
|
configureApplication(app);
|
|
await app.listen(0, '127.0.0.1');
|
|
const origin = await app.getUrl();
|
|
|
|
const response = await fetch(`${origin}/api/v1/health`, {
|
|
signal: AbortSignal.timeout(5000),
|
|
});
|
|
assert.equal(response.status, 200);
|
|
assert.deepEqual(await response.json(), {
|
|
code: 0,
|
|
message: 'ok',
|
|
data: {
|
|
status: 'ok',
|
|
service: 'doodle-store-server',
|
|
},
|
|
});
|
|
|
|
const unversioned = await fetch(`${origin}/health`, {
|
|
signal: AbortSignal.timeout(5000),
|
|
});
|
|
assert.equal(unversioned.status, 404);
|
|
});
|