Skip to content

Commit

Permalink
feat: Universal resolver unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
simonas-notcat committed May 6, 2020
1 parent 5efd82c commit 8b92d1c
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 6 deletions.
1 change: 1 addition & 0 deletions packages/daf-resolver-universal/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
},
"devDependencies": {
"@types/debug": "^4.1.5",
"jest-fetch-mock": "^3.0.3",
"typescript": "^3.8.3"
},
"files": [
Expand Down
6 changes: 0 additions & 6 deletions packages/daf-resolver-universal/src/__tests__/default.test.ts

This file was deleted.

24 changes: 24 additions & 0 deletions packages/daf-resolver-universal/src/__tests__/resolver.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { DafUniversalResolver } from '../resolver'
import fetchMock from 'jest-fetch-mock'
fetchMock.enableMocks()

describe('daf-resolver-universal', () => {
it('should throw error when misconfigured', () => {
expect(() => {
//@ts-ignore
new DafUniversalResolver({})
}).toThrow()
})

it('should have resolve method', () => {
const resolver = new DafUniversalResolver({ url: 'https://example/' })
expect(resolver).toHaveProperty('resolve')
})

it('should fetch did doc', async () => {
const resolver = new DafUniversalResolver({ url: 'https://example/' })
fetchMock.mockResponse(JSON.stringify({ didDocument: { data: '12345' } }))
const doc = await resolver.resolve('did:example:123')
expect(doc).toEqual({ data: '12345' })
})
})
2 changes: 2 additions & 0 deletions packages/daf-resolver-universal/src/resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ export class DafUniversalResolver {
private url: string

constructor(options: Options) {
if (!options.url) throw Error('[daf-resolver-universal] url required')
debug(options.url)
this.url = options.url
}

Expand Down

0 comments on commit 8b92d1c

Please sign in to comment.