Skip to content

Commit 659ad36

Browse files
AsaiToshiyafiatjaf
authored andcommitted
nip05: use stub to test queryProfile().
1 parent d062ab8 commit 659ad36

File tree

1 file changed

+21
-2
lines changed

1 file changed

+21
-2
lines changed

nip05.test.ts

+21-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { test, expect } from 'bun:test'
2-
import fetch from 'node-fetch'
32

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

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

1817
test('fetch nip05 profiles', async () => {
19-
useFetchImplementation(fetch)
18+
const fetchStub = async (url: string) => ({
19+
status: 200,
20+
async json() {
21+
return {
22+
'https://compile-error.net/.well-known/nostr.json?name=_': {
23+
names: { _: '2c7cc62a697ea3a7826521f3fd34f0cb273693cbe5e9310f35449f43622a5cdc' },
24+
},
25+
'https://fiatjaf.com/.well-known/nostr.json?name=_': {
26+
names: { _: '3bf0c63fcb93463407af97a5e5ee64fa883d107ef9e558472c4eb9aaaefa459d' },
27+
relays: {
28+
'3bf0c63fcb93463407af97a5e5ee64fa883d107ef9e558472c4eb9aaaefa459d': [
29+
'wss://pyramid.fiatjaf.com',
30+
'wss://nos.lol',
31+
],
32+
},
33+
},
34+
}[url]
35+
},
36+
})
37+
38+
useFetchImplementation(fetchStub)
2039

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

0 commit comments

Comments
 (0)