Something went wrong. Try again.
Monorepo for wisp.place. A static site hosting service built on top of the AT Protocol.
Something went wrong. Try again.
2.0 kB · 58 lines
TypeScript
at main
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859import { beforeEach, describe, expect, test } from 'bun:test'import { createApp, resolveHostConfig } from './server'
const OWNER_DID = 'did:plc:alice'const domainLookups: string[] = []const served: Array<{ did: string; rkey: string; path: string }> = []
const app = createApp({ hosts: resolveHostConfig({ BASE_HOST: 'wisp.place', PREVIEW_HOST: 'preview.wisp.place' }), getWispDomain: async (domain) => { domainLookups.push(domain) return domain === 'alice.wisp.place' ? { did: OWNER_DID, rkey: 'main-site' } : null }, getCustomDomain: async () => null, getCustomDomainByHash: async () => null, serveFromCache: async (did, rkey, path) => { served.push({ did, rkey, path }) return new Response('preview body') }, serveFromCacheWithRewrite: async () => new Response('unexpected'), metrics: { recordHostingResponse: () => {}, recordHostingNotFound: () => {} }, notFoundLog: { record: () => {} },})
describe('preview host routing', () => { beforeEach(() => { domainLookups.length = 0 served.length = 0 })
test("serves the pr site from the claim owner, ignoring the claim's mapped site", async () => { const response = await app.request('https://pr-ab12cd3-alice.preview.wisp.place/docs/index.html')
expect(response.status).toBe(200) expect(await response.text()).toBe('preview body') expect(domainLookups).toEqual(['alice.wisp.place']) expect(served).toEqual([{ did: OWNER_DID, rkey: 'pr-ab12cd3', path: 'docs/index.html' }]) })
test('404s an unregistered claim', async () => { const response = await app.request('https://pr-ab12cd3-nobody.preview.wisp.place/')
expect(response.status).toBe(404) expect(served).toEqual([]) })
test.each([ 'https://preview.wisp.place/', 'https://main-alice.preview.wisp.place/', 'https://x.pr-ab12cd3-alice.preview.wisp.place/', ])('404s %s without a database lookup', async (url) => { const response = await app.request(url)
expect(response.status).toBe(404) expect(domainLookups).toEqual([]) expect(served).toEqual([]) })})