g1t/apps/web/app/lib/public-cache.test.ts

27 lines1,275 bytesCodeBlame
1import assert from "node:assert/strict";
2import { test } from "node:test";
3
4import { repositoryOfPage, stillPublic } from "./public-cache.ts";
5
6test("a project page names its repository", () => {
7 assert.equal(repositoryOfPage("/flagon-io/hello"), "flagon-io/hello");
8 assert.equal(repositoryOfPage("/flagon-io/hello.data"), "flagon-io/hello");
9 assert.equal(repositoryOfPage("/Flagon-IO/Hello/issues/4"), "flagon-io/hello");
10 assert.equal(repositoryOfPage("/flagon-io/hello/blob/main/src/lib.rs"), "flagon-io/hello");
11});
12
13test("pages that are not a repository's name none", () => {
14 assert.equal(repositoryOfPage("/"), null);
15 assert.equal(repositoryOfPage("/pricing"), null);
16 assert.equal(repositoryOfPage("/flagon-io"), null);
17 assert.equal(repositoryOfPage("/flagon-io/-"), null);
18});
19
20test("only a repository that is there and public is served from the cache", () => {
21 assert.equal(stillPublic([{ path: "a/b", is_private: false }], "a/b"), true);
22 assert.equal(stillPublic([{ path: "a/b", is_private: true }], "a/b"), false);
23 // Deleted or never there: repos leaves it out.
24 assert.equal(stillPublic([], "a/b"), false);
25 assert.equal(stillPublic(null, "a/b"), false);
26 assert.equal(stillPublic([{ path: "a/c", is_private: false }], "a/b"), false);
27});