forked from ipfs-shipyard/is-ipfs
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Closes ipfs-shipyard#12
- Loading branch information
Showing
3 changed files
with
71 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/* eslint-env mocha */ | ||
'use strict' | ||
|
||
const base58 = require('bs58') | ||
const expect = require('chai').expect | ||
const isIPFS = require('../src/index') | ||
|
||
describe('ipfs cid', () => { | ||
it('isIPFS.cid should match a valid CIDv0 (multihash)', (done) => { | ||
const actual = isIPFS.cid('QmYjtig7VJQ6XsnUjqqJvj7QaMcCAwtrgNdahSiFofrE7o') | ||
expect(actual).to.equal(true) | ||
done() | ||
}) | ||
|
||
it('isIPFS.cid should match a valid CIDv0 (multihash) buffer', (done) => { | ||
const actual = isIPFS.cid(new Buffer(base58.decode('QmYjtig7VJQ6XsnUjqqJvj7QaMcCAwtrgNdahSiFofrE7o'))) | ||
expect(actual).to.equal(true) | ||
done() | ||
}) | ||
|
||
it('isIPFS.cid should not match a broken CIDv0 buffer', (done) => { | ||
const actual = isIPFS.cid(new Buffer('QmYjtig7VJQ6XsnUjqqJvj7QaMcCAwtrgNdahSiFofrE70')) | ||
expect(actual).to.equal(false) | ||
done() | ||
}) | ||
|
||
it('isIPFS.cid should not match an invalid CIDv0 (multihash with a typo)', (done) => { | ||
const actual = isIPFS.cid('QmYjtig7VJQ6XsnUjqqJvj7QaMcCAwtrgNdahSiFofrE70') | ||
expect(actual).to.equal(false) | ||
done() | ||
}) | ||
|
||
it('isIPFS.cid should match a valid CIDv1', (done) => { | ||
const actual = isIPFS.cid('zdj7WWeQ43G6JJvLWQWZpyHuAMq6uYWRjkBXFad11vE2LHhQ7') | ||
expect(actual).to.equal(true) | ||
done() | ||
}) | ||
|
||
it('isIPFS.cid should not match an invalid CIDv1 (with a typo)', (done) => { | ||
const actual = isIPFS.cid('zdj7WWeQ43G6JJvLWQWZpyHuAMq6uYWRjkBXFad11vE2LHhQ') | ||
expect(actual).to.equal(false) | ||
done() | ||
}) | ||
|
||
it('isIPFS.cid should not match an invalid CID', (done) => { | ||
const actual = isIPFS.cid('noop') | ||
expect(actual).to.equal(false) | ||
done() | ||
}) | ||
|
||
it('isIPFS.cid should not match an invalid CID data type', (done) => { | ||
const actual = isIPFS.cid(4) | ||
expect(actual).to.equal(false) | ||
done() | ||
}) | ||
}) |