|
| 1 | +/* eslint-env mocha */ |
| 2 | +'use strict' |
| 3 | + |
| 4 | +const base58 = require('bs58') |
| 5 | +const expect = require('chai').expect |
| 6 | +const isIPFS = require('../src/index') |
| 7 | + |
| 8 | +describe('ipfs cid', () => { |
| 9 | + it('isIPFS.cid should match a valid CIDv0 (multihash)', (done) => { |
| 10 | + const actual = isIPFS.cid('QmYjtig7VJQ6XsnUjqqJvj7QaMcCAwtrgNdahSiFofrE7o') |
| 11 | + expect(actual).to.equal(true) |
| 12 | + done() |
| 13 | + }) |
| 14 | + |
| 15 | + it('isIPFS.cid should match a valid CIDv0 (multihash) buffer', (done) => { |
| 16 | + const actual = isIPFS.cid(new Buffer(base58.decode('QmYjtig7VJQ6XsnUjqqJvj7QaMcCAwtrgNdahSiFofrE7o'))) |
| 17 | + expect(actual).to.equal(true) |
| 18 | + done() |
| 19 | + }) |
| 20 | + |
| 21 | + it('isIPFS.cid should not match a broken CIDv0 buffer', (done) => { |
| 22 | + const actual = isIPFS.cid(new Buffer('QmYjtig7VJQ6XsnUjqqJvj7QaMcCAwtrgNdahSiFofrE70')) |
| 23 | + expect(actual).to.equal(false) |
| 24 | + done() |
| 25 | + }) |
| 26 | + |
| 27 | + it('isIPFS.cid should not match an invalid CIDv0 (multihash with a typo)', (done) => { |
| 28 | + const actual = isIPFS.cid('QmYjtig7VJQ6XsnUjqqJvj7QaMcCAwtrgNdahSiFofrE70') |
| 29 | + expect(actual).to.equal(false) |
| 30 | + done() |
| 31 | + }) |
| 32 | + |
| 33 | + it('isIPFS.cid should match a valid CIDv1', (done) => { |
| 34 | + const actual = isIPFS.cid('zdj7WWeQ43G6JJvLWQWZpyHuAMq6uYWRjkBXFad11vE2LHhQ7') |
| 35 | + expect(actual).to.equal(true) |
| 36 | + done() |
| 37 | + }) |
| 38 | + |
| 39 | + it('isIPFS.cid should not match an invalid CIDv1 (with a typo)', (done) => { |
| 40 | + const actual = isIPFS.cid('zdj7WWeQ43G6JJvLWQWZpyHuAMq6uYWRjkBXFad11vE2LHhQ') |
| 41 | + expect(actual).to.equal(false) |
| 42 | + done() |
| 43 | + }) |
| 44 | + |
| 45 | + it('isIPFS.cid should not match an invalid CID', (done) => { |
| 46 | + const actual = isIPFS.cid('noop') |
| 47 | + expect(actual).to.equal(false) |
| 48 | + done() |
| 49 | + }) |
| 50 | + |
| 51 | + it('isIPFS.cid should not match an invalid CID data type', (done) => { |
| 52 | + const actual = isIPFS.cid(4) |
| 53 | + expect(actual).to.equal(false) |
| 54 | + done() |
| 55 | + }) |
| 56 | +}) |
0 commit comments