feat: 创建数据库

This commit is contained in:
R524809
2026-10-12 16:56:42 +08:00
parent 3c6fd2c8ca
commit 63a6993276
35 changed files with 826 additions and 266 deletions
+26 -26
View File
@@ -6,32 +6,32 @@ 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 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 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);
const unversioned = await fetch(`${origin}/health`, {
signal: AbortSignal.timeout(5000),
});
assert.equal(unversioned.status, 404);
});
+12 -12
View File
@@ -3,25 +3,25 @@ import { test } from 'node:test';
import { getRuntimeOptions } from '../src/common/runtime-options';
test('使用本地默认 host 和 port', () => {
assert.deepEqual(getRuntimeOptions({}), {
host: '127.0.0.1',
port: 3000,
});
assert.deepEqual(getRuntimeOptions({}), {
host: '127.0.0.1',
port: 3000,
});
});
test('读取显式 host 和 port', () => {
assert.deepEqual(getRuntimeOptions({ HOST: '0.0.0.0', PORT: '4000' }), {
host: '0.0.0.0',
port: 4000,
});
assert.deepEqual(getRuntimeOptions({ HOST: '0.0.0.0', PORT: '4000' }), {
host: '0.0.0.0',
port: 4000,
});
});
test('拒绝非法端口', () => {
for (const port of ['', '0', '65536', '-1', '3000abc', '3.5', '1e3']) {
assert.throws(() => getRuntimeOptions({ PORT: port }), /PORT/);
}
for (const port of ['', '0', '65536', '-1', '3000abc', '3.5', '1e3']) {
assert.throws(() => getRuntimeOptions({ PORT: port }), /PORT/);
}
});
test('拒绝空 host', () => {
assert.throws(() => getRuntimeOptions({ HOST: ' ' }), /HOST/);
assert.throws(() => getRuntimeOptions({ HOST: ' ' }), /HOST/);
});