@terreno/admin-backend 0.20.2 → 0.22.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.ai/guidelines/core.md +5 -0
- package/.github/copilot-instructions.md +1 -1
- package/AGENTS.md +5 -1
- package/bunfig.toml +1 -1
- package/dist/adminApp.d.ts +74 -1
- package/dist/adminApp.js +620 -83
- package/dist/adminUiV2.d.ts +96 -0
- package/dist/adminUiV2.js +189 -0
- package/dist/index.d.ts +2 -1
- package/dist/index.js +15 -0
- package/package.json +5 -4
- package/src/adminApp.models.test.ts +285 -3
- package/src/adminApp.test.ts +96 -1
- package/src/adminApp.ts +598 -22
- package/src/adminUiV2.test.ts +28 -0
- package/src/adminUiV2.ts +188 -0
- package/src/documentStorageApp.test.ts +1 -1
- package/src/index.ts +9 -1
- package/src/tests/bunSetup.ts +9 -0
- package/tsconfig.json +1 -1
- package/dist/adminApp.models.test.d.ts +0 -1
- package/dist/adminApp.models.test.js +0 -969
- package/dist/adminApp.test.d.ts +0 -1
- package/dist/adminApp.test.js +0 -564
- package/dist/documentStorageApp.test.d.ts +0 -1
- package/dist/documentStorageApp.test.js +0 -874
package/src/adminApp.test.ts
CHANGED
|
@@ -8,7 +8,7 @@ import {
|
|
|
8
8
|
setupAuth,
|
|
9
9
|
type UserModel as UserModelType,
|
|
10
10
|
} from "@terreno/api";
|
|
11
|
-
import {authAsUser, getBaseServer, setupDb, UserModel} from "@terreno/api/
|
|
11
|
+
import {authAsUser, getBaseServer, setupDb, UserModel} from "@terreno/api/testing";
|
|
12
12
|
import type express from "express";
|
|
13
13
|
import supertest from "supertest";
|
|
14
14
|
import type TestAgent from "supertest/lib/agent";
|
|
@@ -289,6 +289,101 @@ describe("AdminApp script routes", () => {
|
|
|
289
289
|
});
|
|
290
290
|
});
|
|
291
291
|
|
|
292
|
+
describe("GET /admin/scripts/runs", () => {
|
|
293
|
+
beforeEach(async () => {
|
|
294
|
+
await setupDb();
|
|
295
|
+
app = buildApp([
|
|
296
|
+
createTestScript({description: "Migrate old data", name: "migrate-data"}),
|
|
297
|
+
createTestScript({description: "Clean up orphans", name: "cleanup"}),
|
|
298
|
+
]);
|
|
299
|
+
adminAgent = await authAsUser(app, "admin");
|
|
300
|
+
notAdminAgent = await authAsUser(app, "notAdmin");
|
|
301
|
+
});
|
|
302
|
+
|
|
303
|
+
it("returns runs for registered scripts, newest first", async () => {
|
|
304
|
+
await adminAgent.post("/admin/scripts/migrate-data/run").expect(201);
|
|
305
|
+
await adminAgent.post("/admin/scripts/cleanup/run?wetRun=true").expect(201);
|
|
306
|
+
await waitForScripts();
|
|
307
|
+
|
|
308
|
+
const res = await adminAgent.get("/admin/scripts/runs").expect(200);
|
|
309
|
+
|
|
310
|
+
expect(res.body.data).toHaveLength(2);
|
|
311
|
+
expect(res.body.total).toBe(2);
|
|
312
|
+
// Newest run (cleanup) is listed first.
|
|
313
|
+
expect(res.body.data[0].taskType).toBe("cleanup");
|
|
314
|
+
expect(res.body.data[1].taskType).toBe("migrate-data");
|
|
315
|
+
});
|
|
316
|
+
|
|
317
|
+
it("narrows history to a single script via the name query", async () => {
|
|
318
|
+
await adminAgent.post("/admin/scripts/migrate-data/run").expect(201);
|
|
319
|
+
await adminAgent.post("/admin/scripts/cleanup/run").expect(201);
|
|
320
|
+
await waitForScripts();
|
|
321
|
+
|
|
322
|
+
const res = await adminAgent.get("/admin/scripts/runs?name=cleanup").expect(200);
|
|
323
|
+
|
|
324
|
+
expect(res.body.data).toHaveLength(1);
|
|
325
|
+
expect(res.body.data[0].taskType).toBe("cleanup");
|
|
326
|
+
});
|
|
327
|
+
|
|
328
|
+
it("returns no runs when the name query is not a registered script", async () => {
|
|
329
|
+
await adminAgent.post("/admin/scripts/migrate-data/run").expect(201);
|
|
330
|
+
await adminAgent.post("/admin/scripts/cleanup/run").expect(201);
|
|
331
|
+
await waitForScripts();
|
|
332
|
+
|
|
333
|
+
const res = await adminAgent.get("/admin/scripts/runs?name=does-not-exist").expect(200);
|
|
334
|
+
|
|
335
|
+
expect(res.body.data).toHaveLength(0);
|
|
336
|
+
expect(res.body.total).toBe(0);
|
|
337
|
+
});
|
|
338
|
+
|
|
339
|
+
it("excludes tasks whose taskType is not a registered script", async () => {
|
|
340
|
+
await BackgroundTask.create({
|
|
341
|
+
isDryRun: false,
|
|
342
|
+
logs: [],
|
|
343
|
+
status: "completed",
|
|
344
|
+
taskType: "some-other-task",
|
|
345
|
+
});
|
|
346
|
+
await adminAgent.post("/admin/scripts/migrate-data/run").expect(201);
|
|
347
|
+
await waitForScripts();
|
|
348
|
+
|
|
349
|
+
const res = await adminAgent.get("/admin/scripts/runs").expect(200);
|
|
350
|
+
|
|
351
|
+
expect(res.body.data).toHaveLength(1);
|
|
352
|
+
expect(res.body.data[0].taskType).toBe("migrate-data");
|
|
353
|
+
});
|
|
354
|
+
|
|
355
|
+
it("paginates and reports `more`", async () => {
|
|
356
|
+
await adminAgent.post("/admin/scripts/migrate-data/run").expect(201);
|
|
357
|
+
await adminAgent.post("/admin/scripts/cleanup/run").expect(201);
|
|
358
|
+
await waitForScripts();
|
|
359
|
+
|
|
360
|
+
const res = await adminAgent.get("/admin/scripts/runs?limit=1&page=1").expect(200);
|
|
361
|
+
|
|
362
|
+
expect(res.body.data).toHaveLength(1);
|
|
363
|
+
expect(res.body.limit).toBe(1);
|
|
364
|
+
expect(res.body.more).toBe(true);
|
|
365
|
+
expect(res.body.total).toBe(2);
|
|
366
|
+
});
|
|
367
|
+
|
|
368
|
+
it("includes the triggering admin's display name", async () => {
|
|
369
|
+
await adminAgent.post("/admin/scripts/migrate-data/run").expect(201);
|
|
370
|
+
await waitForScripts();
|
|
371
|
+
|
|
372
|
+
const res = await adminAgent.get("/admin/scripts/runs").expect(200);
|
|
373
|
+
|
|
374
|
+
expect(res.body.data[0].createdByName).toBeDefined();
|
|
375
|
+
});
|
|
376
|
+
|
|
377
|
+
it("returns 403 for non-admin user", async () => {
|
|
378
|
+
const res = await notAdminAgent.get("/admin/scripts/runs").expect(403);
|
|
379
|
+
expect(res.body.title).toInclude("Only admins can view run history");
|
|
380
|
+
});
|
|
381
|
+
|
|
382
|
+
it("returns 401 for unauthenticated user", async () => {
|
|
383
|
+
await supertest(app).get("/admin/scripts/runs").expect(401);
|
|
384
|
+
});
|
|
385
|
+
});
|
|
386
|
+
|
|
292
387
|
describe("GET /admin/config with scripts", () => {
|
|
293
388
|
beforeEach(async () => {
|
|
294
389
|
await setupDb();
|