g1t/services/runner/src/surroundings.test.ts
| 1 | import assert from "node:assert/strict"; |
| 2 | import { test } from "node:test"; |
| 3 | |
| 4 | import { readableSurroundings } from "./surroundings.ts"; |
| 5 | |
| 6 | const projects = [ |
| 7 | { |
| 8 | slug: "web", |
| 9 | name: "Web", |
| 10 | dependencies: { |
| 11 | dependsOn: [ |
| 12 | { slug: "api", as: "API_URL" }, |
| 13 | { slug: "billing", as: null }, |
| 14 | ], |
| 15 | usedBy: [{ slug: "Admin", as: null }], |
| 16 | }, |
| 17 | }, |
| 18 | ]; |
| 19 | |
| 20 | test("someone who reads every repository is told of every project around it", () => { |
| 21 | assert.deepEqual(readableSurroundings(projects, null), projects); |
| 22 | }); |
| 23 | |
| 24 | test("anyone else is told only of the projects they can read", () => { |
| 25 | const [web] = readableSurroundings(projects, new Set(["web", "api", "admin"])); |
| 26 | assert.deepEqual(web.dependencies.dependsOn.map((d) => d.slug), ["api"], "billing is not named"); |
| 27 | assert.deepEqual(web.dependencies.usedBy.map((d) => d.slug), ["Admin"]); |
| 28 | assert.deepEqual(readableSurroundings(projects, new Set())[0].dependencies, { dependsOn: [], usedBy: [] }); |
| 29 | }); |