|
2 | 2 | /* globals apiClients */
|
3 | 3 | 'use strict'
|
4 | 4 |
|
5 |
| -const expect = require('chai').expect |
6 |
| -const isNode = require('detect-node') |
7 |
| -const path = require('path') |
8 |
| - |
9 |
| -describe('.config', () => { |
10 |
| - describe('.config.{set, get}', () => { |
11 |
| - it('string', (done) => { |
12 |
| - const confKey = 'arbitraryKey' |
13 |
| - const confVal = 'arbitraryVal' |
14 |
| - |
15 |
| - apiClients.a.config.set(confKey, confVal, (err, res) => { |
16 |
| - expect(err).to.not.exist |
17 |
| - apiClients.a.config.get(confKey, (err, res) => { |
18 |
| - expect(err).to.not.exist |
19 |
| - expect(res).to.have.a.property('Value', confVal) |
20 |
| - done() |
21 |
| - }) |
22 |
| - }) |
23 |
| - }) |
24 |
| - |
25 |
| - it('bool', (done) => { |
26 |
| - const confKey = 'otherKey' |
27 |
| - const confVal = true |
28 |
| - |
29 |
| - apiClients.a.config.set(confKey, confVal, (err, res) => { |
30 |
| - expect(err).to.not.exist |
31 |
| - apiClients.a.config.get(confKey, (err, res) => { |
32 |
| - expect(err).to.not.exist |
33 |
| - expect(res.Value).to.deep.equal(confVal) |
34 |
| - done() |
35 |
| - }) |
36 |
| - }) |
37 |
| - }) |
38 |
| - |
39 |
| - it('json', (done) => { |
40 |
| - const confKey = 'API.HTTPHeaders.Access-Control-Allow-Origin' |
41 |
| - const confVal = ['http://example.io'] |
42 |
| - |
43 |
| - apiClients.a.config.set(confKey, confVal, (err, res) => { |
44 |
| - expect(err).to.not.exist |
45 |
| - apiClients.a.config.get(confKey, (err, res) => { |
46 |
| - expect(err).to.not.exist |
47 |
| - expect(res.Value).to.deep.equal(confVal) |
48 |
| - done() |
49 |
| - }) |
50 |
| - }) |
51 |
| - }) |
52 |
| - }) |
53 |
| - |
54 |
| - it('.config.show', (done) => { |
55 |
| - apiClients.c.config.show((err, res) => { |
56 |
| - expect(err).to.not.exist |
57 |
| - expect(res).to.exist |
58 |
| - done() |
59 |
| - }) |
60 |
| - }) |
61 |
| - |
62 |
| - it('.config.replace', (done) => { |
63 |
| - if (!isNode) { |
64 |
| - return done() |
65 |
| - } |
66 |
| - |
67 |
| - apiClients.c.config.replace(path.join(__dirname, '/../r-config.json'), (err, res) => { |
68 |
| - expect(err).to.not.exist |
69 |
| - expect(res).to.be.equal(null) |
70 |
| - done() |
71 |
| - }) |
72 |
| - }) |
73 |
| - |
74 |
| - describe('promise', () => { |
75 |
| - describe('.config.{set, get}', () => { |
76 |
| - it('string', () => { |
77 |
| - const confKey = 'arbitraryKey' |
78 |
| - const confVal = 'arbitraryVal' |
79 |
| - |
80 |
| - return apiClients.a.config.set(confKey, confVal) |
81 |
| - .then((res) => { |
82 |
| - return apiClients.a.config.get(confKey) |
83 |
| - }) |
84 |
| - .then((res) => { |
85 |
| - expect(res).to.have.a.property('Value', confVal) |
86 |
| - }) |
87 |
| - }) |
88 |
| - |
89 |
| - it('bool', () => { |
90 |
| - const confKey = 'otherKey' |
91 |
| - const confVal = true |
92 |
| - |
93 |
| - return apiClients.a.config.set(confKey, confVal) |
94 |
| - .then((res) => { |
95 |
| - return apiClients.a.config.get(confKey) |
96 |
| - }) |
97 |
| - .then((res) => { |
98 |
| - expect(res.Value).to.deep.equal(confVal) |
99 |
| - }) |
100 |
| - }) |
101 |
| - |
102 |
| - it('json', () => { |
103 |
| - const confKey = 'API.HTTPHeaders.Access-Control-Allow-Origin' |
104 |
| - const confVal = ['http://example.com'] |
105 |
| - |
106 |
| - return apiClients.a.config.set(confKey, confVal) |
107 |
| - .then((res) => { |
108 |
| - return apiClients.a.config.get(confKey) |
109 |
| - }) |
110 |
| - .then((res) => { |
111 |
| - expect(res.Value).to.deep.equal(confVal) |
112 |
| - }) |
113 |
| - }) |
114 |
| - }) |
115 |
| - |
116 |
| - it('.config.show', () => { |
117 |
| - return apiClients.c.config.show() |
118 |
| - .then((res) => { |
119 |
| - expect(res).to.exist |
120 |
| - }) |
121 |
| - }) |
122 |
| - |
123 |
| - it('.config.replace', () => { |
124 |
| - if (!isNode) { |
125 |
| - return |
126 |
| - } |
127 |
| - |
128 |
| - return apiClients.c.config.replace(path.join(__dirname, '/../r-config.json')) |
129 |
| - .then((res) => { |
130 |
| - expect(res).to.be.equal(null) |
131 |
| - }) |
132 |
| - }) |
133 |
| - }) |
134 |
| -}) |
| 5 | +const test = require('interface-ipfs-core') |
| 6 | + |
| 7 | +const common = { |
| 8 | + setup: function (cb) { |
| 9 | + cb(null, apiClients.a) |
| 10 | + }, |
| 11 | + teardown: function (cb) { |
| 12 | + cb() |
| 13 | + } |
| 14 | +} |
| 15 | + |
| 16 | +test.config(common) |
0 commit comments