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 pathconfig.spec.js
135 lines (116 loc) · 3.42 KB
/
config.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
/* eslint-env mocha */
/* eslint max-nested-callbacks: ["error", 8] */
/* globals apiClients */
'use strict'
const expect = require('chai').expect
const isNode = require('detect-node')
const path = require('path')
describe('.config', () => {
describe('.config.{set, get}', () => {
it('string', (done) => {
const confKey = 'arbitraryKey'
const confVal = 'arbitraryVal'
apiClients.a.config.set(confKey, confVal, (err, res) => {
expect(err).to.not.exist
apiClients.a.config.get(confKey, (err, res) => {
expect(err).to.not.exist
expect(res).to.have.a.property('Value', confVal)
done()
})
})
})
it('bool', (done) => {
const confKey = 'otherKey'
const confVal = true
apiClients.a.config.set(confKey, confVal, (err, res) => {
expect(err).to.not.exist
apiClients.a.config.get(confKey, (err, res) => {
expect(err).to.not.exist
expect(res.Value).to.deep.equal(confVal)
done()
})
})
})
it('json', (done) => {
const confKey = 'API.HTTPHeaders.Access-Control-Allow-Origin'
const confVal = ['http://example.io']
apiClients.a.config.set(confKey, confVal, (err, res) => {
expect(err).to.not.exist
apiClients.a.config.get(confKey, (err, res) => {
expect(err).to.not.exist
expect(res.Value).to.deep.equal(confVal)
done()
})
})
})
})
it('.config.show', (done) => {
apiClients.c.config.show((err, res) => {
expect(err).to.not.exist
expect(res).to.exist
done()
})
})
it('.config.replace', (done) => {
if (!isNode) {
return done()
}
apiClients.c.config.replace(path.join(__dirname, '/../data/r-config.json'), (err, res) => {
expect(err).to.not.exist
expect(res).to.be.equal(null)
done()
})
})
describe('promise', () => {
describe('.config.{set, get}', () => {
it('string', () => {
const confKey = 'arbitraryKey'
const confVal = 'arbitraryVal'
return apiClients.a.config.set(confKey, confVal)
.then((res) => {
return apiClients.a.config.get(confKey)
})
.then((res) => {
expect(res).to.have.a.property('Value', confVal)
})
})
it('bool', () => {
const confKey = 'otherKey'
const confVal = true
return apiClients.a.config.set(confKey, confVal)
.then((res) => {
return apiClients.a.config.get(confKey)
})
.then((res) => {
expect(res.Value).to.deep.equal(confVal)
})
})
it('json', () => {
const confKey = 'API.HTTPHeaders.Access-Control-Allow-Origin'
const confVal = ['http://example.com']
return apiClients.a.config.set(confKey, confVal)
.then((res) => {
return apiClients.a.config.get(confKey)
})
.then((res) => {
expect(res.Value).to.deep.equal(confVal)
})
})
})
it('.config.show', () => {
return apiClients.c.config.show()
.then((res) => {
expect(res).to.exist
})
})
it('.config.replace', () => {
if (!isNode) {
return
}
return apiClients.c.config.replace(path.join(__dirname, '/../data/r-config.json'))
.then((res) => {
expect(res).to.be.equal(null)
})
})
})
})