This repository has been archived by the owner on Jan 8, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: allow passing custom default resolvers
- Loading branch information
Showing
2 changed files
with
47 additions
and
6 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,41 @@ | ||
/* eslint-env mocha */ | ||
This comment has been minimized.
Sorry, something went wrong. |
||
|
||
import { expect } from 'aegir/chai' | ||
import { MemoryDatastore } from 'datastore-core' | ||
import { type Datastore } from 'interface-datastore' | ||
import { stub } from 'sinon' | ||
import { type StubbedInstance, stubInterface } from 'sinon-ts' | ||
import { type IPNSRouting, ipns } from '../src/index.js' | ||
|
||
describe('resolveDns', () => { | ||
let routing: StubbedInstance<IPNSRouting> | ||
let datastore: Datastore | ||
|
||
beforeEach(async () => { | ||
datastore = new MemoryDatastore() | ||
routing = stubInterface<IPNSRouting>() | ||
routing.get.throws(new Error('Not found')) | ||
}) | ||
|
||
it('should use resolvers passed in constructor', async () => { | ||
const stubbedResolver1 = stub().returns('dnslink=/ipfs/QmUNLLsPACCz1vLxQVkXqqLX5R1X345qqfHbsf67hvA3Nn') | ||
|
||
const name = ipns({ datastore }, [routing], [stubbedResolver1]) | ||
const result = await name.resolveDns('foobar.baz', { nocache: true, offline: true }) | ||
expect(stubbedResolver1.called).to.be.true() | ||
expect(stubbedResolver1.calledWith('foobar.baz')).to.be.true() | ||
expect(result.toString()).to.equal('QmUNLLsPACCz1vLxQVkXqqLX5R1X345qqfHbsf67hvA3Nn') | ||
}) | ||
|
||
it('should allow overriding of resolvers passed in constructor', async () => { | ||
const stubbedResolver1 = stub().returns('dnslink=/ipfs/QmUNLLsPACCz1vLxQVkXqqLX5R1X345qqfHbsf67hvA3Nn') | ||
const stubbedResolver2 = stub().returns('dnslink=/ipfs/bafkreibm6jg3ux5qumhcn2b3flc3tyu6dmlb4xa7u5bf44yegnrjhc4yeq') | ||
|
||
const name = ipns({ datastore }, [routing], [stubbedResolver1]) | ||
const result = await name.resolveDns('foobar.baz', { nocache: true, offline: true, resolvers: [stubbedResolver2] }) | ||
expect(stubbedResolver1.called).to.be.false() | ||
expect(stubbedResolver2.called).to.be.true() | ||
expect(stubbedResolver2.calledWith('foobar.baz')).to.be.true() | ||
expect(result.toString()).to.equal('bafkreibm6jg3ux5qumhcn2b3flc3tyu6dmlb4xa7u5bf44yegnrjhc4yeq') | ||
}) | ||
}) |
This is a nit, but please can you follow the conventions of the existing code. All files should be kebab-case.