This repository was archived by the owner on Mar 10, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 297
/
Copy pathbootstrap.spec.js
181 lines (160 loc) · 5.33 KB
/
bootstrap.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
/* eslint-env mocha */
/* eslint max-nested-callbacks: ["error", 8] */
/* globals apiClients */
'use strict'
const expect = require('chai').expect
const invalidArg = 'this/Is/So/Invalid/'
const validIp4 = '/ip4/104.236.176.52/tcp/4001/ipfs/QmSoLnSGccFuZQJzRadHn95W2CrSFmZuTdDWP8HXaHca9z'
describe('.bootstrap', () => {
let peers
describe('.add', () => {
it('returns an error when called without args or options', (done) => {
return apiClients.a.bootstrap.add(null, (err) => {
expect(err).to.be.an.instanceof(Error)
done()
})
})
it('returns an error when called with an invalid arg', (done) => {
return apiClients.a.bootstrap.add(invalidArg, (err) => {
expect(err).to.be.an.instanceof(Error)
done()
})
})
it('returns a list of containing the bootstrap peer when called with a valid arg (ip4)', (done) => {
return apiClients.a.bootstrap.add(validIp4, (err, res) => {
expect(err).to.not.exist
expect(res).to.be.eql({ Peers: [validIp4] })
peers = res.Peers
expect(peers).to.exist
expect(peers.length).to.eql(1)
done()
})
})
it('returns a list of bootstrap peers when called with the default option', (done) => {
return apiClients.a.bootstrap.add(null, { default: true }, (err, res) => {
expect(err).to.not.exist
peers = res.Peers
expect(peers).to.exist
expect(peers.length).to.above(1)
done()
})
})
})
describe('.list', () => {
it('returns a list of peers', (done) => {
return apiClients.a.bootstrap.list((err, res) => {
expect(err).to.not.exist
peers = res.Peers
expect(peers).to.exist
done()
})
})
})
describe('.rm', () => {
it('returns an error when called with an invalid arg', (done) => {
return apiClients.a.bootstrap.rm(invalidArg, (err) => {
expect(err).to.be.an.instanceof(Error)
done()
})
})
it('returns empty list because no peers removed when called without an arg or options', (done) => {
return apiClients.a.bootstrap.rm(null, (err, res) => {
expect(err).to.not.exist
peers = res.Peers
expect(peers).to.exist
expect(peers.length).to.eql(0)
done()
})
})
it('returns list containing the peer removed when called with a valid arg (ip4)', (done) => {
return apiClients.a.bootstrap.rm(null, (err, res) => {
expect(err).to.not.exist
peers = res.Peers
expect(peers).to.exist
expect(peers.length).to.eql(0)
done()
})
})
it('returns list of all peers removed when all option is passed', (done) => {
return apiClients.a.bootstrap.rm(null, { all: true }, (err, res) => {
expect(err).to.not.exist
peers = res.Peers
expect(peers).to.exist
done()
})
})
})
describe('.promise', () => {
describe('.add', () => {
it('returns an error when called without args or options', () => {
return apiClients.a.bootstrap.add(null)
.catch((err) => {
expect(err).to.be.an.instanceof(Error)
})
})
it('returns an error when called with an invalid arg', () => {
return apiClients.a.bootstrap.add(invalidArg)
.catch((err) => {
expect(err).to.be.an.instanceof(Error)
})
})
it('returns a list of peers when called with a valid arg (ip4)', () => {
return apiClients.a.bootstrap.add(validIp4)
.then((res) => {
expect(res).to.be.eql({ Peers: [validIp4] })
peers = res.Peers
expect(peers).to.exist
expect(peers.length).to.eql(1)
})
})
it('returns a list of default peers when called with the default option', () => {
return apiClients.a.bootstrap.add(null, { default: true })
.then((res) => {
peers = res.Peers
expect(peers).to.exist
expect(peers.length).to.above(1)
})
})
})
describe('.list', () => {
it('returns a list of peers', () => {
return apiClients.a.bootstrap.list()
.then((res) => {
peers = res.Peers
expect(peers).to.exist
})
})
})
describe('.rm', () => {
it('returns an error when called with an invalid arg', () => {
return apiClients.a.bootstrap.rm(invalidArg)
.catch((err) => {
expect(err).to.be.an.instanceof(Error)
})
})
it('returns empty list when called without an arg or options', () => {
return apiClients.a.bootstrap.rm(null)
.then((res) => {
peers = res.Peers
expect(peers).to.exist
expect(peers.length).to.eql(0)
})
})
it('returns list containing the peer removed when called with a valid arg (ip4)', () => {
return apiClients.a.bootstrap.rm(null)
.then((res) => {
peers = res.Peers
expect(peers).to.exist
expect(peers.length).to.eql(0)
})
})
it('returns list of all peers removed when all option is passed', () => {
return apiClients.a.bootstrap.rm(null, { all: true })
.then((res) => {
peers = res.Peers
expect(peers).to.exist
})
})
})
})
})