mirror of
https://codeberg.org/keyoxide/doipjs.git
synced 2024-12-22 22:49:28 -07:00
Add pattern matching
This commit is contained in:
parent
061c834f84
commit
fad32de571
1 changed files with 31 additions and 0 deletions
|
@ -15,11 +15,38 @@ limitations under the License.
|
||||||
*/
|
*/
|
||||||
const chai = require('chai')
|
const chai = require('chai')
|
||||||
const expect = chai.expect
|
const expect = chai.expect
|
||||||
|
const chaiMatchPattern = require('chai-match-pattern')
|
||||||
|
chai.use(chaiMatchPattern)
|
||||||
chai.use(require("chai-as-promised"))
|
chai.use(require("chai-as-promised"))
|
||||||
|
|
||||||
|
const _ = chaiMatchPattern.getLodashModule()
|
||||||
const request = require('supertest')
|
const request = require('supertest')
|
||||||
const doipjs = require('../src')
|
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', () => {
|
describe('verify', () => {
|
||||||
it('should be a function (3 arguments)', () => {
|
it('should be a function (3 arguments)', () => {
|
||||||
expect(doipjs.verify).to.be.a('function')
|
expect(doipjs.verify).to.be.a('function')
|
||||||
|
@ -34,23 +61,27 @@ describe('verify', () => {
|
||||||
expect(matches).to.be.a('array')
|
expect(matches).to.be.a('array')
|
||||||
expect(matches).to.be.length(1)
|
expect(matches).to.be.length(1)
|
||||||
expect(matches[0].serviceprovider.name).to.be.equal('domain')
|
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 () => {
|
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})
|
const matches = await doipjs.verify('xmpp:alice@domain.org', null, {returnMatchesOnly: true})
|
||||||
expect(matches).to.be.a('array')
|
expect(matches).to.be.a('array')
|
||||||
expect(matches).to.be.length(1)
|
expect(matches).to.be.length(1)
|
||||||
expect(matches[0].serviceprovider.name).to.be.equal('xmpp')
|
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 () => {
|
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})
|
const matches = await doipjs.verify('https://twitter.com/alice/status/1234567890123456789', null, {returnMatchesOnly: true})
|
||||||
expect(matches).to.be.a('array')
|
expect(matches).to.be.a('array')
|
||||||
expect(matches).to.be.length(1)
|
expect(matches).to.be.length(1)
|
||||||
expect(matches[0].serviceprovider.name).to.be.equal('twitter')
|
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 () => {
|
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})
|
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.a('array')
|
||||||
expect(matches).to.be.length(1)
|
expect(matches).to.be.length(1)
|
||||||
expect(matches[0].serviceprovider.name).to.be.equal('hackernews')
|
expect(matches[0].serviceprovider.name).to.be.equal('hackernews')
|
||||||
|
expect(matches[0]).to.matchPattern(pattern)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in a new issue