refactor(auth): remove keys auth module and align tests
- remove server auth module and client keys page/routes/api to simplify flow - update mcp and scenario tests to match uuid routes and step schema
This commit is contained in:
@@ -21,24 +21,23 @@ describe("ScenarioController", () => {
|
||||
.post("/scenarios")
|
||||
.send({ name })
|
||||
.expect(201);
|
||||
return res.body as { id: number; name: string };
|
||||
return res.body as { id: string; name: string };
|
||||
}
|
||||
|
||||
async function createStep(
|
||||
scenarioId: number,
|
||||
scenarioId: string,
|
||||
overrides: Record<string, unknown> = {},
|
||||
) {
|
||||
const res = await request(app.getHttpServer())
|
||||
.post(`/scenarios/${scenarioId}/steps`)
|
||||
.send({
|
||||
order: 0,
|
||||
type: "exec",
|
||||
sessionName: "test-session",
|
||||
execCode: "return 1;",
|
||||
...overrides,
|
||||
})
|
||||
.expect(201);
|
||||
return res.body as { id: number };
|
||||
return res.body as { id: string };
|
||||
}
|
||||
|
||||
// ── POST /scenarios ────────────────────────────────────────────────────────
|
||||
@@ -142,7 +141,7 @@ describe("ScenarioController", () => {
|
||||
});
|
||||
|
||||
it("returns 404 for unknown id", async () => {
|
||||
await request(app.getHttpServer()).get("/scenarios/99999").expect(404);
|
||||
await request(app.getHttpServer()).get("/scenarios/00000000-0000-0000-0000-000000000001").expect(404);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -160,7 +159,7 @@ describe("ScenarioController", () => {
|
||||
|
||||
it("returns 404 for unknown id", async () => {
|
||||
await request(app.getHttpServer())
|
||||
.patch("/scenarios/99999")
|
||||
.patch("/scenarios/00000000-0000-0000-0000-000000000001")
|
||||
.send({ name: "x" })
|
||||
.expect(404);
|
||||
});
|
||||
@@ -178,7 +177,7 @@ describe("ScenarioController", () => {
|
||||
});
|
||||
|
||||
it("returns 404 for unknown id", async () => {
|
||||
await request(app.getHttpServer()).delete("/scenarios/99999").expect(404);
|
||||
await request(app.getHttpServer()).delete("/scenarios/00000000-0000-0000-0000-000000000001").expect(404);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -191,7 +190,6 @@ describe("ScenarioController", () => {
|
||||
.post(`/scenarios/${sc.id}/steps`)
|
||||
.send({
|
||||
order: 0,
|
||||
type: "exec",
|
||||
sessionName: "my-session",
|
||||
execCode: "return 1;",
|
||||
})
|
||||
@@ -199,48 +197,50 @@ describe("ScenarioController", () => {
|
||||
|
||||
expect(res.body.id).toBeDefined();
|
||||
expect(res.body.order).toBe(0);
|
||||
expect(res.body.type).toBe("exec");
|
||||
expect(res.body.sessionName).toBe("my-session");
|
||||
});
|
||||
|
||||
it("creates a login step", async () => {
|
||||
it("creates a step without execCode", async () => {
|
||||
const sc = await createScenario();
|
||||
const res = await request(app.getHttpServer())
|
||||
.post(`/scenarios/${sc.id}/steps`)
|
||||
.send({ order: 0, type: "login", sessionName: "session-x" })
|
||||
.send({ order: 0, sessionName: "session-x" })
|
||||
.expect(201);
|
||||
|
||||
expect(res.body.type).toBe("login");
|
||||
expect(res.body.sessionName).toBe("session-x");
|
||||
expect(res.body.execCode).toBeNull();
|
||||
});
|
||||
|
||||
it("returns 400 when order is missing", async () => {
|
||||
const sc = await createScenario();
|
||||
await request(app.getHttpServer())
|
||||
.post(`/scenarios/${sc.id}/steps`)
|
||||
.send({ type: "exec", sessionName: "x" })
|
||||
.send({ sessionName: "x" })
|
||||
.expect(400);
|
||||
});
|
||||
|
||||
it("returns 400 when type is invalid", async () => {
|
||||
it("ignores unknown fields in payload", async () => {
|
||||
const sc = await createScenario();
|
||||
await request(app.getHttpServer())
|
||||
const res = await request(app.getHttpServer())
|
||||
.post(`/scenarios/${sc.id}/steps`)
|
||||
.send({ order: 0, type: "unknown", sessionName: "x" })
|
||||
.expect(400);
|
||||
.expect(201);
|
||||
|
||||
expect(res.body).not.toHaveProperty("type");
|
||||
});
|
||||
|
||||
it("returns 400 when sessionName is missing", async () => {
|
||||
it("allows missing sessionName", async () => {
|
||||
const sc = await createScenario();
|
||||
await request(app.getHttpServer())
|
||||
.post(`/scenarios/${sc.id}/steps`)
|
||||
.send({ order: 0, type: "exec" })
|
||||
.expect(400);
|
||||
.send({ order: 0, execCode: "return 1;" })
|
||||
.expect(201);
|
||||
});
|
||||
|
||||
it("returns 404 for unknown scenario", async () => {
|
||||
await request(app.getHttpServer())
|
||||
.post("/scenarios/99999/steps")
|
||||
.send({ order: 0, type: "exec", sessionName: "x" })
|
||||
.post("/scenarios/00000000-0000-0000-0000-000000000001/steps")
|
||||
.send({ order: 0, sessionName: "x" })
|
||||
.expect(404);
|
||||
});
|
||||
|
||||
@@ -276,7 +276,7 @@ describe("ScenarioController", () => {
|
||||
it("returns 404 for unknown step", async () => {
|
||||
const sc = await createScenario();
|
||||
await request(app.getHttpServer())
|
||||
.get(`/scenarios/${sc.id}/steps/99999`)
|
||||
.get(`/scenarios/${sc.id}/steps/00000000-0000-0000-0000-000000000001`)
|
||||
.expect(404);
|
||||
});
|
||||
});
|
||||
@@ -300,7 +300,7 @@ describe("ScenarioController", () => {
|
||||
it("returns 404 for unknown step", async () => {
|
||||
const sc = await createScenario();
|
||||
await request(app.getHttpServer())
|
||||
.patch(`/scenarios/${sc.id}/steps/99999`)
|
||||
.patch(`/scenarios/${sc.id}/steps/00000000-0000-0000-0000-000000000001`)
|
||||
.send({ order: 1 })
|
||||
.expect(404);
|
||||
});
|
||||
@@ -350,7 +350,7 @@ describe("ScenarioController", () => {
|
||||
|
||||
it("returns 404 for unknown scenario", async () => {
|
||||
await request(app.getHttpServer())
|
||||
.post("/scenarios/99999/run")
|
||||
.post("/scenarios/00000000-0000-0000-0000-000000000001/run")
|
||||
.expect(404);
|
||||
});
|
||||
});
|
||||
@@ -405,7 +405,7 @@ describe("ScenarioController", () => {
|
||||
|
||||
it("returns 404 for unknown scenario", async () => {
|
||||
await request(app.getHttpServer())
|
||||
.get("/scenarios/99999/runs")
|
||||
.get("/scenarios/00000000-0000-0000-0000-000000000001/runs")
|
||||
.expect(404);
|
||||
});
|
||||
});
|
||||
@@ -417,13 +417,11 @@ describe("ScenarioController", () => {
|
||||
const sc = await createScenario("export-me");
|
||||
await createStep(sc.id, {
|
||||
order: 0,
|
||||
type: "login",
|
||||
sessionName: "s",
|
||||
execCode: '{"keyId":"k","environmentName":"e"}',
|
||||
});
|
||||
await createStep(sc.id, {
|
||||
order: 1,
|
||||
type: "exec",
|
||||
sessionName: "s",
|
||||
execCode: "return 1;",
|
||||
validateCode: "return true;",
|
||||
@@ -484,7 +482,7 @@ describe("ScenarioController", () => {
|
||||
|
||||
it("returns 404 for unknown scenario", async () => {
|
||||
await request(app.getHttpServer())
|
||||
.get("/scenarios/99999/export")
|
||||
.get("/scenarios/00000000-0000-0000-0000-000000000001/export")
|
||||
.expect(404);
|
||||
});
|
||||
});
|
||||
@@ -498,21 +496,18 @@ describe("ScenarioController", () => {
|
||||
steps: [
|
||||
{
|
||||
order: 0,
|
||||
type: "login",
|
||||
sessionName: "s",
|
||||
execCode: '{"keyId":"k","environmentName":"e"}',
|
||||
validateCode: null,
|
||||
},
|
||||
{
|
||||
order: 1,
|
||||
type: "exec",
|
||||
sessionName: "s",
|
||||
execCode: "return 1;",
|
||||
validateCode: "return true;",
|
||||
},
|
||||
{
|
||||
order: 2,
|
||||
type: "sign",
|
||||
sessionName: "s",
|
||||
execCode: '{"keyId":"k"}',
|
||||
validateCode: null,
|
||||
@@ -528,12 +523,9 @@ describe("ScenarioController", () => {
|
||||
expect(res.body.id).toBeDefined();
|
||||
expect(res.body.name).toBe("imported scenario");
|
||||
expect(res.body.steps).toHaveLength(3);
|
||||
expect(res.body.steps[0].type).toBe("login");
|
||||
expect(res.body.steps[1].type).toBe("exec");
|
||||
expect(res.body.steps[2].type).toBe("sign");
|
||||
});
|
||||
|
||||
it("assigns a new id (does not collide with source)", async () => {
|
||||
it("preserves id when importing an exported scenario with id", async () => {
|
||||
const sc = await createScenario("original");
|
||||
const exportRes = await request(app.getHttpServer())
|
||||
.get(`/scenarios/${sc.id}/export`)
|
||||
@@ -544,14 +536,13 @@ describe("ScenarioController", () => {
|
||||
.send(exportRes.body)
|
||||
.expect(201);
|
||||
|
||||
expect(importRes.body.id).not.toBe(sc.id);
|
||||
expect(importRes.body.id).toBe(sc.id);
|
||||
});
|
||||
|
||||
it("round-trips a scenario faithfully", async () => {
|
||||
const sc = await createScenario("roundtrip");
|
||||
await createStep(sc.id, {
|
||||
order: 0,
|
||||
type: "exec",
|
||||
sessionName: "rs",
|
||||
execCode: "return 42;",
|
||||
validateCode: "return true;",
|
||||
@@ -600,14 +591,14 @@ describe("ScenarioController", () => {
|
||||
.expect(400);
|
||||
});
|
||||
|
||||
it("returns 400 when a step has an invalid type", async () => {
|
||||
it("ignores unknown step fields during import", async () => {
|
||||
await request(app.getHttpServer())
|
||||
.post("/scenarios/import")
|
||||
.send({
|
||||
name: "bad-type",
|
||||
steps: [{ order: 0, type: "unknown", sessionName: "s" }],
|
||||
})
|
||||
.expect(400);
|
||||
.expect(201);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -654,7 +645,7 @@ describe("ScenarioController", () => {
|
||||
it("returns 404 for unknown run", async () => {
|
||||
const sc = await createScenario();
|
||||
await request(app.getHttpServer())
|
||||
.get(`/scenarios/${sc.id}/run/99999`)
|
||||
.get(`/scenarios/${sc.id}/run/00000000-0000-0000-0000-000000000001`)
|
||||
.expect(404);
|
||||
});
|
||||
|
||||
@@ -674,7 +665,9 @@ describe("ScenarioController", () => {
|
||||
|
||||
it("returns 404 for unknown scenario", async () => {
|
||||
await request(app.getHttpServer())
|
||||
.get("/scenarios/99999/run/1")
|
||||
.get(
|
||||
"/scenarios/00000000-0000-0000-0000-000000000001/run/00000000-0000-0000-0000-000000000001",
|
||||
)
|
||||
.expect(404);
|
||||
});
|
||||
});
|
||||
@@ -693,7 +686,7 @@ describe("ScenarioController", () => {
|
||||
// Manually mark run as pass so wait resolves immediately
|
||||
const dataSource = app.get(DataSource);
|
||||
await dataSource.query(
|
||||
`UPDATE scenario_runs SET status='pass' WHERE id=${runId}`,
|
||||
`UPDATE scenario_runs SET status='pass' WHERE id='${runId}'`,
|
||||
);
|
||||
|
||||
const res = await request(app.getHttpServer())
|
||||
@@ -716,7 +709,7 @@ describe("ScenarioController", () => {
|
||||
|
||||
const dataSource = app.get(DataSource);
|
||||
await dataSource.query(
|
||||
`UPDATE scenario_runs SET status='fail' WHERE id=${runId}`,
|
||||
`UPDATE scenario_runs SET status='fail' WHERE id='${runId}'`,
|
||||
);
|
||||
|
||||
const res = await request(app.getHttpServer())
|
||||
@@ -729,13 +722,15 @@ describe("ScenarioController", () => {
|
||||
it("returns 404 for unknown run", async () => {
|
||||
const sc = await createScenario();
|
||||
await request(app.getHttpServer())
|
||||
.post(`/scenarios/${sc.id}/run/99999/wait`)
|
||||
.post(`/scenarios/${sc.id}/run/00000000-0000-0000-0000-000000000001/wait`)
|
||||
.expect(404);
|
||||
});
|
||||
|
||||
it("returns 404 for unknown scenario", async () => {
|
||||
await request(app.getHttpServer())
|
||||
.post("/scenarios/99999/run/1/wait")
|
||||
.post(
|
||||
"/scenarios/00000000-0000-0000-0000-000000000001/run/00000000-0000-0000-0000-000000000001/wait",
|
||||
)
|
||||
.expect(404);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user