Skip to content

Commit

Permalink
nip05: use stub to test queryProfile().
Browse files Browse the repository at this point in the history
  • Loading branch information
AsaiToshiya authored and fiatjaf committed Oct 31, 2024
1 parent d062ab8 commit 659ad36
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions nip05.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { test, expect } from 'bun:test'
import fetch from 'node-fetch'

import { useFetchImplementation, queryProfile, NIP05_REGEX, isNip05 } from './nip05.ts'

Expand All @@ -16,7 +15,27 @@ test('validate NIP05_REGEX', () => {
})

test('fetch nip05 profiles', async () => {
useFetchImplementation(fetch)
const fetchStub = async (url: string) => ({
status: 200,
async json() {
return {
'https://compile-error.net/.well-known/nostr.json?name=_': {
names: { _: '2c7cc62a697ea3a7826521f3fd34f0cb273693cbe5e9310f35449f43622a5cdc' },
},
'https://fiatjaf.com/.well-known/nostr.json?name=_': {
names: { _: '3bf0c63fcb93463407af97a5e5ee64fa883d107ef9e558472c4eb9aaaefa459d' },
relays: {
'3bf0c63fcb93463407af97a5e5ee64fa883d107ef9e558472c4eb9aaaefa459d': [
'wss://pyramid.fiatjaf.com',
'wss://nos.lol',
],
},
},
}[url]
},
})

useFetchImplementation(fetchStub)

let p2 = await queryProfile('compile-error.net')
expect(p2!.pubkey).toEqual('2c7cc62a697ea3a7826521f3fd34f0cb273693cbe5e9310f35449f43622a5cdc')
Expand Down

0 comments on commit 659ad36

Please sign in to comment.