Files
tab-bot/apps/web/e2e/mocked-host.spec.ts
T
2026-09-06 19:10:40 -04:00

66 lines
1.8 KiB
TypeScript

import { expect, test } from '@playwright/test'
test('mocked DiscordJS ping path does not put token in the URL', async ({ page }) => {
await page.addInitScript(() => {
const listeners: Record<string, ((...a: unknown[]) => void)[]> = {}
const client = {
user: { id: '1', tag: 'Ping#0000' },
ws: { ping: 12 },
once(ev: string, fn: (...a: unknown[]) => void) {
listeners[ev] = listeners[ev] || []
listeners[ev].push(fn)
return this
},
on(ev: string, fn: (...a: unknown[]) => void) {
listeners[ev] = listeners[ev] || []
listeners[ev].push(fn)
return this
},
async login() {
for (const fn of listeners.clientReady || listeners.ready || []) fn({ user: this.user })
},
async destroy() {},
}
const DiscordJS = {
GatewayIntentBits: { Guilds: 1, DirectMessages: 2 },
Events: { ClientReady: 'clientReady', InteractionCreate: 'interactionCreate' },
SlashCommandBuilder: class {
setName() {
return this
}
setDescription() {
return this
}
toJSON() {
return { name: 'ping' }
}
},
REST: class {
setToken() {
return this
}
async put() {}
},
Routes: { applicationCommands: () => '/commands' },
Client: class {
constructor() {
return client
}
},
async status() {
return { enabled: true, loaded: true, clients: 0, maxClients: 4 }
},
async ready() {
return DiscordJS
},
}
window.BridgeSwarm = {
ready: async () => window.BridgeSwarm,
DiscordJS,
}
})
await page.goto('/health')
await expect(page.locator('pre')).toContainText('ready')
expect(page.url()).not.toContain('token')
})