|
3 | 3 | 'use strict'
|
4 | 4 |
|
5 | 5 | const expect = require('chai').expect
|
6 |
| -// const multiaddr = require('multiaddr') |
7 | 6 |
|
8 |
| -describe('.bootstrap', () => { |
9 |
| - const emptyArg = '' |
10 |
| - const invalidArg = 'QmaCpDMGvV2BGHeYERUEnRQAwe3N8SzbUtfsmvsqQLuvuJ' |
11 |
| - const validIp4 = '/ip4/104.236.176.52/tcp/4001/ipfs/QmSoLnSGccFuZQJzRadHn95W2CrSFmZuTdDWP8HXaHca9z' |
| 7 | +const invalidArg = 'this/Is/So/Invalid/' |
| 8 | +const validIp4 = '/ip4/104.236.176.52/tcp/4001/ipfs/QmSoLnSGccFuZQJzRadHn95W2CrSFmZuTdDWP8HXaHca9z' |
12 | 9 |
|
| 10 | +describe('.bootstrap', () => { |
13 | 11 | let peers
|
14 | 12 |
|
15 |
| - it('add returns an error when not passing an arg', (done) => { |
16 |
| - return apiClients.a.bootstrap.add(null, (err) => { |
17 |
| - expect(err).to.be.an.instanceof(Error) |
18 |
| - done() |
| 13 | + describe('.add', () => { |
| 14 | + it('returns an error when called without args or options', (done) => { |
| 15 | + return apiClients.a.bootstrap.add(null, (err) => { |
| 16 | + expect(err).to.be.an.instanceof(Error) |
| 17 | + done() |
| 18 | + }) |
| 19 | + }) |
| 20 | + |
| 21 | + it('returns an error when called with an invalid arg', (done) => { |
| 22 | + return apiClients.a.bootstrap.add(invalidArg, (err) => { |
| 23 | + expect(err).to.be.an.instanceof(Error) |
| 24 | + done() |
| 25 | + }) |
| 26 | + }) |
| 27 | + |
| 28 | + it('returns a list of peers when called with a valid arg (ip4)', (done) => { |
| 29 | + return apiClients.a.bootstrap.add(validIp4, (err, res) => { |
| 30 | + expect(err).to.not.exist |
| 31 | + expect(res).to.be.eql({ Peers: [validIp4] }) |
| 32 | + peers = res.Peers |
| 33 | + expect(peers).to.exist |
| 34 | + expect(peers.length).to.eql(1) |
| 35 | + done() |
| 36 | + }) |
19 | 37 | })
|
20 |
| - }) |
21 | 38 |
|
22 |
| - it('add returns an error when passing an invalid arg', (done) => { |
23 |
| - return apiClients.a.bootstrap.add(invalidArg, (err) => { |
24 |
| - expect(err).to.be.an.instanceof(Error) |
25 |
| - done() |
| 39 | + it('returns a list of default peers when called with the default option', (done) => { |
| 40 | + return apiClients.a.bootstrap.add(null, { default: true }, (err, res) => { |
| 41 | + expect(err).to.not.exist |
| 42 | + peers = res.Peers |
| 43 | + expect(peers).to.exist |
| 44 | + expect(peers.length).to.above(1) |
| 45 | + done() |
| 46 | + }) |
26 | 47 | })
|
27 | 48 | })
|
28 | 49 |
|
29 |
| - it('add returns an error when passing an empty arg', (done) => { |
30 |
| - return apiClients.a.bootstrap.add(emptyArg, (err) => { |
31 |
| - expect(err).to.be.an.instanceof(Error) |
32 |
| - done() |
| 50 | + describe('.list', () => { |
| 51 | + it('returns a list of peers', (done) => { |
| 52 | + return apiClients.a.bootstrap.list(null, (err, res) => { |
| 53 | + expect(err).to.not.exist |
| 54 | + peers = res.Peers |
| 55 | + expect(peers).to.exist |
| 56 | + done() |
| 57 | + }) |
33 | 58 | })
|
34 | 59 | })
|
35 | 60 |
|
36 |
| - it('adds a valid address (ip4)', (done) => { |
37 |
| - return apiClients.a.bootstrap.add(validIp4, (err, res) => { |
38 |
| - expect(err).to.not.exist |
39 |
| - expect(res).to.be.eql({ Peers: [validIp4] }) |
40 |
| - peers = res.Peers |
41 |
| - expect(peers).to.exist |
42 |
| - expect(peers.length).to.eql(1) |
43 |
| - done() |
| 61 | + describe('.rm', () => { |
| 62 | + it('returns an error when called with an invalid arg', (done) => { |
| 63 | + return apiClients.a.bootstrap.rm(invalidArg, (err) => { |
| 64 | + expect(err).to.be.an.instanceof(Error) |
| 65 | + done() |
| 66 | + }) |
| 67 | + }) |
| 68 | + |
| 69 | + it('returns empty list when called without an arg or options', (done) => { |
| 70 | + return apiClients.a.bootstrap.rm(null, (err, res) => { |
| 71 | + expect(err).to.not.exist |
| 72 | + peers = res.Peers |
| 73 | + expect(peers).to.exist |
| 74 | + expect(peers.length).to.eql(0) |
| 75 | + done() |
| 76 | + }) |
| 77 | + }) |
| 78 | + |
| 79 | + it('returns list containing the peer removed when called with a valid arg (ip4)', (done) => { |
| 80 | + return apiClients.a.bootstrap.rm(null, (err, res) => { |
| 81 | + expect(err).to.not.exist |
| 82 | + peers = res.Peers |
| 83 | + expect(peers).to.exist |
| 84 | + expect(peers.length).to.eql(0) |
| 85 | + done() |
| 86 | + }) |
| 87 | + }) |
| 88 | + |
| 89 | + it('returns list of all peers removed when all option is passed', (done) => { |
| 90 | + return apiClients.a.bootstrap.rm(null, { all: true }, (err, res) => { |
| 91 | + expect(err).to.not.exist |
| 92 | + peers = res.Peers |
| 93 | + expect(peers).to.exist |
| 94 | + done() |
| 95 | + }) |
44 | 96 | })
|
45 | 97 | })
|
46 | 98 |
|
47 |
| - it('add returns a list of default peers when default arg passed', (done) => { |
48 |
| - return apiClients.a.bootstrap.add(null, { default: true }, (err, res) => { |
49 |
| - expect(err).to.not.exist |
50 |
| - peers = res.Peers |
51 |
| - expect(peers).to.exist |
52 |
| - done() |
| 99 | + describe('.promise', () => { |
| 100 | + describe('.add', () => { |
| 101 | + it('returns an error when called without args or options', (done) => { |
| 102 | + return apiClients.a.bootstrap.add(null) |
| 103 | + .catch((err) => { |
| 104 | + expect(err).to.be.an.instanceof(Error) |
| 105 | + done() |
| 106 | + }) |
| 107 | + }) |
| 108 | + |
| 109 | + it('returns an error when called with an invalid arg', (done) => { |
| 110 | + return apiClients.a.bootstrap.add(invalidArg) |
| 111 | + .catch((err) => { |
| 112 | + expect(err).to.be.an.instanceof(Error) |
| 113 | + done() |
| 114 | + }) |
| 115 | + }) |
| 116 | + |
| 117 | + it('returns a list of peers when called with a valid arg (ip4)', (done) => { |
| 118 | + return apiClients.a.bootstrap.add(validIp4) |
| 119 | + .then((res) => { |
| 120 | + expect(res).to.be.eql({ Peers: [validIp4] }) |
| 121 | + peers = res.Peers |
| 122 | + expect(peers).to.exist |
| 123 | + expect(peers.length).to.eql(1) |
| 124 | + done() |
| 125 | + }) |
| 126 | + }) |
| 127 | + |
| 128 | + it('returns a list of default peers when called with the default option', (done) => { |
| 129 | + return apiClients.a.bootstrap.add(null, { default: true }) |
| 130 | + .then((res) => { |
| 131 | + peers = res.Peers |
| 132 | + expect(peers).to.exist |
| 133 | + expect(peers.length).to.above(1) |
| 134 | + done() |
| 135 | + }) |
| 136 | + }) |
| 137 | + }) |
| 138 | + |
| 139 | + describe('.list', () => { |
| 140 | + it('returns a list of peers', (done) => { |
| 141 | + return apiClients.a.bootstrap.list(null) |
| 142 | + .then((res) => { |
| 143 | + peers = res.Peers |
| 144 | + expect(peers).to.exist |
| 145 | + done() |
| 146 | + }) |
| 147 | + }) |
| 148 | + }) |
| 149 | + |
| 150 | + describe('.rm', () => { |
| 151 | + it('returns an error when called with an invalid arg', (done) => { |
| 152 | + return apiClients.a.bootstrap.rm(invalidArg) |
| 153 | + .catch((err) => { |
| 154 | + expect(err).to.be.an.instanceof(Error) |
| 155 | + done() |
| 156 | + }) |
| 157 | + }) |
| 158 | + |
| 159 | + it('returns empty list when called without an arg or options', (done) => { |
| 160 | + return apiClients.a.bootstrap.rm(null) |
| 161 | + .then((res) => { |
| 162 | + peers = res.Peers |
| 163 | + expect(peers).to.exist |
| 164 | + expect(peers.length).to.eql(0) |
| 165 | + done() |
| 166 | + }) |
| 167 | + }) |
| 168 | + |
| 169 | + it('returns list containing the peer removed when called with a valid arg (ip4)', (done) => { |
| 170 | + return apiClients.a.bootstrap.rm(null) |
| 171 | + .then((res) => { |
| 172 | + peers = res.Peers |
| 173 | + expect(peers).to.exist |
| 174 | + expect(peers.length).to.eql(0) |
| 175 | + done() |
| 176 | + }) |
| 177 | + }) |
| 178 | + |
| 179 | + it('returns list of all peers removed when all option is passed', (done) => { |
| 180 | + return apiClients.a.bootstrap.rm(null, { all: true }) |
| 181 | + .then((res) => { |
| 182 | + peers = res.Peers |
| 183 | + expect(peers).to.exist |
| 184 | + done() |
| 185 | + }) |
| 186 | + }) |
53 | 187 | })
|
54 | 188 | })
|
55 | 189 | })
|
0 commit comments