1import { DEFAULT_HOSTED_APP_URL } from "@t3tools/shared/connectAuth";
2import { afterEach, expect, it, vi } from "vite-plus/test";
3
4import appleAppSiteAssociation from "../web/public/.well-known/apple-app-site-association.json";
5import assetLinks from "../web/public/.well-known/assetlinks.json";
6
7// Keep config parsing independent of local env files and build credentials.
8vi.mock("../../scripts/lib/public-config.ts", () => ({
9 loadRepoEnv: () => ({ APP_VARIANT: process.env.APP_VARIANT }),
10}));
11
12afterEach(() => {
13 vi.unstubAllEnvs();
14});
15
16async function loadConfig(variant: string | undefined) {
17 vi.resetModules();
18 vi.stubEnv("APP_VARIANT", variant);
19 return (await import("./app.config.ts")).default;
20}
21
22it.each(["prod", ""])("rejects APP_VARIANT=%j before selecting production IDs", async (value) => {
23 await expect(loadConfig(value)).rejects.toThrow(
24 "APP_VARIANT must be development, preview, or production.",
25 );
26});
27
28it.each([
29 [undefined, "com.t3tools.t3code"],
30 ["development", "com.t3tools.t3code.dev"],
31 ["preview", "com.t3tools.t3code.preview"],
32 ["production", "com.t3tools.t3code"],
33])("keeps the iOS and Android identifiers for APP_VARIANT=%j", async (value, identifier) => {
34 const config = await loadConfig(value);
35 expect(config.ios?.bundleIdentifier).toBe(identifier);
36 expect(config.android?.package).toBe(identifier);
37 // Copied thread links open this app only while app.t3.codes lists it.
38 const host = new URL(DEFAULT_HOSTED_APP_URL).host;
39 expect(config.ios?.associatedDomains).toContain(`applinks:${host}`);
40 expect(appleAppSiteAssociation.applinks.details[0]?.appIDs).toContain(
41 `${config.ios?.appleTeamId}.${identifier}`,
42 );
43 expect(config.android?.intentFilters?.[0]?.data).toEqual([
44 { scheme: "https", host, pathPrefix: "/threads/" },
45 ]);
46 expect(assetLinks.map((link) => link.target.package_name)).toContain(identifier);
47});