2019-06-20 00:20:09 +02:00
|
|
|
import { assert } from 'chai'
|
2019-09-09 12:18:54 +02:00
|
|
|
import { zeroX, noZeroX, didPrefixed, noDidPrefixed } from '../../src/utils/ConversionTypeHelpers'
|
2019-03-04 13:30:34 +01:00
|
|
|
|
2019-06-20 00:20:09 +02:00
|
|
|
describe('ConversionTypeHelpers', () => {
|
|
|
|
describe('#zeroXTransformer()', () => {
|
2019-03-04 13:30:34 +01:00
|
|
|
it("should return the input if it's not hex value", async () => {
|
2019-06-20 00:20:09 +02:00
|
|
|
const result1 = zeroX('Test 1')
|
|
|
|
const result2 = noZeroX('Test 2')
|
|
|
|
assert.equal(result1, 'Test 1')
|
|
|
|
assert.equal(result2, 'Test 2')
|
2019-03-04 13:30:34 +01:00
|
|
|
})
|
|
|
|
|
2019-06-20 00:20:09 +02:00
|
|
|
it('should return the value with 0x prefix', async () => {
|
|
|
|
const result1 = zeroX('0x1234')
|
|
|
|
const result2 = zeroX('1234')
|
|
|
|
assert.equal(result1, '0x1234')
|
|
|
|
assert.equal(result2, '0x1234')
|
2019-03-04 13:30:34 +01:00
|
|
|
})
|
|
|
|
|
2019-06-20 00:20:09 +02:00
|
|
|
it('should return the value without 0x prefix', async () => {
|
|
|
|
const result1 = noZeroX('0x1234')
|
|
|
|
const result2 = noZeroX('1234')
|
|
|
|
assert.equal(result1, '1234')
|
|
|
|
assert.equal(result2, '1234')
|
2019-03-04 13:30:34 +01:00
|
|
|
})
|
|
|
|
})
|
2019-03-11 22:46:27 +01:00
|
|
|
|
2019-06-20 00:20:09 +02:00
|
|
|
describe('#didTransformer()', () => {
|
|
|
|
const did = 'a'.repeat(64)
|
2019-03-11 22:46:27 +01:00
|
|
|
|
|
|
|
it("should return the input if it's not valid", async () => {
|
2019-06-20 00:20:09 +02:00
|
|
|
const result1 = didPrefixed('Test 1')
|
|
|
|
const result2 = noDidPrefixed('Test 2')
|
|
|
|
const result3 = noDidPrefixed('Test 3')
|
|
|
|
assert.equal(result1, 'Test 1')
|
|
|
|
assert.equal(result2, 'Test 2')
|
|
|
|
assert.equal(result3, 'Test 3')
|
2019-03-11 22:46:27 +01:00
|
|
|
})
|
|
|
|
|
2019-06-20 00:20:09 +02:00
|
|
|
it('should return the value with did:op: prefix', async () => {
|
2019-03-11 22:46:27 +01:00
|
|
|
const result1 = didPrefixed(`0x${did}`)
|
|
|
|
const result2 = didPrefixed(did)
|
|
|
|
const result3 = didPrefixed(`did:op:${did}`)
|
|
|
|
assert.equal(result1, `did:op:${did}`)
|
|
|
|
assert.equal(result2, `did:op:${did}`)
|
|
|
|
assert.equal(result3, `did:op:${did}`)
|
|
|
|
})
|
|
|
|
|
2019-06-20 00:20:09 +02:00
|
|
|
it('should return the value without did:op: prefix', async () => {
|
2019-03-11 22:46:27 +01:00
|
|
|
const result1 = noDidPrefixed(`0x${did}`)
|
|
|
|
const result2 = noDidPrefixed(did)
|
|
|
|
const result3 = noDidPrefixed(`did:op:${did}`)
|
|
|
|
assert.equal(result1, did)
|
|
|
|
assert.equal(result2, did)
|
|
|
|
assert.equal(result3, did)
|
|
|
|
})
|
|
|
|
})
|
2019-03-04 13:30:34 +01:00
|
|
|
})
|