1
0
mirror of https://github.com/oceanprotocol-archive/squid-js.git synced 2024-02-02 15:31:51 +01:00
squid-js/test/unit/ocean/DID.test.ts

61 lines
1.5 KiB
TypeScript
Raw Permalink Normal View History

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())
})
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()
}
})
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)
})
})
})