2026-03-13 05:14:15 +00:00
|
|
|
/**
|
|
|
|
|
* E2E authentication helpers.
|
2026-07-30 22:31:26 -04:00
|
|
|
* Provides a programmatic bot lookup for tests without browser extension interaction.
|
2026-03-13 05:14:15 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
import { randomPubkey } from './setup.js'
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Create a test identity (pubkey + nsec equivalent).
|
2026-07-30 22:31:26 -04:00
|
|
|
* For E2E tests, we use the read-only lookup helper below (loginWithPubkey)
|
2026-03-13 05:14:15 +00:00
|
|
|
* 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
|
2026-07-30 22:31:26 -04:00
|
|
|
// For testing, we use the deprecated read-only lookup endpoint
|
2026-03-13 05:14:15 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2026-07-30 22:31:26 -04:00
|
|
|
* 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.
|
2026-03-13 05:14:15 +00:00
|
|
|
*/
|
|
|
|
|
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()
|
|
|
|
|
}
|