-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathdeveloperApp.js
352 lines (323 loc) · 12.2 KB
/
developerApp.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
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
// developerApp.js
// ------------------------------------------------------------------
//
// Tests for operations on Developer apps.
//
// Copyright 2017-2025 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
/* global describe, faker, it, before, after, assert */
const common = require("./common");
describe("DeveloperApp", function () {
this.timeout(common.testTimeout);
this.slow(common.slowThreshold);
common.connectApigee(function (org) {
const entityName =
"apigee-edge-js-test-" + faker.lorem.word() + faker.random.number(),
firstName = faker.name.firstName(),
lastName = faker.name.lastName(),
developerEmail = `${firstName}.${lastName}@apigee-edge-js-test.org`,
createOptions = {
developerEmail,
lastName,
firstName,
userName: firstName + lastName,
};
let apiProducts = [];
before(() =>
org.developers
.create(createOptions)
.then(() => org.products.get())
.then((result) => {
apiProducts = result;
}),
);
after(() => org.developers.del({ developerEmail }));
describe("create", function () {
it("should create a developer app", () => {
const options = {
developerEmail,
name: entityName,
apiProduct: apiProducts[0],
};
return org.developerapps
.create(options)
.then((result) => {
assert.exists(result.name);
assert.exists(result.credentials);
assert.isAtLeast(result.credentials.length, 1);
})
.catch((error) => {
var util = require("util");
console.log(util.format(error));
assert.fail("should not be reached");
});
});
it("should fail to create a developer app with existing name", () => {
const options = {
developerEmail,
name: entityName,
apiProduct: apiProducts[0],
};
return org.developerapps
.create(options)
.then(() => assert.fail("should not be reached"))
.catch((error) => {
assert.equal(error, "Error: bad status: 409");
assert.exists(error.result);
assert.equal(
error.result.message,
`App with name ${entityName} already exists`,
);
});
});
it("should fail to create a developer app w/non-existing product", () => {
const fakeName = faker.random.alphaNumeric(22);
const options = {
developerEmail,
name: entityName + "-B",
apiProduct: fakeName,
};
return org.developerapps
.create(options)
.then(() => assert.fail("should not be reached"))
.catch((error) => {
//console.log(error.result.message);
assert.equal(error, "Error: bad status: 404");
assert.exists(error.result);
assert.exists(error.result.message);
assert.equal(
error.result.message,
`Product with id [${fakeName}] does not exist`,
);
});
});
it("should fail to create a developer app - no name", () => {
const options = {
developerEmail,
apiProduct: faker.random.alphaNumeric(22),
};
return org.developerapps
.create(options)
.then(() => assert.fail("should not be reached"))
.catch((error) => {
assert.equal(error, "Error: missing required input: appName");
});
});
it("should fail to create a developer app - no developer", () => {
const options = {
name: entityName + "-C",
apiProduct: faker.random.alphaNumeric(22),
};
return org.developerapps
.create(options)
.then(() => assert.fail("should not be reached"))
.catch((error) => {
assert.equal(error, "Error: missing required input: email");
});
});
it("should fail to create a developer app - no product", () => {
const options = {
developerEmail,
name: entityName + "-D",
};
return org.developerapps
.create(options)
.then(() => assert.fail("should not be reached"))
.catch((error) => {
assert.equal(error, "Error: missing required input: apiProduct");
});
});
});
describe("get", function () {
it("should get a list of developerapps", () =>
org.developerapps
.get({ developerEmail })
.then((result) => {
assert.notExists(result.error);
assert.exists(result.length);
assert.isAtLeast(result.length, 1);
})
.catch((reason) => assert.fail("should not be reached")));
it("should fail to get apps when supplying no identifier", () =>
org.developerapps
.get({ nothing: "useful" })
.then(() => assert.fail("should not be reached"))
.catch((error) => {
//const util = require('util');
//console.log('reason: ' + util.format(reason));
assert.equal(error, "Error: missing developer email or id");
}));
it("should fail to get a non-existent developerapp", () => {
const nonExistentApp = faker.random.alphaNumeric(22);
return org.developerapps
.get({ developerEmail, name: nonExistentApp })
.then(() => assert.fail("should not be reached"))
.catch((reason) => {
assert.isNotNull(reason.error, "the expected error did not occur");
assert.exists(reason.result);
assert.exists(reason.result.message);
assert.equal(
reason.result.message,
`App named ${nonExistentApp} does not exist under ${developerEmail}`,
);
});
});
it("should fail to get apps under a non-existent developer", () => {
const nonExistentDev = faker.random.alphaNumeric(22);
return org.developerapps
.get({ developerEmail: nonExistentDev })
.then(() => assert.fail("should not be reached"))
.catch((error) => {
assert.isNotNull(error, "the expected error did not occur");
assert.exists(error.result);
assert.exists(error.result.message);
assert.equal(
error.result.message,
`DeveloperId ${nonExistentDev} does not exist in organization ${org.conn.orgname}`,
);
});
});
});
describe("attributes", function () {
var originalAttrCount = 0;
it("should get the custom attributes on an existing developerapp", () => {
//org.conn.verbosity = 1;
return org.developerapps
.get({ developerEmail, name: entityName })
.then((result) => {
assert.exists(result.attributes);
assert.isTrue(Array.isArray(result.attributes));
originalAttrCount = result.attributes.length;
if (result.attributes.length > 0) {
//console.log('[0]: ' +JSON.stringify(result.attributes[0]));
}
})
.catch((reason) => {
const util = require("util");
console.log(util.format(reason));
assert.fail("should not be reached");
});
});
it("should update the custom attributes on an existing developerapp", () => {
const attributes = {
updatedBy: "apigee-edge-js-test",
updateDate: new Date().toISOString(),
};
return org.developerapps
.update({ developerEmail, name: entityName, attributes })
.then((result) => {
assert.exists(result.attributes);
//console.log('attrs: ' + JSON.stringify(result.attributes));
assert.equal(result.attributes.length, 2 + originalAttrCount);
assert.isTrue(
result.attributes.find((x) => x.name == "updatedBy").value ==
"apigee-edge-js-test",
);
assert(result.attributes.find((x) => x.name == "updateDate"));
});
//.catch(reason => assert.fail('should not be reached'));
});
it("should read the custom attributes on an existing developerapp", () => {
return org.developerapps
.get({ developerEmail, name: entityName })
.then((result) => {
assert.exists(result.attributes);
assert.equal(result.attributes.length, 2 + originalAttrCount);
assert.isTrue(
result.attributes.find((x) => x.name == "updatedBy").value ==
"apigee-edge-js-test",
);
assert(result.attributes.find((x) => x.name == "updateDate"));
});
// .catch(reason => assert.fail('should not be reached'));
});
it("should replace the custom attributes on an existing developerapp", () => {
const attributes = {};
return org.developerapps
.update({
developerEmail,
name: entityName,
replace: true,
attributes,
})
.then((result) => {
assert.exists(result.attributes);
assert.equal(result.attributes.length, 0);
})
.catch((reason) => assert.fail("should not be reached"));
});
});
describe("delete", function () {
it("should delete a developerapp", () =>
org.developerapps
.del({ developerEmail, name: entityName })
.catch((reason) => {
console.log(reason.error);
assert.fail("should not be reached");
}));
it("should fail to delete a developerapp because no email", () =>
org.developerapps
.del({ name: entityName })
.then(() => assert.fail("should not be reached"))
.catch((error) => {
assert.equal(error, "Error: missing developer email or id");
}));
it("should fail to delete a developerapp because no name", () =>
org.developerapps
.del({ developerEmail })
.then(() => assert.fail("should not be reached"))
.catch((error) => {
assert.equal(error, "Error: missing developer app name");
}));
it("should fail to delete a non-existent developerapp", () => {
const fakeName = faker.random.alphaNumeric(22);
return org.developerapps
.del({ developerEmail, name: fakeName })
.then(() => assert.fail("should not be reached"))
.catch((error) => {
assert.equal(error, "Error: bad status: 404");
assert.exists(error.result);
assert.equal(
error.result.code,
"developer.service.AppDoesNotExist",
);
assert.equal(
error.result.message,
`App named ${fakeName} does not exist under ${developerEmail}`,
);
});
});
it("should fail to delete an app under a non-existent developer", () => {
const fakeName = faker.random.alphaNumeric(22);
const fakeEmail = faker.random.alphaNumeric(22);
return org.developerapps
.del({ developerEmail: fakeEmail, name: fakeName })
.then(() => assert.fail("should not be reached"))
.catch((error) => {
assert.equal(error, "Error: bad status: 404");
assert.exists(error.result);
assert.equal(
error.result.code,
"developer.service.DeveloperIdDoesNotExist",
);
assert.equal(
error.result.message,
`DeveloperId ${fakeEmail} does not exist in organization ${org.conn.orgname}`,
);
});
});
});
});
});