2018-12-17 15:54:58 +01:00
|
|
|
import * as assert from "assert"
|
|
|
|
import DID from "../../src/ocean/DID"
|
|
|
|
|
|
|
|
describe("DID", () => {
|
|
|
|
|
|
|
|
describe("#generate()", () => {
|
|
|
|
it("should generate a new did", () => {
|
|
|
|
const did: DID = DID.generate()
|
|
|
|
assert(did)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
describe("#parse()", () => {
|
|
|
|
it("should parse a valid did", () => {
|
|
|
|
|
2019-01-22 14:14:49 +01:00
|
|
|
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) => {
|
|
|
|
|
|
|
|
const id = "1234"
|
|
|
|
try {
|
|
|
|
const did: DID = DID.parse(`did:xxx:${id}`)
|
|
|
|
assert(!did)
|
|
|
|
} catch {
|
|
|
|
done()
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
it("should throw if id does not match", (done) => {
|
|
|
|
|
2019-01-22 14:14:49 +01: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()
|
|
|
|
}
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
describe("#getDid()", () => {
|
|
|
|
it("should return the full did", () => {
|
|
|
|
|
|
|
|
const did: DID = DID.generate()
|
|
|
|
assert(did)
|
|
|
|
|
|
|
|
assert(did.getDid().startsWith("did:op:"))
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
describe("#getDid()", () => {
|
|
|
|
it("should return only the id part of the did", () => {
|
|
|
|
|
2019-01-22 14:14:49 +01:00
|
|
|
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)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|