Skip to content

Commit

Permalink
chore: harden custom dns resolver test
Browse files Browse the repository at this point in the history
  • Loading branch information
SgtPooki committed Feb 21, 2024
1 parent fcc5c32 commit fc1e5b8
Showing 1 changed file with 5 additions and 10 deletions.
15 changes: 5 additions & 10 deletions packages/verified-fetch/test/verified-fetch.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -526,26 +526,21 @@ describe('@helia/verifed-fetch', () => {

describe('custom dns-resolvers', () => {
it('uses custom dnsResolvers if provided', async () => {
const customResolver1 = Sinon.stub()
const customResolver2 = Sinon.stub()
const customDnsResolver = Sinon.stub()
const onProgress = Sinon.stub()

customResolver1.rejects(new Error('Could not resolve PeerId "mydomain.com"'))
customResolver2.returns(Promise.resolve('/ipfs/QmVP2ip92jQuMDezVSzQBWDqWFbp9nyCHNQSiciRauPLDg'))
customDnsResolver.returns(Promise.resolve('/ipfs/QmVP2ip92jQuMDezVSzQBWDqWFbp9nyCHNQSiciRauPLDg'))

const verifiedFetch = new VerifiedFetch({
helia
}, {
dnsResolvers: [customResolver1, customResolver2]
dnsResolvers: [customDnsResolver]
})
// error of walking the CID/dag because we haven't actually added the block to the blockstore
await expect(verifiedFetch.fetch('ipns://mydomain.com', { onProgress })).to.eventually.be.rejectedWith('All promises were rejected')

expect(customResolver1.callCount).to.equal(1)
expect(customResolver1.getCall(0).args).to.deep.equal(['mydomain.com', { onProgress }])
await expect(customResolver1.getCall(0).returnValue).to.eventually.be.rejectedWith('Could not resolve PeerId "mydomain.com"')
expect(customResolver2.callCount).to.equal(1)
expect(customResolver2.getCall(0).args).to.deep.equal(['mydomain.com', { onProgress }])
expect(customDnsResolver.callCount).to.equal(1)
expect(customDnsResolver.getCall(0).args).to.deep.equal(['mydomain.com', { onProgress }])
})
})
})

0 comments on commit fc1e5b8

Please sign in to comment.