first commit
This commit is contained in:
@@ -0,0 +1,65 @@
|
||||
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')
|
||||
})
|
||||
Reference in New Issue
Block a user