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

61 lines
1.5 KiB
TypeScript
Raw Normal View History

2019-06-20 00:20:09 +02:00
import * as assert from 'assert'
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())
})
2019-06-20 00:20:09 +02:00
it('should throw if prefix does not match', done => {
const id = '1234'
2018-12-17 15:54:58 +01:00
try {
const did: DID = DID.parse(`did:xxx:${id}`)
assert(!did)
} catch {
done()
}
})
2019-06-20 00:20:09 +02:00
it('should throw if id does not match', done => {
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)
})
})
})