1import * as Railway from "@/Railway";
2import { suitePartition } from "./suiteProject.ts";
3import * as Test from "@/Test/Alchemy";
4import { expect } from "alchemy-test";
5import * as Effect from "effect/Effect";
6import { MinimumLogLevel } from "effect/References";
7
8const { test } = Test.make({ providers: Railway.providers() });
9
10const logLevel = Effect.provideService(
11 MinimumLogLevel,
12 process.env.DEBUG ? "Debug" : "Info",
13);
14
15test.provider(
16 "list workspace audit logs",
17 (stack) =>
18 Effect.gen(function* () {
19 yield* stack.destroy();
20
21 const types = yield* Railway.listAuditLogEventTypes();
22 expect(Array.isArray(types)).toEqual(true);
23 for (const item of types) {
24 expect(item.eventType).toEqual(expect.any(String));
25 expect(item.eventType.length).toBeGreaterThan(0);
26 expect(item.description).toEqual(expect.any(String));
27 }
28
29 const logs = yield* Railway.listAuditLogs({ first: 10 });
30 expect(Array.isArray(logs)).toEqual(true);
31 for (const log of logs) {
32 expect(log.id).toEqual(expect.any(String));
33 expect(log.id.length).toBeGreaterThan(0);
34 expect(log.eventType).toEqual(expect.any(String));
35 expect(log.eventType.length).toBeGreaterThan(0);
36 expect(log.createdAt).toEqual(expect.any(String));
37 }
38
39 const created = yield* stack.deploy(
40 Effect.gen(function* () {
41 const { project, environment } = yield* suitePartition;
42 return { project, environment };
43 }),
44 );
45
46 const projectLogs = yield* Railway.listAuditLogs({
47 project: created.project,
48 environment: created.environment,
49 first: 10,
50 });
51 expect(Array.isArray(projectLogs)).toEqual(true);
52 expect(
53 projectLogs.every(
54 (log) =>
55 log.projectId === undefined ||
56 log.projectId === created.project.projectId,
57 ),
58 ).toEqual(true);
59
60 const first = logs[0] ?? projectLogs[0];
61 if (first !== undefined) {
62 const fetched = yield* Railway.getAuditLog({ id: first.id });
63 expect(fetched.id).toEqual(first.id);
64 expect(fetched.eventType).toEqual(first.eventType);
65 }
66
67 yield* stack.destroy();
68 }).pipe(logLevel),
69 {
70 tags: [
71 "provider:railway",
72 "provider:railway:project",
73 "provider:railway:projectenvironment",
74 "live",
75 ],
76 timeout: 120_000,
77 },
78);