- move NestJS app into server/ subdirectory - add client/ React+TypeScript (Vite) app with Hello World - update docker-compose to build and run both services - add root package.json declaring npm workspaces - update .gitignore to cover node_modules and dist at all depths
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
|
|
});
|
|
});
|
|
});
|