videogen/apps/watch/tests/push.test.ts
caelum0x d56639a594
Some checks are pending
build-images / api (push) Waiting to run
build-images / worker-gpu (push) Waiting to run
build-images / web (push) Waiting to run
codeql / Analyze (javascript-typescript) (push) Waiting to run
codeql / Analyze (python) (push) Waiting to run
perf / API hot-path micro-smoke (budgeted) (push) Waiting to run
perf / Desktop engine crates (release build check) (push) Waiting to run
vision2026-ci / Shared packages (TS≡Python golden parity) (comfy-workflow-schema) (push) Waiting to run
vision2026-ci / Shared packages (TS≡Python golden parity) (effects-core) (push) Waiting to run
vision2026-ci / Shared packages (TS≡Python golden parity) (eventbus-types) (push) Waiting to run
vision2026-ci / Shared packages (TS≡Python golden parity) (growth-analytics) (push) Waiting to run
vision2026-ci / Shared packages (TS≡Python golden parity) (trends-schema) (push) Waiting to run
vision2026-ci / API phase modules (ruff + pytest) (push) Waiting to run
vision2026-ci / Shared packages (TS≡Python golden parity) (provider-adapter-kit) (push) Waiting to run
vision2026-ci / Shared packages (TS≡Python golden parity) (publishing-connectors) (push) Waiting to run
vision2026-ci / Shared packages (TS≡Python golden parity) (render-core) (push) Waiting to run
vision2026-ci / Shared packages (TS≡Python golden parity) (shot-template-schema) (push) Waiting to run
vision2026-ci / Python SDK resource tests (push) Waiting to run
vision2026-ci / Desktop engine crates (test + clippy + fmt) (push) Waiting to run
vision2026-ci / Alembic upgrade + drift check (push) Waiting to run
vision2026-ci / Shared packages (TS≡Python golden parity) (caption-engine) (push) Waiting to run
Menivor — open source release (MIT), free to use and fork
Paid, hosted product at menivor.com, now retired as a company project.
Fresh squashed history of the cleaned working tree (secret-scanned,
no .env, no customer data, no outreach logs). Built on
MoneyPrinterTurbo (MIT, harry0703) — see NOTICE.
2026-12-04 02:10:26 +03:00

56 lines
3.0 KiB
TypeScript

import { readFileSync } from "node:fs";
import { join } from "node:path";
import { describe, expect, it, vi } from "vitest";
import config from "../app.config";
import { createClient } from "../src/api/client";
import { MESSAGES, optIn, routeFor } from "../src/push/optin";
const TOKEN = "ExponentPushToken[abcdefghij0123456789]";
function api() {
const calls: { url: string; init?: RequestInit }[] = [];
const fetcher = vi.fn(async (url: string, init?: RequestInit) => {
calls.push({ url, init });
const body = JSON.parse(String(init?.body ?? "{}"));
return { ok: true, status: 200, json: async () => ({ data: { opted_in: true, topics: body.topics ?? [] } }) } as Response;
});
return { client: createClient("https://api.example/api/v1", fetcher), calls };
}
describe("push opt-in", () => {
it("sends the token and only the chosen topics, per channel", async () => {
const { client, calls } = api();
const result = await optIn({ api: client, platform: "ios", askPermission: async () => true, getToken: async () => TOKEN },
"maya", "vs-1", ["live", "live"], "proj-1");
expect(result).toEqual({ ok: true, token: TOKEN, topics: ["live"] });
expect(calls[0].url).toBe("https://api.example/api/v1/ott/viewers/maya/push");
expect(calls[0].init?.method).toBe("PUT");
expect(JSON.parse(String(calls[0].init?.body))).toEqual({ token: TOKEN, platform: "ios", topics: ["live"] });
});
it("explains each refusal and never asks the API", async () => {
const { client, calls } = api();
const deps = { api: client, platform: "android" as const, askPermission: async () => false, getToken: async () => TOKEN };
expect(await optIn(deps, "maya", "vs", [], "p")).toMatchObject({ ok: false, message: MESSAGES.no_topics });
expect(await optIn(deps, "maya", "vs", ["episodes"], "")).toMatchObject({ ok: false, reason: "not_set_up" });
expect(await optIn(deps, "maya", "vs", ["episodes"], "p")).toMatchObject({ ok: false, reason: "denied" });
expect(calls).toHaveLength(0);
});
it("a tapped alert opens only an episode or a channel", () => {
expect(routeFor({ handle: "maya", kind: "episode", title_id: "t1" })).toBe("/c/maya/t1");
expect(routeFor({ handle: "maya", kind: "live", stream_id: "s1" })).toBe("/c/maya");
expect(routeFor({ handle: "../x", kind: "episode", title_id: "t1" })).toBeNull();
expect(routeFor({ handle: "maya", kind: "promo" })).toBeNull();
expect(routeFor(undefined)).toBeNull();
});
it("phones get the notifications plugin; TV builds do not", () => {
const names = (c: ReturnType<typeof config>) => (c.plugins ?? []).map((p) => (Array.isArray(p) ? p[0] : p));
expect(names(config({ config: {} } as never, {} as never))).toContain("expo-notifications");
expect(names(config({ config: {} } as never, { EXPO_TV: "1" } as never))).not.toContain("expo-notifications");
const pkg = JSON.parse(readFileSync(join(__dirname, "../package.json"), "utf8"));
expect(pkg.dependencies["expo-notifications"]).toBeTruthy();
});
});