forked from ubiquity/ubq.fi-router
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsitemap.test.ts
More file actions
55 lines (48 loc) · 1.73 KB
/
Copy pathsitemap.test.ts
File metadata and controls
55 lines (48 loc) · 1.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import { describe, expect, test } from 'bun:test'
import worker, { type Env } from '../src/worker'
import { buildRouteMap } from '../src/sitemap'
const githubResponse = [
{ name: 'ubq.fi' },
{ name: 'pay.ubq.fi' },
{ name: 'ubiquity-os-kernel' },
{ name: 'old.ubq.fi', archived: true },
]
describe('dynamic route map', () => {
test('builds JSON route map from active GitHub repos', async () => {
globalThis.fetch = (async () => Response.json(githubResponse)) as unknown as typeof fetch
const entries = await buildRouteMap('https://ubq.fi')
expect(entries).toEqual([
{
type: 'plugin',
name: 'ubiquity-os-kernel',
host: 'os-kernel.ubq.fi',
url: 'https://os-kernel.ubq.fi/',
upstream: 'https://kernel-main.deno.dev/',
},
{
type: 'app',
name: 'pay.ubq.fi',
host: 'pay.ubq.fi',
url: 'https://pay.ubq.fi/',
upstream: 'https://pay-ubq-fi.ubiquity-dao.deno.net/',
},
{
type: 'app',
name: 'ubq.fi',
host: 'ubq.fi',
url: 'https://ubq.fi/',
upstream: 'https://ubq-fi.ubiquity-dao.deno.net/',
},
])
})
test('serves sitemap xml through the worker', async () => {
globalThis.fetch = (async () => Response.json(githubResponse)) as unknown as typeof fetch
const res = await worker.fetch(new Request('https://ubq.fi/sitemap.xml'), {} as Env)
const body = await res.text()
expect(res.status).toBe(200)
expect(res.headers.get('content-type')).toContain('application/xml')
expect(res.headers.get('x-uos-router-revision')).toBe('local')
expect(body).toContain('<loc>https://pay.ubq.fi/</loc>')
expect(body).toContain('<loc>https://os-kernel.ubq.fi/</loc>')
})
})