import { describe, expect, it } from "vitest"; import { MEDIA_PLATFORM_PROFILES, MediaCheckSchema, MediaPlatformIdSchema, PlatformProfileSchema, } from "./media-platforms.js"; import { MEDIA_PRESETS } from "./media-presets.js"; describe("platform profiles", () => { it("ships one valid profile per platform id, keyed by its id", () => { expect(Object.keys(MEDIA_PLATFORM_PROFILES)).toEqual(MediaPlatformIdSchema.options); for (const [id, profile] of Object.entries(MEDIA_PLATFORM_PROFILES)) { expect(PlatformProfileSchema.parse(profile)).toEqual(profile); expect(profile.id).toBe(id); expect(profile.sourceUrls.every((url) => url.startsWith("https://"))).toBe(true); } }); it("uses only the aspect ratios the presets know, at a size of that ratio", () => { const aspects = new Set(Object.values(MEDIA_PRESETS).map((preset) => preset.aspect)); for (const profile of Object.values(MEDIA_PLATFORM_PROFILES)) { expect(aspects.has(profile.video.aspect)).toBe(true); } const tiktok = MEDIA_PLATFORM_PROFILES.tiktok; expect( PlatformProfileSchema.safeParse({ ...tiktok, video: { ...tiktok.video, aspect: "3:2" } }) .success, ).toBe(false); expect( PlatformProfileSchema.safeParse({ ...tiktok, video: { ...tiktok.video, width: 1920 } }) .success, ).toBe(false); expect( PlatformProfileSchema.safeParse({ ...tiktok, duration: { hardMinMs: 5000, hardMaxMs: 4000 }, }).success, ).toBe(false); }); it("keeps the research provenance on every profile", () => { for (const profile of Object.values(MEDIA_PLATFORM_PROFILES)) { expect(profile.reviewedAt).toMatch(/^\d{4}-\d{2}-\d{2}$/); expect(profile.unverified).toBe(true); } }); }); describe("platform check", () => { it("carries language-neutral issue codes with their numbers", () => { expect( MediaCheckSchema.parse({ status: "fail", issues: [ { code: "too_long", maxMs: 600_000, actualMs: 720_000 }, { code: "codec_mismatch" }, ], }).issues, ).toHaveLength(2); expect( MediaCheckSchema.safeParse({ status: "warn", issues: [{ code: "too_blurry" }] }).success, ).toBe(false); expect( MediaCheckSchema.safeParse({ status: "fail", issues: [{ code: "too_long", maxMs: 1 }] }) .success, ).toBe(false); }); });