SPB Git

Repository Public

catalog.test.ts 21.1 KB 319 lines typescript

1/**2 * =============================================================================3 *                  SP BOUCHER | SOFTWARE & RESEARCH4 *             ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING5 * =============================================================================6 *7 * Project          : ORIX App Universe8 * File             : tests/catalog.test.ts9 * Module           : tests10 * Repository       : https://git.spboucher.ai/orix-spboucher-ai11 * Project Website  : https://www.orixlab.dev12 * Created          : 2026-11-2113 * Last Modified    : 2026-11-2114 *15 * Author           : Simon-Pierre Boucher16 * Position         : Professor of Finance17 * Institution      : Université du Québec en Outaouais (UQO)18 * Organization     : SP Boucher19 * Website          : https://spboucher.ai20 * Git              : https://git.spboucher.ai21 *22 * Preferred Contact: support@spboucher.ai23 * Development      : dev@spboucher.ai24 * Support          : support@spboucher.ai25 * Security/Admin   : admin@spboucher.ai26 *27 * Copyright (c) 202628 * Simon-Pierre Boucher29 * All rights reserved where applicable. This file is governed by the30 * applicable project license, copyright notices and relevant law.31 * Existing third-party rights and notices remain unaffected.32 *33 * License          : None specified (no license file in this repository)34 *35 * Do not embed credentials, private keys, access tokens,36 * certificates or confidential personal information.37 *38 * =============================================================================39 * END OF SP BOUCHER SOURCE HEADER40 * =============================================================================41 */4243import { afterAll, beforeAll, describe, expect, it } from "vitest";44import { existsSync } from "node:fs";45import { freshData, macApp, seedDocs } from "./helpers";46import { AppDoc, publishProblems, STATUSES } from "@/models/app";47import { filterApps, isUniversal, statusOn, type CardApp } from "@/models/filter";4849const data = freshData();50let cat: typeof import("@/lib/catalog"), view: typeof import("@/lib/view");51beforeAll(async () => { cat = await import("@/lib/catalog"); view = await import("@/lib/view"); for (const d of seedDocs()) cat.upsertSeed(d); });52afterAll(() => data.cleanup());5354/** The intended catalogue. ORIX Navigator is released for Mac (beta 0.2.0) while its iPhone and iPad version is still to come. */55const AVAILABLE = ["astra", "audio", "camera", "clean", "convert", "docs", "monitor", "navigator", "prism", "sheet", "sonata"];56const COMING = ["alarm", "arcade", "calc", "maps", "scan"];57const RETIRED = ["dj", "secure"];58const MAC_LINEUP = ["astra", "clean", "convert", "docs", "sheet", "sonata", "prism", "navigator", "monitor"];59const MOBILE_LINEUP = ["alarm", "arcade", "astra", "calc", "camera", "maps", "scan", "audio", "navigator"];60const APP_STORE = /^https:\/\/apps\.apple\.com\/app\/[a-z0-9-]+\/id\d+$/;61const seeded = new Set(seedDocs().map((d) => d.slug));62/** A list of expected slugs, without the optional fiche while it is absent. */63const present = (slugs: string[]) => slugs.filter((s) => s !== "navigator" || seeded.has(s));64/** The editorial order of the catalogue: `order`, then the slug. */65const editorial = (docs: AppDoc[]) => [...docs].sort((a, b) => a.order - b.order || (a.slug < b.slug ? -1 : 1)).map((d) => d.slug);66const storeUrl = (d: AppDoc) => d.distribution.find((ch) => ch.channel === "appstore-ios" && ch.state === "public")?.url ?? null;6768describe("seed content", () => {69  const docs = seedDocs();70  it("contains exactly the ORIX applications of the catalogue, all valid", () => {71    expect(docs.map((d) => d.slug).sort()).toEqual(present([...AVAILABLE, ...COMING]).sort());72    for (const slug of RETIRED) expect(seeded.has(slug), slug).toBe(false);73    for (const d of docs) { expect(AppDoc.safeParse(d).success, d.slug).toBe(true); expect(publishProblems(d), d.slug).toEqual([]); }74  });75  it("uses two statuses only: available or coming soon", () => {76    expect(docs.filter((d) => d.status === "available").map((d) => d.slug).sort()).toEqual(AVAILABLE);77    expect(docs.filter((d) => d.status === "coming-soon").map((d) => d.slug).sort()).toEqual(present(COMING));78    for (const d of docs) for (const st of Object.values(d.platformStatus ?? {})) expect(["available", "coming-soon"], d.slug).toContain(st);79    // ORIX Astra is released for Mac while its iPhone version is still to come.80    const astra = docs.find((d) => d.slug === "astra")!;81    expect(astra.platforms).toEqual(expect.arrayContaining(["macos", "ios"]));82    expect(astra.platformStatus).toEqual({ ios: "coming-soon" });83    // ORIX Navigator likewise: a notarized beta for Mac, nothing to install yet on iPhone or iPad.84    const navigator = docs.find((d) => d.slug === "navigator")!;85    expect(navigator.platforms).toEqual(["macos", "ios", "ipados"]);86    expect(navigator.platformStatus).toEqual({ ios: "coming-soon", ipados: "coming-soon" });87    expect(navigator.distribution.find((ch) => ch.channel === "testflight")).toMatchObject({ state: "internal", url: null });88  });89  it("references only files that exist, with both languages filled", () => {90    for (const d of docs) {91      if (d.icon) expect(existsSync(`public/apps/${d.slug}/${d.icon}`), `${d.slug} icon`).toBe(true);92      for (const s of d.screenshots) { expect(existsSync(`public/apps/${d.slug}/${s.file}`), `${d.slug}/${s.file}`).toBe(true); expect(s.caption.en && s.caption.fr, `${d.slug}/${s.file} caption`).toBeTruthy(); }93      for (const f of d.features) expect(f.title.en && f.title.fr && f.body.en && f.body.fr, `${d.slug} feature`).toBeTruthy();94      expect(d.screenshots.filter((s) => s.hero).length).toBeLessThanOrEqual(1);95    }96  });97  it("claims no public distribution other than a released disk image, an App Store page or a public TestFlight invitation", () => {98    for (const d of docs) {99      const released = d.distribution.filter((ch) => ch.state === "public");100      // "Available" means exactly this: a macOS image released on the public forge, or a page on the App Store.101      expect(d.status === "available", d.slug).toBe(released.some((ch) => ch.channel === "dmg" || ch.channel === "appstore-ios"));102      for (const ch of released) {103        if (ch.channel === "testflight") {104          // A public invitation belongs to an iPhone / iPad application. The seed never carries the verification itself.105          expect(d.platforms, d.slug).not.toContain("macos");106          expect(d.platforms, d.slug).toContain("ios");107          expect(ch.url, d.slug).toMatch(/^https:\/\/testflight\.apple\.com\/join\/[A-Za-z0-9]{6,12}$/);108          expect(ch.check, d.slug).toBeUndefined();109          continue;110        }111        if (ch.channel === "appstore-ios") {112          expect(d.platforms, d.slug).not.toContain("macos");113          expect(d.platforms, d.slug).toContain("ios");114          expect(d.platformStatus?.ios ?? d.status, d.slug).toBe("available");115          expect(ch.url, d.slug).toMatch(APP_STORE);116          continue;117        }118        expect(ch.channel, d.slug).toBe("dmg");119        expect(d.platforms, d.slug).toContain("macos");120        expect(d.platformStatus?.macos ?? d.status, d.slug).toBe("available");121        expect(d.repo.visibility, d.slug).toBe("public");122        // The release tag is `v<version>`, with a platform prefix where one repository ships several platforms (`mac-v2.0.2`).123        expect(ch.url, d.slug).toMatch(new RegExp(`^https://git\\.spboucher\\.ai/releases/${d.repo.name}/(?:[a-z]+-)?v${d.version!.replace(/\./g, "\\.")}/[A-Za-z0-9._-]+\\.dmg$`));124      }125      for (const ch of d.distribution.filter((c) => c.state !== "public")) expect(ch.url, `${d.slug}/${ch.channel}`).toBeNull();126    }127    expect(docs.filter((d) => storeUrl(d)).map((d) => d.slug).sort()).toEqual(["audio", "camera"]);128  });129});130131describe("catalog listing and filters", () => {132  const docs = seedDocs();133  let cards: CardApp[];134  beforeAll(() => { cards = view.cards("en"); });135  it("lists every published application in editorial order", () => {136    expect(cards.map((c) => c.slug)).toEqual(editorial(docs));137    expect(cards[0].slug).toBe("astra");138    for (const slug of RETIRED) expect(cards.some((c) => c.slug === slug), slug).toBe(false);139  });140  it("filters by platform, including universal", () => {141    const mac = filterApps(cards, { platform: "macos" }).map((c) => c.slug);142    expect(mac).toEqual(editorial(docs.filter((d) => d.platforms.includes("macos"))));143    expect([...mac].sort()).toEqual(present(MAC_LINEUP).sort());144    expect(filterApps(cards, { platform: "ios" }).map((c) => c.slug).sort()).toEqual(present(MOBILE_LINEUP).sort());145    const ipad = filterApps(cards, { platform: "ipados" });146    expect(ipad.length).toBeGreaterThan(0);147    expect(ipad.every((c) => c.platforms.includes("ipados"))).toBe(true);148    const universal = filterApps(cards, { platform: "universal" });149    expect(universal.every(isUniversal)).toBe(true);150    expect(universal.length).toBe(docs.filter((d) => d.platforms.length > 1).length);151    expect(universal.map((c) => c.slug)).toEqual(expect.arrayContaining(["astra", "audio", "calc", "camera", "maps", "scan"]));152    expect(universal.map((c) => c.slug)).not.toContain("clean");153  });154  it("filters by status and category", () => {155    expect(filterApps(cards, { status: "beta" }).map((c) => c.slug)).toEqual([]);156    expect(filterApps(cards, { status: "development" }).map((c) => c.slug)).toEqual([]);157    expect(filterApps(cards, { status: "available" }).map((c) => c.slug)).toEqual(editorial(docs.filter((d) => d.status === "available")));158    expect(filterApps(cards, { status: "available" }).map((c) => c.slug).sort()).toEqual(AVAILABLE);159    expect(filterApps(cards, { status: "coming-soon" }).map((c) => c.slug).sort()).toEqual(present(COMING));160    expect(filterApps(cards, { category: "security" }).map((c) => c.slug)).toEqual([]);161    expect(filterApps(cards, { category: "games" }).map((c) => c.slug)).toEqual(["arcade"]);162    expect(filterApps(cards, { category: "music" }).map((c) => c.slug)).toEqual(["sonata"]);163  });164  it("searches names and features, ignoring case and accents", () => {165    expect(filterApps(cards, { q: "ORIX SCAN" }).map((c) => c.slug)).toContain("scan");166    expect(filterApps(cards, { q: "orix sonata" }).map((c) => c.slug)).toEqual(["sonata"]);167    expect(filterApps(cards, { q: "zzzz-nothing" })).toEqual([]);168    const fr = view.cards("fr");169    expect(filterApps(fr, { q: "numérisation" }).length).toBeGreaterThan(0);170    expect(filterApps(fr, { q: "numerisation" }).length).toBe(filterApps(fr, { q: "numérisation" }).length);171  });172  it("sorts by name and by availability", () => {173    const names = filterApps(cards, { sort: "name" }).map((c) => c.name);174    expect(names).toEqual([...names].sort((a, b) => a.localeCompare(b)));175    const ranks = filterApps(cards, { sort: "status" }).map((c) => STATUSES.indexOf(c.status));176    expect(ranks).toEqual([...ranks].sort((a, b) => a - b));177    expect(new Set(ranks).size).toBe(2); // available first, then coming soon178  });179  it("gives no card a download or TestFlight action without a verified destination", () => {180    // This database holds no verified image and no verified invitation: the only real action is a public App Store page.181    for (const c of cards) {182      const store = storeUrl(docs.find((d) => d.slug === c.slug)!);183      expect(c.action, c.slug).toEqual(store ? { kind: "appstore", href: store } : { kind: "details", href: `/apps/${c.slug}` });184    }185    expect(cards.filter((c) => c.action.kind === "appstore").map((c) => c.slug).sort()).toEqual(["audio", "camera"]);186    expect(view.cards("fr")[0].action.href).toBe(`/fr/apps/${cards[0].slug}`);187  });188  it("sends a card to the App Store only for a public page on apps.apple.com", () => {189    const ios = (over: Partial<AppDoc>) => macApp({ platforms: ["ios", "ipados"], minOS: { ios: "18.0" }, ...over });190    const page = "https://apps.apple.com/app/orix-demo/id1234567890";191    expect(view.primaryAction(ios({ distribution: [{ channel: "appstore-ios", state: "public", url: page }] }), "en", null)).toEqual({ kind: "appstore", href: page });192    expect(view.primaryAction(ios({ distribution: [{ channel: "appstore-ios", state: "public", url: page }] }), "fr", null)).toEqual({ kind: "appstore", href: page });193    for (const distribution of [194      [{ channel: "appstore-ios", state: "internal", url: null }],195      [{ channel: "appstore-ios", state: "none", url: null }],196      [{ channel: "appstore-ios", state: "public", url: "https://example.com/app/orix-demo/id1234567890" }],197      [{ channel: "appstore-mac", state: "public", url: page }],198    ] as AppDoc["distribution"][]) expect(view.primaryAction(ios({ distribution }), "en", null), JSON.stringify(distribution)).toEqual({ kind: "details", href: "/apps/demo" });199    expect(view.primaryAction(ios({ status: "unavailable", distribution: [{ channel: "appstore-ios", state: "public", url: page }] }), "en", null).kind).toBe("details");200    // A verified open invitation alone still leads to TestFlight; the App Store page wins when both exist.201    const invite = { channel: "testflight" as const, state: "public" as const, url: "https://testflight.apple.com/join/ABCDEFGH", check: { at: "2026-11-25T00:00:00Z", result: "open" as const } };202    expect(view.primaryAction(ios({ status: "beta", distribution: [invite] }), "en", null).kind).toBe("testflight");203    expect(view.primaryAction(ios({ distribution: [invite, { channel: "appstore-ios", state: "public", url: page }] }), "en", null)).toEqual({ kind: "appstore", href: page });204  });205  it("shows a version only for something that exists as a build", () => {206    for (const c of cards) if (c.status === "development" || c.status === "coming-soon") expect(c.version, c.slug).toBeNull();207    for (const c of cards) if (c.status === "available") expect(c.version, c.slug).toBe(docs.find((d) => d.slug === c.slug)!.version);208  });209  it("reads the status of one platform, falling back to the application's", () => {210    const astra = cards.find((c) => c.slug === "astra")!;211    expect(astra.status).toBe("available");212    expect(statusOn(astra, "macos")).toBe("available");213    expect(statusOn(astra, "ios")).toBe("coming-soon");214    const clean = cards.find((c) => c.slug === "clean")!;215    expect(clean.platformStatus).toEqual({});216    expect(statusOn(clean, "macos")).toBe("available");217    expect(statusOn({ status: "coming-soon", platformStatus: { macos: "beta" } }, "macos")).toBe("beta");218    expect(statusOn({ status: "coming-soon", platformStatus: { macos: "beta" } }, "ios")).toBe("coming-soon");219  });220});221222describe("home page line-up", () => {223  let families: ReturnType<typeof view.lineup>;224  const docs = seedDocs();225  beforeAll(() => { families = view.lineup("en"); });226  it("lists each device family in its fixed editorial order", () => {227    expect(families.mac.map((c) => c.slug)).toEqual(present(MAC_LINEUP));228    expect(families.mobile.map((c) => c.slug)).toEqual(present(MOBILE_LINEUP));229    // Every published application is in at least one family, and only those that run on the family's devices.230    expect([...new Set([...families.mac, ...families.mobile].map((c) => c.slug))].sort()).toEqual(docs.map((d) => d.slug).sort());231    for (const c of families.mac) expect(c.platforms, c.slug).toEqual(["macos"]);232    for (const c of families.mobile) { expect(c.platforms.length, c.slug).toBeGreaterThan(0); expect(c.platforms, c.slug).not.toContain("macos"); }233  });234  it("carries, in each family, the status of that family only", () => {235    const of = (list: CardApp[], slug: string) => list.find((c) => c.slug === slug)!;236    expect(of(families.mac, "astra").status).toBe("available");237    expect(of(families.mac, "astra").version).toBe(docs.find((d) => d.slug === "astra")!.version);238    expect(of(families.mobile, "astra").status).toBe("coming-soon");239    expect(of(families.mobile, "astra").version).toBeNull();240    expect(of(families.mac, "navigator").status).toBe("available");241    expect(of(families.mac, "navigator").version).toBe(docs.find((d) => d.slug === "navigator")!.version);242    expect(of(families.mobile, "navigator").status).toBe("coming-soon");243    expect(of(families.mobile, "navigator").version).toBeNull();244    expect(of(families.mobile, "navigator").action).toEqual({ kind: "details", href: "/apps/navigator" });245    expect(families.mac.filter((c) => c.status === "available").map((c) => c.slug)).toEqual(MAC_LINEUP);246    expect(families.mobile.filter((c) => c.status === "available").map((c) => c.slug)).toEqual(["camera", "audio"]);247    for (const c of [...families.mac, ...families.mobile]) {248      expect(["available", "coming-soon"], c.slug).toContain(c.status);249      if (c.status === "coming-soon") expect(c.version, c.slug).toBeNull();250    }251  });252  it("offers the App Store for the released iPhone apps, and nothing unverified elsewhere", () => {253    for (const c of families.mobile) {254      const store = storeUrl(docs.find((d) => d.slug === c.slug)!);255      expect(c.action, c.slug).toEqual(store ? { kind: "appstore", href: store } : { kind: "details", href: `/apps/${c.slug}` });256    }257    expect(families.mobile.filter((c) => c.action.kind === "appstore").map((c) => c.slug)).toEqual(["camera", "audio"]);258    // No verified image in this database: a Mac card never points to the App Store or to a download that does not exist.259    for (const c of families.mac) expect(c.action, c.slug).toEqual({ kind: "details", href: `/apps/${c.slug}` });260    expect(view.lineup("fr").mac[0].action.href).toBe("/fr/apps/astra");261  });262  it("offers the Mac download of a verified image in the Mac family only", async () => {263    const { db, now } = await import("@/lib/database/db");264    const sha = "a".repeat(64);265    db().prepare(`INSERT INTO releases (slug, repo, tag, version, tag_date, subject, asset_name, asset_size, sha256_declared, sha256_computed, source_url, state, signature, discovered_at, published_at, artifact)266      VALUES ('astra', 'orix-astra', 'mac-v2.0.2', '2.0.2', ?, 'Astra', 'ORIX-Astra-2.0.2.dmg', 10, ?, ?, 'https://git.test/releases/orix-astra/mac-v2.0.2/ORIX-Astra-2.0.2.dmg', 'published', '{}', ?, ?, '/nonexistent/ORIX-Astra-2.0.2.dmg')`).run(now(), sha, sha, now(), now());267    try {268      const l = view.lineup("en");269      expect(l.mac.find((c) => c.slug === "astra")!.action).toEqual({ kind: "download", href: "/download/astra/2.0.2/ORIX-Astra-2.0.2.dmg" });270      expect(l.mobile.find((c) => c.slug === "astra")!.action).toEqual({ kind: "details", href: "/apps/astra" });271    } finally { db().prepare("DELETE FROM releases WHERE slug = 'astra'").run(); }272  });273  it("showcases the released applications only, each with a real capture", async () => {274    const shown = await view.showcase("en");275    expect(shown.map((s) => s.slug)).toEqual(editorial(docs.filter((d) => d.status === "available" && d.screenshots.length > 0)));276    expect(shown.length).toBeGreaterThan(0);277    for (const s of shown) {278      expect(s.status, s.slug).toBe("available");279      expect(s.shot.src, s.slug).toMatch(new RegExp(`^/apps/${s.slug}/[A-Za-z0-9._-]+$`));280      expect(existsSync(`public${s.shot.src}`), s.shot.src).toBe(true);281      expect(s.shot.width, s.slug).toBeGreaterThan(0); expect(s.shot.height, s.slug).toBeGreaterThan(0);282      expect(s.shot.alt, s.slug).toBeTruthy();283      expect(["iphone", "ipad", "mac"], s.slug).toContain(s.device);284    }285  });286});287288describe("CMS publishing workflow", () => {289  it("keeps a new application and its draft edits private until published", () => {290    cat.createApp("notes", "ORIX Notes");291    expect(cat.getApp("notes")).toBeNull();292    expect(() => cat.publishApp("notes")).toThrowError(/Required fields/);293    const doc = macApp({ slug: "notes", name: "ORIX Notes", status: "coming-soon", version: null });294    cat.saveDraft("notes", doc);295    expect(cat.getApp("notes")).toBeNull();296    cat.publishApp("notes");297    expect(cat.getApp("notes")?.app.tagline.en).toBe("Demo");298  });299  it("serves the published document while a draft is pending, and the draft only in preview", () => {300    cat.saveDraft("notes", macApp({ slug: "notes", name: "ORIX Notes 2", status: "coming-soon", version: null }));301    expect(cat.getApp("notes")?.app.name).toBe("ORIX Notes");302    expect(cat.getApp("notes", { all: true, preview: true })?.app.name).toBe("ORIX Notes 2");303    cat.discardDraft("notes");304    expect(cat.getApp("notes", { all: true, preview: true })?.app.name).toBe("ORIX Notes");305  });306  it("rejects invalid documents and impossible claims", () => {307    expect(() => cat.saveDraft("notes", { slug: "notes" })).toThrowError(/invalid/);308    expect(() => cat.saveDraft("notes", macApp({ slug: "other" }))).toThrowError();309    expect(publishProblems(macApp({ status: "available", version: null }))).toContain("available without a version");310    expect(publishProblems(macApp({ distribution: [{ channel: "testflight", state: "public", url: null }] }))).toContain("testflight: public without a URL");311    expect(publishProblems(macApp({ distribution: [{ channel: "testflight", state: "public", url: "https://example.com/join/ABCDEFGH" }] }))).toContain("testflight: not a public invitation URL");312  });313  it("hides unpublished and archived applications", () => {314    cat.setPublish("notes", "draft"); expect(cat.getApp("notes")).toBeNull();315    cat.setPublish("notes", "archived"); expect(cat.listApps().some((r) => r.slug === "notes")).toBe(false);316    expect(cat.listApps({ all: true }).some((r) => r.slug === "notes")).toBe(true);317  });318});319
Files main
Menu

Theme