- add jest, ts-jest, supertest, and related dev dependencies - add test scripts (test, test:debug, test:watch) to package.json - add jest.config.js with ts-jest transform and module name mappers - add controller specs for auth, browser, environment, mcp, scenario, session - add mocks for jsdom, playwright, and readability - add test/tsconfig.json and exclude test dir from main tsconfig
62 lines
2.1 KiB
TypeScript
62 lines
2.1 KiB
TypeScript
import { INestApplication } from '@nestjs/common';
|
|
import request from 'supertest';
|
|
import { buildTestApp } from './app.harness';
|
|
|
|
/**
|
|
* Auth controller integration tests.
|
|
*
|
|
* The login endpoint requires a live browser + real key files, so it is not
|
|
* exercised here (those belong to e2e tests with real credentials).
|
|
* We cover the parts that can be tested without external dependencies.
|
|
*/
|
|
describe('AuthController', () => {
|
|
let app: INestApplication;
|
|
|
|
beforeAll(async () => {
|
|
app = await buildTestApp();
|
|
});
|
|
|
|
afterAll(async () => {
|
|
await app.close();
|
|
});
|
|
|
|
// ── GET /keys ──────────────────────────────────────────────────────────────
|
|
|
|
describe('GET /keys', () => {
|
|
it('returns 200 with a keys array', async () => {
|
|
const res = await request(app.getHttpServer()).get('/keys').expect(200);
|
|
expect(res.body).toHaveProperty('keys');
|
|
expect(Array.isArray(res.body.keys)).toBe(true);
|
|
});
|
|
});
|
|
|
|
// ── POST /login ────────────────────────────────────────────────────────────
|
|
|
|
describe('POST /login', () => {
|
|
it('returns 400 when body is empty', async () => {
|
|
await request(app.getHttpServer()).post('/login').send({}).expect(400);
|
|
});
|
|
|
|
it('returns 400 when key is missing', async () => {
|
|
await request(app.getHttpServer())
|
|
.post('/login')
|
|
.send({ environmentName: 'test-env' })
|
|
.expect(400);
|
|
});
|
|
|
|
it('returns 400 when environmentName is missing', async () => {
|
|
await request(app.getHttpServer())
|
|
.post('/login')
|
|
.send({ key: 'some-key' })
|
|
.expect(400);
|
|
});
|
|
|
|
it('returns 400 when key file does not exist', async () => {
|
|
await request(app.getHttpServer())
|
|
.post('/login')
|
|
.send({ key: 'nonexistent-key', environmentName: 'test-env' })
|
|
.expect(404); // NotFoundException for missing environment
|
|
});
|
|
});
|
|
});
|