forked from ipfs-inactive/js-ipfs-http-client
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ls.spec.js
68 lines (56 loc) · 1.95 KB
/
ls.spec.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
/* eslint-env mocha */
/* globals apiClients */
'use strict'
const expect = require('chai').expect
const isNode = require('detect-node')
describe('ls', function () {
it('should correctly retrieve links', function (done) {
if (!isNode) return done()
apiClients.a.ls('QmYwAPJzv5CZsnA625s3Xf2nemtYgPpHdWEz79ojWnPbdG', (err, res) => {
expect(err).to.not.exist
expect(res).to.have.a.property('Objects')
expect(res.Objects[0]).to.have.a.property('Links')
expect(res.Objects[0]).to.have.property('Hash', 'QmYwAPJzv5CZsnA625s3Xf2nemtYgPpHdWEz79ojWnPbdG')
done()
})
})
it('should correctly handle a nonexisting hash', function (done) {
apiClients.a.ls('surelynotavalidhashheh?', (err, res) => {
expect(err).to.exist
expect(res).to.not.exist
done()
})
})
it('should correctly handle a nonexisting path', function (done) {
if (!isNode) return done()
apiClients.a.ls('QmRNjDeKStKGTQXnJ2NFqeQ9oW/folder_that_isnt_there', (err, res) => {
expect(err).to.exist
expect(res).to.not.exist
done()
})
})
describe('promise', () => {
it('should correctly retrieve links', () => {
if (!isNode) return
return apiClients.a.ls('QmYwAPJzv5CZsnA625s3Xf2nemtYgPpHdWEz79ojWnPbdG')
.then((res) => {
expect(res).to.have.a.property('Objects')
expect(res.Objects[0]).to.have.a.property('Links')
expect(res.Objects[0]).to.have.property('Hash', 'QmYwAPJzv5CZsnA625s3Xf2nemtYgPpHdWEz79ojWnPbdG')
})
})
it('should correctly handle a nonexisting hash', () => {
return apiClients.a.ls('surelynotavalidhashheh?')
.catch((err) => {
expect(err).to.exist
})
})
it('should correctly handle a nonexisting path', () => {
if (!isNode) return
return apiClients.a.ls('QmRNjDeKStKGTQXnJ3NFqeQ9oW/folder_that_isnt_there')
.catch((err) => {
expect(err).to.exist
})
})
})
})