2019-11-11 12:27:18 +01:00
|
|
|
import assert from 'assert'
|
2020-01-30 22:08:18 +01:00
|
|
|
import DID from '../../../src/ocean/DID'
|
2018-12-17 15:54:58 +01:00
|
|
|
|
2019-06-20 00:20:09 +02:00
|
|
|
describe('DID', () => {
|
|
|
|
describe('#generate()', () => {
|
|
|
|
it('should generate a new did', () => {
|
2018-12-17 15:54:58 +01:00
|
|
|
const did: DID = DID.generate()
|
|
|
|
assert(did)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2019-06-20 00:20:09 +02:00
|
|
|
describe('#parse()', () => {
|
|
|
|
it('should parse a valid did', () => {
|
|
|
|
const id = 'a'.repeat(64)
|
2018-12-17 15:54:58 +01:00
|
|
|
const did: DID = DID.parse(`did:op:${id}`)
|
|
|
|
assert(did)
|
|
|
|
|
|
|
|
assert(did.getId() === id, did.getId())
|
|
|
|
})
|
|
|
|
|
2020-05-19 16:15:56 +02:00
|
|
|
it('should throw if prefix does not match', (done) => {
|
2019-06-20 00:20:09 +02:00
|
|
|
const id = '1234'
|
2018-12-17 15:54:58 +01:00
|
|
|
try {
|
|
|
|
const did: DID = DID.parse(`did:xxx:${id}`)
|
|
|
|
assert(!did)
|
|
|
|
} catch {
|
|
|
|
done()
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2020-05-19 16:15:56 +02:00
|
|
|
it('should throw if id does not match', (done) => {
|
2019-06-20 00:20:09 +02:00
|
|
|
const id = 'xyz'
|
2018-12-17 15:54:58 +01:00
|
|
|
try {
|
|
|
|
const did: DID = DID.parse(`did:op:${id}`)
|
|
|
|
assert(!did)
|
|
|
|
} catch {
|
|
|
|
done()
|
|
|
|
}
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2019-06-20 00:20:09 +02:00
|
|
|
describe('#getDid()', () => {
|
|
|
|
it('should return the full did', () => {
|
2018-12-17 15:54:58 +01:00
|
|
|
const did: DID = DID.generate()
|
|
|
|
assert(did)
|
|
|
|
|
2019-06-20 00:20:09 +02:00
|
|
|
assert(did.getDid().startsWith('did:op:'))
|
2018-12-17 15:54:58 +01:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2019-06-20 00:20:09 +02:00
|
|
|
describe('#getDid()', () => {
|
|
|
|
it('should return only the id part of the did', () => {
|
|
|
|
const id = 'a'.repeat(64)
|
2018-12-17 15:54:58 +01:00
|
|
|
const did: DID = DID.parse(`did:op:${id}`)
|
|
|
|
assert(did)
|
|
|
|
|
|
|
|
assert(did.getId() === id)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|