Files
botfights/e2e/helpers/auth.ts
T

42 lines
1.3 KiB
TypeScript
Raw Normal View History

/**
* E2E authentication helpers.
* Provides a programmatic bot lookup for tests without browser extension interaction.
*/
import { randomPubkey } from './setup.js'
/**
* Create a test identity (pubkey + nsec equivalent).
* For E2E tests, we use the read-only lookup helper below (loginWithPubkey)
* 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 deprecated read-only lookup endpoint
}
}
/**
* Look up a bot by pubkey via the deprecated, read-only POST /api/auth/login
* endpoint. This is NOT a login — it establishes no session and issues no
* token (D-01/BOT-01). It's kept only as a test helper: real session
* establishment goes through POST /api/auth/nostr/session (NIP-98) and
* session restoration through GET /api/auth/me (JWT). Returns bot info if
* the pubkey has a registered bot, `{}` otherwise.
*/
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()
}