Skip to content

Black Friday

Annual Pro is $90 for the first year, normally $120. Or start monthly at $6 for two months, then $12.

Ends Dec 4, 11:59 PM PT.

Create an account
← Public packages

@noah/mega-radio

MEGA Radio (the WAKE album) for members of the MEGA.dev Discord: sign in with Kody, verify with Discord, listen with repeat.

FollowForkOpen app

Files

origin-move.test.ts

37 lines · 1.7 KB · TypeScript
/**
 * The app is served on two addresses until December 17, 2026: https://noah.kody.run/mega-radio/ (appBasePath
 * '/mega-radio') and https://mega-radio--noah.kody.run/ (appBasePath ''). Every link must follow the base.
 */
import { test } from 'node:test'
import assert from 'node:assert/strict'
import { renderPage } from '../src/page.ts'
import { signArt } from '../src/art.ts'
import { fileRoute } from '../src/audio-core.ts'
import { HOSTED_URL } from '../src/config.ts'

const member = { kind: 'member' as const, username: 'n', logoutHref: '/-/auth/logout?app=mega-radio', discordName: 'Noah', expiresAt: '2026-12-31T00:00:00Z' }

for (const base of ['/mega-radio', '']) {
	test(`page links follow the base (${base || 'new origin'})`, () => {
		const html = renderPage(base, member)
		assert.ok(html.includes(`<html lang="en" data-app-base="${base}">`))
		assert.ok(html.includes(`<script src="${base}/player.js"`))
		assert.ok(html.includes(`<a class="home" href="${base}/">`))
		assert.ok(html.includes(`action="${base}/forget"`))
		assert.ok(!html.includes('noah.kody.run'))
		if (!base) assert.ok(!html.includes('/mega-radio/'))
	})
	test(`signed art URLs follow the base (${base || 'new origin'})`, async () => {
		const u = await signArt(base, 3, '0'.repeat(64), 0)
		assert.ok(u.startsWith(`${base}/art/03.png?exp=`))
	})
}

test('routes are matched on the base-stripped path, the same on both origins', () => {
	assert.deepEqual(fileRoute('/files/radio/03.mp3')?.key, 'radio/03.mp3')
	assert.equal(fileRoute('/mega-radio/files/radio/03.mp3'), null)
})

test('the fallback address is the new per-app origin', () => {
	assert.equal(HOSTED_URL, 'https://mega-radio--noah.kody.run')
})