-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d0aeec0
commit 3b44223
Showing
2 changed files
with
68 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import nock from 'nock'; | ||
import { CashuMint } from '../src/CashuMint.js'; | ||
import { CashuWallet } from '../src/CashuWallet.js'; | ||
import { setGlobalRequestOptions } from '../src/request.js'; | ||
|
||
let request: Record<string, string> | undefined; | ||
const mintUrl = 'https://legend.lnbits.com/cashu/api/v1/4gr9Xcmz3XEkUNwiBiQGoC'; | ||
const invoice = | ||
'lnbc20u1p3u27nppp5pm074ffk6m42lvae8c6847z7xuvhyknwgkk7pzdce47grf2ksqwsdpv2phhwetjv4jzqcneypqyc6t8dp6xu6twva2xjuzzda6qcqzpgxqyz5vqsp5sw6n7cztudpl5m5jv3z6dtqpt2zhd3q6dwgftey9qxv09w82rgjq9qyyssqhtfl8wv7scwp5flqvmgjjh20nf6utvv5daw5h43h69yqfwjch7wnra3cn94qkscgewa33wvfh7guz76rzsfg9pwlk8mqd27wavf2udsq3yeuju'; | ||
|
||
beforeAll(() => { | ||
nock.disableNetConnect(); | ||
}); | ||
|
||
beforeEach(() => { | ||
nock.cleanAll(); | ||
request = undefined; | ||
}); | ||
|
||
describe('requests', () => { | ||
test('request with body contains the correct headers', async () => { | ||
const mint = new CashuMint(mintUrl); | ||
nock(mintUrl) | ||
.post('/checkfees') | ||
.reply(200, function () { | ||
request = this.req.headers; | ||
return { fee: 20 }; | ||
}); | ||
|
||
const wallet = new CashuWallet(mint); | ||
await wallet.getFee(invoice); | ||
|
||
expect(request).toBeDefined(); | ||
expect(request!['content-type']).toContain('application/json'); | ||
expect(request!['accept']).toContain('application/json, text/plain, */*'); | ||
}); | ||
test('global custom headers can be set', async () => { | ||
const mint = new CashuMint(mintUrl); | ||
nock(mintUrl) | ||
.post('/checkfees') | ||
.reply(200, function () { | ||
request = this.req.headers; | ||
return { fee: 20 }; | ||
}); | ||
|
||
const wallet = new CashuWallet(mint); | ||
setGlobalRequestOptions({ headers: { 'x-cashu': 'xyz-123-abc' } }); | ||
await wallet.getFee(invoice); | ||
|
||
expect(request).toBeDefined(); | ||
expect(request!['x-cashu']).toContain('xyz-123-abc'); | ||
}); | ||
}); |