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
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.
77 lines
4.2 KiB
TypeScript
77 lines
4.2 KiB
TypeScript
import { readFileSync } from "node:fs";
|
|
import { join } from "node:path";
|
|
import { describe, expect, it, vi } from "vitest";
|
|
import { createClient } from "../src/api/client";
|
|
import type { Offer } from "../src/api/ott";
|
|
import { readConfig } from "../src/config";
|
|
import { COPY, formatPrice } from "../src/checkout/copy";
|
|
import { buyOnHostedCheckout, checkoutMode, offersFor, unlocks, waitForUnlock } from "../src/checkout/hosted";
|
|
|
|
const ROOT = join(__dirname, "..");
|
|
const BUY: Offer = { id: "o1", kind: "tvod", title_id: "t1", name: "Own", price_cents: 999, currency: "USD", interval: null,
|
|
rental_hours: null };
|
|
const SVOD: Offer = { ...BUY, id: "o2", kind: "svod", title_id: null, name: "Members", price_cents: 500, interval: "month" };
|
|
|
|
function api(entitlementAnswers: unknown[][]) {
|
|
const calls: { url: string; init?: RequestInit }[] = [];
|
|
let reads = 0;
|
|
const fetcher = vi.fn(async (url: string, init?: RequestInit) => {
|
|
calls.push({ url, init });
|
|
let body: unknown = {};
|
|
if (url.endsWith("/checkout")) body = { data: { url: "https://test.checkout.example/cs_1" } };
|
|
if (url.endsWith("/entitlements")) {
|
|
body = { data: { items: entitlementAnswers[Math.min(reads, entitlementAnswers.length - 1)] } };
|
|
reads += 1;
|
|
}
|
|
return { ok: true, status: 200, json: async () => body } as Response;
|
|
});
|
|
return { client: createClient("https://api.example/api/v1", fetcher), calls };
|
|
}
|
|
|
|
describe("hosted checkout", () => {
|
|
it("opens the creator's checkout and unlocks once the grant lands", async () => {
|
|
const granted = [{ id: "e1", kind: "tvod", title_id: "t1", status: "active", expires_at: null }];
|
|
const { client, calls } = api([[], [], granted]);
|
|
const opened: string[] = [];
|
|
const result = await buyOnHostedCheckout(
|
|
{ api: client, openBrowser: async (url) => void opened.push(url), sleep: async () => undefined },
|
|
{ handle: "maya", session: "vs-1", offer: BUY, titleId: "t1", couponCode: "SAVE20" });
|
|
expect(opened).toEqual(["https://test.checkout.example/cs_1"]);
|
|
expect(result).toEqual({ unlocked: true, checkedTimes: 3 });
|
|
const checkout = calls.find((c) => c.url.endsWith("/checkout"));
|
|
expect(JSON.parse(String(checkout?.init?.body))).toEqual({ offer_id: "o1", coupon_code: "SAVE20" });
|
|
expect((checkout?.init?.headers as Record<string, string>)["X-OTT-Viewer"]).toBe("vs-1");
|
|
});
|
|
|
|
it("does not unlock from the browser result alone", async () => {
|
|
const { client } = api([[]]);
|
|
const result = await waitForUnlock({ api: client, openBrowser: async () => undefined, sleep: async () => undefined,
|
|
attempts: 4 }, "maya", "vs-1", "t1");
|
|
expect(result).toEqual({ unlocked: false, checkedTimes: 4 });
|
|
});
|
|
|
|
it("a subscription unlocks every title; a refund does not", () => {
|
|
expect(unlocks([{ id: "e", kind: "svod", title_id: null, status: "active", expires_at: null }], "t9")).toBe(true);
|
|
expect(unlocks([{ id: "e", kind: "tvod", title_id: "t1", status: "revoked", expires_at: null }], "t1")).toBe(false);
|
|
expect(offersFor([BUY, SVOD, { ...BUY, id: "o3", title_id: "t2" }], "t1").map((o) => o.id)).toEqual(["o1", "o2"]);
|
|
});
|
|
|
|
it("iOS stays a reader app unless the owner turns external links on", () => {
|
|
expect(checkoutMode("ios", { externalCheckoutIos: false })).toBe("reader");
|
|
expect(checkoutMode("ios", { externalCheckoutIos: true })).toBe("link");
|
|
expect(checkoutMode("android", { externalCheckoutIos: false })).toBe("link");
|
|
expect(checkoutMode("tv", { externalCheckoutIos: false })).toBe("link");
|
|
expect(readConfig({}).externalCheckoutIos).toBe(false);
|
|
expect(readConfig({ externalCheckoutIos: true }).externalCheckoutIos).toBe(true);
|
|
});
|
|
|
|
it("uses no in-app store purchase library and says who is paid", () => {
|
|
const pkg = JSON.parse(readFileSync(join(ROOT, "package.json"), "utf8"));
|
|
const deps = Object.keys({ ...pkg.dependencies, ...pkg.devDependencies });
|
|
expect(deps).toContain("expo-web-browser");
|
|
expect(deps.filter((d) => /purchase|iap|revenuecat|billing/i.test(d))).toEqual([]);
|
|
expect(COPY.paysCreator).toMatch(/creator directly/);
|
|
expect(formatPrice({ ...BUY, kind: "rental", rental_hours: 48, price_cents: 299 })).toBe("$2.99 for 48 hours");
|
|
});
|
|
});
|