forked from robburger/citizen
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlist.spec.js
256 lines (232 loc) · 9.29 KB
/
list.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
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
const request = require('supertest');
const { expect } = require('chai');
const app = require('../app');
const { db, save } = require('../lib/store');
const { deleteDbAll } = require('../test/helper');
describe('GET /v1/modules', () => {
before(async () => {
await save({
namespace: 'GCP', name: 'lb-http', provider: 'google', version: '1.0.4', owner: '',
});
await save({
namespace: 'aws-modules', name: 'vpc', provider: 'aws', version: '1.2.1', owner: '',
});
await save({
namespace: 'aws-modules', name: 'vpc', provider: 'aws', version: '1.5.0', owner: '',
});
await save({
namespace: 'aws-modules', name: 'vpc', provider: 'aws', version: '1.5.1', owner: '',
});
});
after(async () => {
await deleteDbAll(db);
});
it('should return all modules', () => request(app)
.get('/v1/modules')
.expect('Content-Type', /application\/json/)
.expect(200)
.then((res) => {
expect(res.body).to.have.property('meta')
.to.have.property('current_offset').to.equal(0);
expect(res.body).to.have.property('modules').to.have.lengthOf(4);
}));
it('should support pagination', () => request(app)
.get('/v1/modules?offset=0&limit=2')
.expect('Content-Type', /application\/json/)
.expect(200)
.then((res) => {
expect(res.body).to.have.property('modules').to.have.lengthOf(2);
}));
it('should return meta of pagination', () => request(app)
.get('/v1/modules?offset=1&limit=2')
.expect('Content-Type', /application\/json/)
.expect(200)
.then((res) => {
expect(res.body).to.have.property('meta');
expect(res.body.meta).to.have.property('limit').to.equal(2);
expect(res.body.meta).to.have.property('current_offset').to.equal(1);
expect(res.body.meta).to.have.property('next_offset').to.equal(3);
expect(res.body.meta).to.have.property('next_url').to.equal('/v1/modules/?limit=2&offset=3');
}));
it('should not be next_offset when there is no more modules', () => request(app)
.get('/v1/modules?offset=2&limit=2')
.expect('Content-Type', /application\/json/)
.expect(200)
.then((res) => {
expect(res.body).to.have.property('meta');
expect(res.body.meta).to.have.property('limit');
expect(res.body.meta).to.have.property('current_offset');
expect(res.body.meta).to.not.have.property('next_offset');
expect(res.body.meta).to.not.have.property('next_url');
}));
});
describe('GET /v1/modules/:namespace', () => {
before(async () => {
await save({
namespace: 'GCP', name: 'lb-http', provider: 'google', version: '1.0.4', owner: '',
});
await save({
namespace: 'aws-modules', name: 'vpc', provider: 'microsoft', version: '1.2.1', owner: '',
});
await save({
namespace: 'aws-modules', name: 'vpc', provider: 'microsoft', version: '1.5.0', owner: '',
});
await save({
namespace: 'aws-modules', name: 'vpc', provider: 'aws', version: '1.5.1', owner: '',
});
});
after(async () => {
await deleteDbAll(db);
});
it('should return all modules of namespace', () => request(app)
.get('/v1/modules/aws-modules')
.expect('Content-Type', /application\/json/)
.expect(200)
.then((res) => {
expect(res.body).to.have.property('meta')
.to.have.property('current_offset').to.equal(0);
expect(res.body).to.have.property('modules').to.have.lengthOf(3);
}));
it('should filter modules by provider', () => request(app)
.get('/v1/modules/aws-modules?provider=microsoft')
.expect('Content-Type', /application\/json/)
.expect(200)
.then((res) => {
expect(res.body).to.have.property('meta')
.to.have.property('current_offset').to.equal(0);
expect(res.body).to.have.property('modules').to.have.lengthOf(2);
}));
});
describe('GET /v1/modules/search', () => {
before(async () => {
await save({
namespace: 'GCP', name: 'lb-http', provider: 'google', version: '1.0.4', owner: '',
});
await save({
namespace: 'aws-modules', name: 'vpc', provider: 'microsoft', version: '1.2.1', owner: '',
});
await save({
namespace: 'aws-modules', name: 'vpc', provider: 'microsoft', version: '1.5.0', owner: '',
});
await save({
namespace: 'aws-modules', name: 'vpc', provider: 'aws', version: '1.5.1', owner: '',
});
});
after(async () => {
await deleteDbAll(db);
});
it('should return all modules which matched by q', () => request(app)
.get('/v1/modules/search?q=vpc')
.expect('Content-Type', /application\/json/)
.expect(200)
.then((res) => {
expect(res.body).to.have.property('meta')
.to.have.property('current_offset').to.equal(0);
expect(res.body).to.have.property('modules').to.have.lengthOf(3);
}));
it('should return all modules which contain q', () => request(app)
.get('/v1/modules/search?q=pc')
.expect('Content-Type', /application\/json/)
.expect(200)
.then((res) => {
expect(res.body).to.have.property('meta')
.to.have.property('current_offset').to.equal(0);
expect(res.body).to.have.property('modules').to.have.lengthOf(3);
}));
it('should reject the request which does not have q parameter', () => request(app)
.get('/v1/modules/search')
.expect('Content-Type', /application\/json/)
.expect(400)
.then((res) => {
expect(res.body).to.have.property('errors');
}));
});
describe('GET /v1/modules/:namespace/:name/:provider/versions', () => {
before(async () => {
await save({
namespace: 'GCP', name: 'lb-http', provider: 'google', version: '1.0.4', owner: '', definition: { root: { name: 'lb-http' }, submodules: [{ name: 'example' }] },
});
await save({
namespace: 'aws-modules', name: 'vpc', provider: 'aws', version: '1.2.1', owner: '', definition: { root: { name: 'vpc' }, submodules: [{ name: 'example' }] },
});
await save({
namespace: 'aws-modules', name: 'vpc', provider: 'aws', version: '1.5.0', owner: '', definition: { root: { name: 'vpc' }, submodules: [{ name: 'example' }] },
});
await save({
namespace: 'aws-modules', name: 'vpc', provider: 'aws', version: '1.5.1', owner: '', definition: { root: { name: 'vpc' }, submodules: [{ name: 'example' }] },
});
});
after(async () => {
await deleteDbAll(db);
});
it('should return available versions for a specific module', () => request(app)
.get('/v1/modules/aws-modules/vpc/aws/versions')
.expect('Content-Type', /application\/json/)
.expect(200)
.then((res) => {
expect(res.body).to.have.property('modules').to.have.lengthOf(1);
expect(res.body.modules[0].versions).to.have.lengthOf(3);
expect(res.body.modules[0]).to.have.property('versions').to.have.lengthOf(3);
}));
it('should return root and submodules', () => request(app)
.get('/v1/modules/aws-modules/vpc/aws/versions')
.expect('Content-Type', /application\/json/)
.expect(200)
.then((res) => {
const specificModule = res.body.modules[0].versions[0];
expect(specificModule)
.to.have.property('root')
.to.have.property('name').to.equal('vpc');
expect(specificModule)
.to.have.property('submodules').to.have.lengthOf(1);
expect(specificModule.submodules[0])
.to.have.property('name').to.equal('example');
}));
});
describe('GET /v1/modules/:namespace/:name', () => {
before(async () => {
await save({
namespace: 'hashicorp', name: 'consul', provider: 'azurerm', version: '0.1.0', owner: '',
});
await save({
namespace: 'hashicorp', name: 'consul', provider: 'azurerm', version: '0.2.0', owner: '',
});
await save({
namespace: 'hashicorp', name: 'consul', provider: 'aws', version: '1.1.1', owner: '',
});
await save({
namespace: 'hashicorp', name: 'consul', provider: 'aws', version: '1.1.2', owner: '',
});
await save({
namespace: 'hashicorp', name: 'consul', provider: 'google', version: '1.1.2', owner: '',
});
});
after(async () => {
await deleteDbAll(db);
});
it('should return all latest version of module for all providers', () => request(app)
.get('/v1/modules/hashicorp/consul')
.expect('Content-Type', /application\/json/)
.expect(200)
.then((res) => {
expect(res.body).to.have.property('modules').to.have.lengthOf(3);
expect(res.body.modules[0].provider).to.equal('azurerm');
expect(res.body.modules[0].version).to.equal('0.2.0');
expect(res.body.modules[1].provider).to.equal('aws');
expect(res.body.modules[1].version).to.equal('1.1.2');
expect(res.body.modules[2].provider).to.equal('google');
expect(res.body.modules[2].version).to.equal('1.1.2');
}));
it('should support pagination', () => request(app)
.get('/v1/modules/hashicorp/consul?offset=1&limit=1')
.expect('Content-Type', /application\/json/)
.expect(200)
.then((res) => {
expect(res.body).to.have.property('meta');
expect(res.body.meta).to.have.property('limit').to.equal(1);
expect(res.body.meta).to.have.property('current_offset').to.equal(1);
expect(res.body.meta).to.have.property('next_offset').to.equal(2);
expect(res.body.meta).to.have.property('next_url').to.equal('/v1/modules/hashicorp/consul?limit=1&offset=2');
expect(res.body).to.have.property('modules').to.have.lengthOf(1);
}));
});