diff --git a/test/verify.test.js b/test/verify.test.js index f31ab04..2241f59 100644 --- a/test/verify.test.js +++ b/test/verify.test.js @@ -15,11 +15,38 @@ limitations under the License. */ const chai = require('chai') const expect = chai.expect +const chaiMatchPattern = require('chai-match-pattern') +chai.use(chaiMatchPattern) chai.use(require("chai-as-promised")) +const _ = chaiMatchPattern.getLodashModule() const request = require('supertest') const doipjs = require('../src') +const pattern = { + serviceprovider: { + type: _.isString, + name: _.isString + }, + profile: { + display: _.isString, + uri: _.isString + }, + proof: { + uri: (x) => { return _.isString(x) || _.isNull(x) }, + fetch: (x) => { return _.isString(x) || _.isNull(x) }, + useProxy: _.isBoolean, + format: _.isString + }, + claim: { + fingerprint: (x) => { return _.isString(x) || _.isNull(x) }, + format: _.isString, + path: _.isArray, + relation: _.isString + }, + qr: (x) => { return _.isString(x) || _.isNull(x) } +} + describe('verify', () => { it('should be a function (3 arguments)', () => { expect(doipjs.verify).to.be.a('function') @@ -34,23 +61,27 @@ describe('verify', () => { expect(matches).to.be.a('array') expect(matches).to.be.length(1) expect(matches[0].serviceprovider.name).to.be.equal('domain') + expect(matches[0]).to.matchPattern(pattern) }) it('should match "xmpp:alice@domain.org" to the XMPP service provider', async () => { const matches = await doipjs.verify('xmpp:alice@domain.org', null, {returnMatchesOnly: true}) expect(matches).to.be.a('array') expect(matches).to.be.length(1) expect(matches[0].serviceprovider.name).to.be.equal('xmpp') + expect(matches[0]).to.matchPattern(pattern) }) it('should match "https://twitter.com/alice/status/1234567890123456789" to the Twitter service provider', async () => { const matches = await doipjs.verify('https://twitter.com/alice/status/1234567890123456789', null, {returnMatchesOnly: true}) expect(matches).to.be.a('array') expect(matches).to.be.length(1) expect(matches[0].serviceprovider.name).to.be.equal('twitter') + expect(matches[0]).to.matchPattern(pattern) }) it('should match "https://news.ycombinator.com/user?id=Alice" to the Hackernews service provider', async () => { const matches = await doipjs.verify('https://news.ycombinator.com/user?id=Alice', null, {returnMatchesOnly: true}) expect(matches).to.be.a('array') expect(matches).to.be.length(1) expect(matches[0].serviceprovider.name).to.be.equal('hackernews') + expect(matches[0]).to.matchPattern(pattern) }) })