import assert from 'node:assert/strict' import { test } from 'node:test' import { errorPage, renderPage, shortDate } from '../src/page.ts' import { PLAYER_JS } from '../src/player.ts' import { MEMBERSHIP_DAYS, MEMBERSHIP_TTL_MS, SIGNUP_URL } from '../src/config.ts' test('player script parses', () => { assert.doesNotThrow(() => new Function(PLAYER_JS)) }) test('signed-out page offers Kody sign-in and the referral sign-up link', () => { const html = renderPage('/mega-radio', { kind: 'signed-out', loginHref: '/-/auth/login?app=mega-radio' }) assert.ok(html.includes(SIGNUP_URL) && SIGNUP_URL === 'https://kody.codes/signup?ref=noah') assert.ok(!html.includes('/files/radio/'), 'no audio URLs before verification') assert.match(html, /Sign in with Kody<\/a>/) assert.match(html, /class="pill ghost" href="https:\/\/kody\.codes\/signup\?ref=noah"[^>]*>Create a Free Account<\/a>/) assert.ok(html.includes('Sign in to listen') && html.includes("Sign in, then confirm you're in the MEGA.dev Discord.")) }) test('MEGA Radio name appears only in the header (no big h1, not in the sign-in title)', () => { for (const s of [ { kind: 'signed-out', loginHref: '/l' }, { kind: 'unverified', username: 'n', logoutHref: '/x' }, { kind: 'member', username: 'n', logoutHref: '/x', discordName: null, expiresAt: '2026-11-27T00:00:00Z' }, ] as const) { const html = renderPage('/mega-radio', s) assert.ok(!html.includes('MEGA Radio')) } }) test('a Discord check is good for 30 days', () => { assert.equal(MEMBERSHIP_DAYS, 30) assert.equal(MEMBERSHIP_TTL_MS, 30 * 86_400_000) const html = renderPage('/mega-radio', { kind: 'unverified', username: 'n', logoutHref: '/x' }) assert.ok(html.includes('A check is good for 30 days.')) assert.ok(renderPage('/mega-radio', { kind: 'signed-out', loginHref: '/l' }).includes('unlocks the radio for 30 days')) }) test('member page has players and a repeat icon button, off by default', () => { const html = renderPage('/mega-radio', { kind: 'member', username: 'n', logoutHref: '/x', discordName: 'Noah', expiresAt: '2026-11-04T00:00:00Z' }) assert.ok(html.includes('data-src="/mega-radio/files/radio/01.mp3"') && html.includes('data-src="/mega-radio/files/radio/02.mp3"') && html.includes('data-src="/mega-radio/files/radio/03.mp3"') && html.includes('data-src="/mega-radio/files/radio/04.mp3"') && html.includes('data-src="/mega-radio/files/radio/05.mp3"')) assert.ok(!html.includes('/files/radio/06.mp3')) assert.match(html, /