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

67 lines
1.5 KiB
TypeScript
Raw Normal View History

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