test(integration): add lightweight MySQL-backed API smoke tests for center and guild
This commit is contained in:
43
Fabric.Backend.Guild/src/health.integration.spec.ts
Normal file
43
Fabric.Backend.Guild/src/health.integration.spec.ts
Normal file
@@ -0,0 +1,43 @@
|
||||
import { INestApplication } from '@nestjs/common';
|
||||
import { Test } from '@nestjs/testing';
|
||||
import request from 'supertest';
|
||||
import { afterAll, beforeAll, describe, expect, it } from 'vitest';
|
||||
|
||||
process.env.DB_HOST = '127.0.0.1';
|
||||
process.env.DB_PORT = '3308';
|
||||
process.env.DB_USER = 'fabric';
|
||||
process.env.DB_PASSWORD = 'fabric';
|
||||
process.env.DB_NAME = 'fabric_guild';
|
||||
process.env.DB_SYNC = 'false';
|
||||
process.env.FABRIC_API_KEY = 'test-api-key';
|
||||
|
||||
describe('guild integration (mysql + api)', () => {
|
||||
let app: INestApplication;
|
||||
|
||||
beforeAll(async () => {
|
||||
const { AppModule } = await import('./app.module');
|
||||
const moduleRef = await Test.createTestingModule({
|
||||
imports: [AppModule],
|
||||
}).compile();
|
||||
|
||||
app = moduleRef.createNestApplication();
|
||||
app.setGlobalPrefix('api');
|
||||
await app.init();
|
||||
}, 30000);
|
||||
|
||||
afterAll(async () => {
|
||||
if (app) await app.close();
|
||||
});
|
||||
|
||||
it('GET /api/healthz returns db ready', async () => {
|
||||
const res = await request(app.getHttpServer()).get('/api/healthz');
|
||||
expect(res.status).toBe(200);
|
||||
expect(res.body.ok).toBe(true);
|
||||
expect(res.body.service).toBe('guild');
|
||||
});
|
||||
|
||||
it('protects non-health endpoints by x-api-key', async () => {
|
||||
const res = await request(app.getHttpServer()).get('/api/channels/non-exist/messages');
|
||||
expect(res.status).toBe(401);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user