Repository Public
1/**2 * =============================================================================3 * SP BOUCHER | SOFTWARE & RESEARCH4 * ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING5 * =============================================================================6 *7 * Project : ORIX App Universe8 * File : tests/testflight.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 { describe, expect, it } from "vitest";44import { betaAccess, checkInvite, isPublicInvite } from "@/lib/testflight";45import type { Distribution } from "@/models/app";4647const URL_OK = "https://testflight.apple.com/join/AbCd1234";48const at = "2026-11-21T00:00:00.000Z";49const ios = (d: Partial<Distribution>) => ({ platforms: ["ios", "ipados"] as ("ios" | "ipados")[], distribution: [{ channel: "testflight" as const, state: "none" as const, url: null, ...d }] });50const page = (body: string, status = 200) => async () => new Response(body, { status });5152describe("TestFlight invitation URL", () => {53 it("accepts only public invitation links", () => {54 expect(isPublicInvite(URL_OK)).toBe(true);55 for (const bad of [null, "", "http://testflight.apple.com/join/AbCd1234", "https://testflight.apple.com/v1/invite/abc?ct=X&advp=1", "https://testflight.apple.com.evil.io/join/AbCd1234", "https://testflight.apple.com/join/AbCd1234?x=1", "https://appstoreconnect.apple.com/apps/123/testflight"]) expect(isPublicInvite(bad), String(bad)).toBe(false);56 });57});5859describe("what the site may show", () => {60 it("offers Join only for a public invitation verified as open", () => {61 expect(betaAccess(ios({ state: "public", url: URL_OK, check: { at, result: "open" } }))).toEqual({ kind: "join", url: URL_OK, verifiedAt: at });62 });63 it("shows Beta Access Coming Soon when there is no invitation", () => {64 expect(betaAccess(ios({}))).toEqual({ kind: "soon", reason: "no-invite" });65 expect(betaAccess(ios({ state: "public", url: null }))).toEqual({ kind: "soon", reason: "no-invite" });66 });67 it("never exposes an internal build, even if a link is stored", () => {68 expect(betaAccess(ios({ state: "internal", url: URL_OK, check: { at, result: "open" } }))).toEqual({ kind: "soon", reason: "internal-only" });69 });70 it("withholds a link that is unverified, disabled or full", () => {71 expect(betaAccess(ios({ state: "public", url: URL_OK }))).toEqual({ kind: "soon", reason: "unverified" });72 expect(betaAccess(ios({ state: "public", url: URL_OK, check: { at, result: "closed" } }))).toEqual({ kind: "soon", reason: "closed" });73 expect(betaAccess(ios({ state: "public", url: URL_OK, check: { at, result: "full" } }))).toEqual({ kind: "soon", reason: "full" });74 expect(betaAccess(ios({ state: "public", url: URL_OK, check: { at, result: "error" } }))).toEqual({ kind: "soon", reason: "unverified" });75 });76 it("ignores a TestFlight entry on a Mac-only application (incorrect platform)", () => {77 expect(betaAccess({ platforms: ["macos"], distribution: [{ channel: "testflight", state: "public", url: URL_OK, check: { at, result: "open" } }] })).toEqual({ kind: "none" });78 });79});8081describe("invitation check against Apple's page", () => {82 it("recognizes an open beta", async () => { expect((await checkInvite(URL_OK, page("<title>Join the ORIX Scan beta - TestFlight - Apple</title>"))).result).toBe("open"); });83 it("recognizes a full beta", async () => { expect((await checkInvite(URL_OK, page("<span>This beta is full.</span>"))).result).toBe("full"); });84 it("recognizes a disabled invitation", async () => {85 expect((await checkInvite(URL_OK, page("This beta isn't accepting any new testers right now."))).result).toBe("closed");86 expect((await checkInvite(URL_OK, page("", 404))).result).toBe("closed");87 });88 it("answers unknown rather than guessing", async () => {89 expect((await checkInvite(URL_OK, page("<html>something else</html>"))).result).toBe("unknown");90 expect((await checkInvite(URL_OK, page("", 503))).result).toBe("unknown");91 });92 it("reports network failures and refuses foreign URLs without fetching", async () => {93 expect((await checkInvite(URL_OK, async () => { throw new Error("offline"); })).result).toBe("error");94 let called = false;95 expect((await checkInvite("https://evil.example/join/AbCd1234", async () => { called = true; return new Response(""); })).result).toBe("error");96 expect(called).toBe(false);97 });98});99