Set up Playwright with Chromium, dev server auto-start, test helpers for seeding bots and programmatic auth. Added smoke spec that verifies homepage and leaderboard load without crashes. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
38 lines
1015 B
TypeScript
38 lines
1015 B
TypeScript
/**
|
|
* E2E authentication helpers.
|
|
* Provides programmatic login for tests without browser extension interaction.
|
|
*/
|
|
|
|
import { randomPubkey } from './setup.js'
|
|
|
|
/**
|
|
* Create a test identity (pubkey + nsec equivalent).
|
|
* For E2E tests, we use direct pubkey-based login (legacy endpoint)
|
|
* since we can't interact with NIP-07 browser extensions.
|
|
*/
|
|
export function createTestIdentity() {
|
|
return {
|
|
pubkey: randomPubkey(),
|
|
// In a real NIP-98 flow, this would be a signed event
|
|
// For testing, we use the legacy login endpoint
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Login via legacy endpoint and get bot data.
|
|
* Returns bot info if the pubkey has a registered bot.
|
|
*/
|
|
export async function loginWithPubkey(baseURL: string, pubkey: string): Promise<{ bot?: { id: string; name: string } }> {
|
|
const res = await fetch(`${baseURL}/api/auth/login`, {
|
|
method: 'POST',
|
|
headers: { 'Content-Type': 'application/json' },
|
|
body: JSON.stringify({ pubkey }),
|
|
})
|
|
|
|
if (!res.ok) {
|
|
return {}
|
|
}
|
|
|
|
return res.json()
|
|
}
|