| 1 | import assert from "node:assert/strict"; |
| 2 | import { test } from "node:test"; |
| 3 | |
| 4 | import { MAX_ALIAS_NOTE, parseNewAlias, parseRemovalReason } from "./aliases.ts"; |
| 5 | |
| 6 | test("an alias, its workspace and why are read as identity takes them", () => { |
| 7 | assert.deepEqual(parseNewAlias(" G1T ", " Flagon-IO ", " The product's name, for Flagon, Inc. "), { |
| 8 | ok: true, |
| 9 | value: { alias: "g1t", workspace: "flagon-io", note: "The product's name, for Flagon, Inc." }, |
| 10 | }); |
| 11 | }); |
| 12 | |
| 13 | test("a malformed alias or workspace, or no reason, is refused before identity is asked", () => { |
| 14 | for (const [alias, workspace, note] of [ |
| 15 | ["g--1t", "flagon-io", "x"], |
| 16 | ["-g1t", "flagon-io", "x"], |
| 17 | ["g1t_inc", "flagon-io", "x"], |
| 18 | ["g1t", "", "x"], |
| 19 | ["g1t", "flagon io", "x"], |
| 20 | ["g1t", "flagon-io", " "], |
| 21 | ["flagon-io", "flagon-io", "x"], |
| 22 | ["g1t", "flagon-io", "x".repeat(MAX_ALIAS_NOTE + 1)], |
| 23 | ]) { |
| 24 | assert.equal(parseNewAlias(alias!, workspace!, note!).ok, false, `${alias} ${workspace}`); |
| 25 | } |
| 26 | }); |
| 27 | |
| 28 | test("removing an alias needs a reason", () => { |
| 29 | assert.deepEqual(parseRemovalReason(" Flagon renamed the product "), { ok: true, value: "Flagon renamed the product" }); |
| 30 | assert.equal(parseRemovalReason("").ok, false); |
| 31 | assert.equal(parseRemovalReason("x".repeat(MAX_ALIAS_NOTE + 1)).ok, false); |
| 32 | }); |