From fad32de5710aafe062210d7b4fc091e3ddbc14db Mon Sep 17 00:00:00 2001 From: Yarmo Mackenbach Date: Sat, 24 Oct 2020 23:36:25 +0200 Subject: [PATCH] Add pattern matching --- test/verify.test.js | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) 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) }) })