pr_01m47d15m3e54sn21z27rpy5n9/apps/web/app/lib/legal.test.ts

47 lines2,076 bytesCodeBlame

Pick any line to see why it is the way it is: the commit, the pull request and issue it came from, and what the agent was thinking.

Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look1import assert from "node:assert/strict";
2import { test } from "node:test";
3
4import { CONTACT, POLICIES, copyright, copyrightYear, listed, longDate, securityTxt } from "./legal.ts";
5
6test("the copyright year is computed, in UTC", () => {
7 assert.equal(copyrightYear(new Date("2026-10-05T12:00:00Z")), 2026);
8 assert.equal(copyrightYear(new Date("2027-01-01T00:00:00Z")), 2027);
9 // Still 31 December in UTC, whatever the server's own zone says.
10 assert.equal(copyrightYear(new Date("2026-12-31T23:59:59Z")), 2026);
11});
12
13test("the legal line names the company and the year", () => {
14 assert.equal(copyright(new Date("2026-10-05T00:00:00Z")), "© 2026 Flagon, Inc. All rights reserved.");
15 assert.equal(copyright(new Date("2031-03-01T00:00:00Z")), "© 2031 Flagon, Inc. All rights reserved.");
16});
17
18test("products are listed the way a sentence lists them", () => {
19 assert.equal(listed([]), "");
20 assert.equal(listed(["HEY"]), "HEY");
21 assert.equal(listed(["HEY", "Fizzy"]), "HEY and Fizzy");
22 assert.equal(listed(["A", "B", "C"]), "A, B and C");
23});
24
25test("policy dates read as words", () => {
26 assert.equal(longDate("2026-10-05"), "October 5, 2026");
27 assert.equal(longDate("2027-01-31"), "January 31, 2027");
28});
29
30test("every policy has its own address", () => {
31 const slugs = POLICIES.map((policy) => policy.slug);
32 assert.equal(new Set(slugs).size, slugs.length);
33 for (const slug of slugs) assert.match(slug, /^[a-z-]+$/);
34});
35
36test("security.txt has the fields RFC 9116 asks for, and expires within a year", () => {
37 const now = new Date("2026-10-05T15:30:00Z");
38 const text = securityTxt(now);
39 assert.ok(text.split("\n").includes(`Contact: mailto:${CONTACT.security}`));
40 assert.match(text, /^Policy: https:\/\/g1t\.sh\/security#responsible-disclosure$/m);
41 const expires = /^Expires: (.+)$/m.exec(text)?.[1];
42 assert.ok(expires);
43 assert.match(expires, /^\d{4}-\d{2}-\d{2}T00:00:00Z$/);
44 const days = (Date.parse(expires) - now.getTime()) / 86_400_000;
45 assert.ok(days > 30 && days < 365, `${days} days`);
46 assert.ok(text.endsWith("\n"));
47});