| 1 | import assert from "node:assert/strict"; |
| 2 | import { test } from "node:test"; |
| 3 | |
| 4 | import { apkName, manifestFor, newestBuild, version } from "./mobile-release.mjs"; |
| 5 | |
| 6 | test("the version is the app's, and the APK is named by it", () => { |
| 7 | assert.match(version(), /^\d+\.\d+\.\d+$/); |
| 8 | assert.equal(apkName("0.2.0"), "g1t-0.2.0-android.apk"); |
| 9 | }); |
| 10 | |
| 11 | test("the manifest lists the APK with its size and SHA-256, and SHA256SUMS matches", () => { |
| 12 | const { manifest, sums } = manifestFor({ |
| 13 | version: "0.2.0", |
| 14 | build: 7, |
| 15 | notes: "", |
| 16 | files: [{ name: "g1t-0.2.0-android.apk", size: 42, sha256: "ab".repeat(32) }], |
| 17 | now: new Date("2026-10-11T00:00:00Z"), |
| 18 | }); |
| 19 | assert.deepEqual(manifest, { |
| 20 | version: "0.2.0", |
| 21 | build: 7, |
| 22 | pub_date: "2026-10-11T00:00:00.000Z", |
| 23 | notes: undefined, |
| 24 | downloads: [{ platform: "android", kind: "apk", name: "g1t-0.2.0-android.apk", size: 42, sha256: "ab".repeat(32) }], |
| 25 | }); |
| 26 | assert.equal(sums, `${"ab".repeat(32)} g1t-0.2.0-android.apk\n`); |
| 27 | }); |
| 28 | |
| 29 | test("the newest finished build with an APK is the one fetched", () => { |
| 30 | const list = [ |
| 31 | { id: "a", status: "FINISHED", createdAt: "2026-10-10T00:00:00Z", artifacts: { buildUrl: "https://x/a.apk" } }, |
| 32 | { id: "b", status: "ERRORED", createdAt: "2026-10-12T00:00:00Z", artifacts: {} }, |
| 33 | { id: "c", status: "FINISHED", createdAt: "2026-10-11T00:00:00Z", artifacts: { buildUrl: "https://x/c.apk" } }, |
| 34 | ]; |
| 35 | assert.equal(newestBuild(list)?.id, "c"); |
| 36 | assert.equal(newestBuild([]), null); |
| 37 | assert.equal(newestBuild(null), null); |
| 38 | }); |