@superblocksteam/sabs-client 0.152.0 → 0.154.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/sabs.d.ts.map +1 -1
- package/dist/sabs.js +78 -0
- package/dist/sabs.js.map +1 -1
- package/dist/sabs.test.js +237 -25
- package/dist/sabs.test.js.map +1 -1
- package/package.json +2 -2
- package/src/sabs.test.ts +465 -169
- package/src/sabs.ts +85 -0
- package/tsconfig.tsbuildinfo +1 -1
package/src/sabs.test.ts
CHANGED
|
@@ -17,22 +17,57 @@ describe('sabs service', () => {
|
|
|
17
17
|
});
|
|
18
18
|
|
|
19
19
|
describe('build', () => {
|
|
20
|
-
test.each([
|
|
21
|
-
|
|
22
|
-
{ accessToken
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
20
|
+
test.each([{ accessToken: 'anyScopedJwt', expectedHeaders: { Authorization: 'Bearer anyScopedJwt' } }])(
|
|
21
|
+
'returns expected response with accessToken=$accessToken',
|
|
22
|
+
async ({ accessToken, expectedHeaders }) => {
|
|
23
|
+
const expectedBuildId = 'expectedBuildId';
|
|
24
|
+
const expectedCreated = new Date();
|
|
25
|
+
const expectedUpdated = new Date();
|
|
26
|
+
|
|
27
|
+
const mockAxios = jest.spyOn(axios, 'request');
|
|
28
|
+
mockAxios.mockResolvedValue({
|
|
29
|
+
data: {
|
|
30
|
+
buildId: expectedBuildId,
|
|
31
|
+
created: expectedCreated,
|
|
32
|
+
updated: expectedUpdated
|
|
33
|
+
}
|
|
34
|
+
});
|
|
27
35
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
36
|
+
const anyDirectoryHash = 'anyDirectoryHash';
|
|
37
|
+
const anyApplicationMetadata = new ApplicationMetadata({
|
|
38
|
+
id: 'anyApplicationId',
|
|
39
|
+
organizationId: 'anyOrganizationId'
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
const sabs = new SabsClient('http://localhost:3000');
|
|
43
|
+
const result = await sabs.build({
|
|
44
|
+
directoryHash: anyDirectoryHash,
|
|
45
|
+
meta: anyApplicationMetadata,
|
|
46
|
+
buildKey: anyBuildKey,
|
|
47
|
+
accessToken
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
expect(result).toEqual({
|
|
31
51
|
buildId: expectedBuildId,
|
|
32
52
|
created: expectedCreated,
|
|
33
53
|
updated: expectedUpdated
|
|
34
|
-
}
|
|
35
|
-
|
|
54
|
+
});
|
|
55
|
+
expect(mockAxios).toHaveBeenCalledWith({
|
|
56
|
+
method: 'POST',
|
|
57
|
+
url: 'http://localhost:3000/v1/builds',
|
|
58
|
+
headers: expectedHeaders,
|
|
59
|
+
data: {
|
|
60
|
+
directoryHash: anyDirectoryHash,
|
|
61
|
+
applicationMetadata: anyApplicationMetadata,
|
|
62
|
+
buildKey: anyBuildKey
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
);
|
|
67
|
+
|
|
68
|
+
test('raises error when request fails', async () => {
|
|
69
|
+
const mockAxios = jest.spyOn(axios, 'request');
|
|
70
|
+
mockAxios.mockRejectedValue(new Error('any error'));
|
|
36
71
|
|
|
37
72
|
const anyDirectoryHash = 'anyDirectoryHash';
|
|
38
73
|
const anyApplicationMetadata = new ApplicationMetadata({
|
|
@@ -41,22 +76,14 @@ describe('sabs service', () => {
|
|
|
41
76
|
});
|
|
42
77
|
|
|
43
78
|
const sabs = new SabsClient('http://localhost:3000');
|
|
44
|
-
|
|
45
|
-
directoryHash: anyDirectoryHash,
|
|
46
|
-
|
|
47
|
-
buildKey: anyBuildKey,
|
|
48
|
-
accessToken
|
|
49
|
-
});
|
|
79
|
+
await expect(
|
|
80
|
+
sabs.build({ directoryHash: anyDirectoryHash, meta: anyApplicationMetadata, buildKey: anyBuildKey, accessToken: anyAccessToken })
|
|
81
|
+
).rejects.toThrow();
|
|
50
82
|
|
|
51
|
-
expect(result).toEqual({
|
|
52
|
-
buildId: expectedBuildId,
|
|
53
|
-
created: expectedCreated,
|
|
54
|
-
updated: expectedUpdated
|
|
55
|
-
});
|
|
56
83
|
expect(mockAxios).toHaveBeenCalledWith({
|
|
57
84
|
method: 'POST',
|
|
58
85
|
url: 'http://localhost:3000/v1/builds',
|
|
59
|
-
headers:
|
|
86
|
+
headers: { Authorization: `Bearer ${anyAccessToken}` },
|
|
60
87
|
data: {
|
|
61
88
|
directoryHash: anyDirectoryHash,
|
|
62
89
|
applicationMetadata: anyApplicationMetadata,
|
|
@@ -65,68 +92,109 @@ describe('sabs service', () => {
|
|
|
65
92
|
});
|
|
66
93
|
});
|
|
67
94
|
|
|
68
|
-
test('raises error when
|
|
69
|
-
const
|
|
70
|
-
|
|
95
|
+
test('raises error when directory hash is empty', async () => {
|
|
96
|
+
const sabs = new SabsClient('http://localhost:3000');
|
|
97
|
+
const anyApplicationMetadata = new ApplicationMetadata({
|
|
98
|
+
id: 'anyApplicationId',
|
|
99
|
+
organizationId: 'anyOrganizationId'
|
|
100
|
+
});
|
|
101
|
+
await expect(sabs.build({ directoryHash: '', meta: anyApplicationMetadata, buildKey: anyBuildKey })).rejects.toThrow();
|
|
102
|
+
});
|
|
71
103
|
|
|
72
|
-
|
|
104
|
+
test('raises error when application metadata is empty', async () => {
|
|
105
|
+
const sabs = new SabsClient('http://localhost:3000');
|
|
106
|
+
await expect(
|
|
107
|
+
sabs.build({
|
|
108
|
+
directoryHash: '',
|
|
109
|
+
meta: undefined as unknown as ApplicationMetadata,
|
|
110
|
+
buildKey: anyBuildKey,
|
|
111
|
+
accessToken: anyAccessToken
|
|
112
|
+
})
|
|
113
|
+
).rejects.toThrow();
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
test('raises error when build key is empty', async () => {
|
|
117
|
+
const sabs = new SabsClient('http://localhost:3000');
|
|
73
118
|
const anyApplicationMetadata = new ApplicationMetadata({
|
|
74
119
|
id: 'anyApplicationId',
|
|
75
120
|
organizationId: 'anyOrganizationId'
|
|
76
121
|
});
|
|
122
|
+
await expect(
|
|
123
|
+
sabs.build({ directoryHash: 'anyDirectoryHash', meta: anyApplicationMetadata, buildKey: '', accessToken: anyAccessToken })
|
|
124
|
+
).rejects.toThrow();
|
|
125
|
+
});
|
|
77
126
|
|
|
127
|
+
test('raises error when application id is empty', async () => {
|
|
78
128
|
const sabs = new SabsClient('http://localhost:3000');
|
|
79
|
-
|
|
129
|
+
const anyApplicationMetadata = new ApplicationMetadata({
|
|
130
|
+
id: '',
|
|
131
|
+
organizationId: 'anyOrganizationId'
|
|
132
|
+
});
|
|
133
|
+
await expect(
|
|
134
|
+
sabs.build({ directoryHash: 'anyDirectoryHash', meta: anyApplicationMetadata, buildKey: anyBuildKey, accessToken: anyAccessToken })
|
|
135
|
+
).rejects.toThrow();
|
|
136
|
+
});
|
|
80
137
|
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
}
|
|
138
|
+
test('raises error when organization id is empty', async () => {
|
|
139
|
+
const sabs = new SabsClient('http://localhost:3000');
|
|
140
|
+
const anyApplicationMetadata = new ApplicationMetadata({
|
|
141
|
+
id: 'anyApplicationId',
|
|
142
|
+
organizationId: ''
|
|
143
|
+
});
|
|
144
|
+
await expect(
|
|
145
|
+
sabs.build({ directoryHash: 'anyDirectoryHash', meta: anyApplicationMetadata, buildKey: anyBuildKey, accessToken: anyAccessToken })
|
|
146
|
+
).rejects.toThrow();
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
test('raises error when access token is empty', async () => {
|
|
150
|
+
const sabs = new SabsClient('http://localhost:3000');
|
|
151
|
+
const anyApplicationMetadata = new ApplicationMetadata({
|
|
152
|
+
id: 'anyApplicationId',
|
|
153
|
+
organizationId: 'anyOrganizationId'
|
|
89
154
|
});
|
|
155
|
+
await expect(
|
|
156
|
+
sabs.build({ directoryHash: 'anyDirectoryHash', meta: anyApplicationMetadata, buildKey: anyBuildKey, accessToken: '' })
|
|
157
|
+
).rejects.toThrow();
|
|
90
158
|
});
|
|
91
159
|
});
|
|
92
160
|
|
|
93
161
|
describe('status', () => {
|
|
94
|
-
test.each([
|
|
95
|
-
|
|
96
|
-
{ accessToken
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
162
|
+
test.each([{ accessToken: 'anyScopedJwt', expectedHeaders: { Authorization: 'Bearer anyScopedJwt' } }])(
|
|
163
|
+
'returns expected response with accessToken=$accessToken',
|
|
164
|
+
async ({ accessToken, expectedHeaders }) => {
|
|
165
|
+
const expectedBuildId = 'expectedBuildId';
|
|
166
|
+
const expectedStatus = BuildStatus.SUCCESS;
|
|
167
|
+
const expectedCreated = new Date();
|
|
168
|
+
const expectedUpdated = new Date();
|
|
169
|
+
|
|
170
|
+
const mockAxios = jest.spyOn(axios, 'request');
|
|
171
|
+
mockAxios.mockResolvedValue({
|
|
172
|
+
data: {
|
|
173
|
+
buildId: expectedBuildId,
|
|
174
|
+
status: expectedStatus,
|
|
175
|
+
created: expectedCreated,
|
|
176
|
+
updated: expectedUpdated
|
|
177
|
+
}
|
|
178
|
+
});
|
|
102
179
|
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
180
|
+
const anyBuildId = 'anyBuildId';
|
|
181
|
+
|
|
182
|
+
const sabs = new SabsClient('http://localhost:3000');
|
|
183
|
+
const result = await sabs.status({ buildId: anyBuildId, accessToken });
|
|
184
|
+
|
|
185
|
+
expect(result).toEqual({
|
|
106
186
|
buildId: expectedBuildId,
|
|
107
187
|
status: expectedStatus,
|
|
108
188
|
created: expectedCreated,
|
|
109
189
|
updated: expectedUpdated
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
expect(result).toEqual({
|
|
119
|
-
buildId: expectedBuildId,
|
|
120
|
-
status: expectedStatus,
|
|
121
|
-
created: expectedCreated,
|
|
122
|
-
updated: expectedUpdated
|
|
123
|
-
});
|
|
124
|
-
expect(mockAxios).toHaveBeenCalledWith({
|
|
125
|
-
method: 'GET',
|
|
126
|
-
url: `http://localhost:3000/v1/builds/${anyBuildId}`,
|
|
127
|
-
headers: expectedHeaders
|
|
128
|
-
});
|
|
129
|
-
});
|
|
190
|
+
});
|
|
191
|
+
expect(mockAxios).toHaveBeenCalledWith({
|
|
192
|
+
method: 'GET',
|
|
193
|
+
url: `http://localhost:3000/v1/builds/${anyBuildId}`,
|
|
194
|
+
headers: expectedHeaders
|
|
195
|
+
});
|
|
196
|
+
}
|
|
197
|
+
);
|
|
130
198
|
|
|
131
199
|
test('raises error when request fails', async () => {
|
|
132
200
|
const mockAxios = jest.spyOn(axios, 'request');
|
|
@@ -135,23 +203,70 @@ describe('sabs service', () => {
|
|
|
135
203
|
const anyBuildId = 'anyBuildId';
|
|
136
204
|
|
|
137
205
|
const sabs = new SabsClient('http://localhost:3000');
|
|
138
|
-
await expect(sabs.status({ buildId: anyBuildId })).rejects.toThrow();
|
|
206
|
+
await expect(sabs.status({ buildId: anyBuildId, accessToken: anyAccessToken })).rejects.toThrow();
|
|
139
207
|
|
|
140
208
|
expect(mockAxios).toHaveBeenCalledWith({
|
|
209
|
+
headers: { Authorization: `Bearer ${anyAccessToken}` },
|
|
141
210
|
method: 'GET',
|
|
142
211
|
url: `http://localhost:3000/v1/builds/${anyBuildId}`
|
|
143
212
|
});
|
|
144
213
|
});
|
|
214
|
+
|
|
215
|
+
test('raises error when build id is empty', async () => {
|
|
216
|
+
const sabs = new SabsClient('http://localhost:3000');
|
|
217
|
+
await expect(sabs.status({ buildId: '', accessToken: anyAccessToken })).rejects.toThrow();
|
|
218
|
+
});
|
|
219
|
+
|
|
220
|
+
test('raises error when access token is empty', async () => {
|
|
221
|
+
const sabs = new SabsClient('http://localhost:3000');
|
|
222
|
+
await expect(sabs.status({ buildId: 'anyBuildId', accessToken: '' })).rejects.toThrow();
|
|
223
|
+
});
|
|
145
224
|
});
|
|
146
225
|
|
|
147
226
|
describe('list', () => {
|
|
148
|
-
test.each([
|
|
149
|
-
|
|
150
|
-
{ accessToken
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
227
|
+
test.each([{ accessToken: 'anyScopedJwt', expectedHeaders: { Authorization: 'Bearer anyScopedJwt' } }])(
|
|
228
|
+
'returns expected response with accessToken=$accessToken',
|
|
229
|
+
async ({ accessToken, expectedHeaders }) => {
|
|
230
|
+
const mockAxios = jest.spyOn(axios, 'request');
|
|
231
|
+
mockAxios.mockResolvedValue({
|
|
232
|
+
data: {
|
|
233
|
+
builds: [
|
|
234
|
+
{
|
|
235
|
+
buildId: 'id1',
|
|
236
|
+
status: BuildStatus.SUCCESS,
|
|
237
|
+
created: new Date('2023-01-01'),
|
|
238
|
+
updated: new Date('2023-01-02')
|
|
239
|
+
},
|
|
240
|
+
{
|
|
241
|
+
buildId: 'id2',
|
|
242
|
+
status: BuildStatus.RUNNING,
|
|
243
|
+
created: new Date('2023-01-03'),
|
|
244
|
+
updated: new Date('2023-01-04')
|
|
245
|
+
},
|
|
246
|
+
{
|
|
247
|
+
buildId: 'id3',
|
|
248
|
+
status: BuildStatus.FAILED,
|
|
249
|
+
error: 'Build failed',
|
|
250
|
+
created: new Date('2023-01-05'),
|
|
251
|
+
updated: new Date('2023-01-06')
|
|
252
|
+
}
|
|
253
|
+
]
|
|
254
|
+
}
|
|
255
|
+
});
|
|
256
|
+
|
|
257
|
+
const anyOrganizationId = 'anyOrganizationId';
|
|
258
|
+
const anyApplicationId = 'anyApplicationId';
|
|
259
|
+
const anyDirectoryHash = 'anyDirectoryHash';
|
|
260
|
+
|
|
261
|
+
const sabs = new SabsClient('http://localhost:3000');
|
|
262
|
+
const result = await sabs.list({
|
|
263
|
+
organizationId: anyOrganizationId,
|
|
264
|
+
applicationId: anyApplicationId,
|
|
265
|
+
directoryHash: anyDirectoryHash,
|
|
266
|
+
accessToken
|
|
267
|
+
});
|
|
268
|
+
|
|
269
|
+
expect(result).toEqual({
|
|
155
270
|
builds: [
|
|
156
271
|
{
|
|
157
272
|
buildId: 'id1',
|
|
@@ -173,55 +288,19 @@ describe('sabs service', () => {
|
|
|
173
288
|
updated: new Date('2023-01-06')
|
|
174
289
|
}
|
|
175
290
|
]
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
organizationId: anyOrganizationId,
|
|
186
|
-
applicationId: anyApplicationId,
|
|
187
|
-
directoryHash: anyDirectoryHash,
|
|
188
|
-
accessToken
|
|
189
|
-
});
|
|
190
|
-
|
|
191
|
-
expect(result).toEqual({
|
|
192
|
-
builds: [
|
|
193
|
-
{
|
|
194
|
-
buildId: 'id1',
|
|
195
|
-
status: BuildStatus.SUCCESS,
|
|
196
|
-
created: new Date('2023-01-01'),
|
|
197
|
-
updated: new Date('2023-01-02')
|
|
198
|
-
},
|
|
199
|
-
{
|
|
200
|
-
buildId: 'id2',
|
|
201
|
-
status: BuildStatus.RUNNING,
|
|
202
|
-
created: new Date('2023-01-03'),
|
|
203
|
-
updated: new Date('2023-01-04')
|
|
204
|
-
},
|
|
205
|
-
{
|
|
206
|
-
buildId: 'id3',
|
|
207
|
-
status: BuildStatus.FAILED,
|
|
208
|
-
error: 'Build failed',
|
|
209
|
-
created: new Date('2023-01-05'),
|
|
210
|
-
updated: new Date('2023-01-06')
|
|
291
|
+
});
|
|
292
|
+
expect(mockAxios).toHaveBeenCalledWith({
|
|
293
|
+
method: 'GET',
|
|
294
|
+
url: `http://localhost:3000/v1/build`,
|
|
295
|
+
headers: expectedHeaders,
|
|
296
|
+
params: {
|
|
297
|
+
organizationId: anyOrganizationId,
|
|
298
|
+
applicationId: anyApplicationId,
|
|
299
|
+
directoryHash: anyDirectoryHash
|
|
211
300
|
}
|
|
212
|
-
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
method: 'GET',
|
|
216
|
-
url: `http://localhost:3000/v1/build`,
|
|
217
|
-
headers: expectedHeaders,
|
|
218
|
-
params: {
|
|
219
|
-
organizationId: anyOrganizationId,
|
|
220
|
-
applicationId: anyApplicationId,
|
|
221
|
-
directoryHash: anyDirectoryHash
|
|
222
|
-
}
|
|
223
|
-
});
|
|
224
|
-
});
|
|
301
|
+
});
|
|
302
|
+
}
|
|
303
|
+
);
|
|
225
304
|
|
|
226
305
|
test('raises error when request fails', async () => {
|
|
227
306
|
const mockAxios = jest.spyOn(axios, 'request');
|
|
@@ -236,14 +315,15 @@ describe('sabs service', () => {
|
|
|
236
315
|
sabs.list({
|
|
237
316
|
organizationId: anyOrganizationId,
|
|
238
317
|
applicationId: anyApplicationId,
|
|
239
|
-
directoryHash: anyDirectoryHash
|
|
318
|
+
directoryHash: anyDirectoryHash,
|
|
319
|
+
accessToken: anyAccessToken
|
|
240
320
|
})
|
|
241
321
|
).rejects.toThrow();
|
|
242
322
|
|
|
243
323
|
expect(mockAxios).toHaveBeenCalledWith({
|
|
244
324
|
method: 'GET',
|
|
245
325
|
url: `http://localhost:3000/v1/build`,
|
|
246
|
-
headers:
|
|
326
|
+
headers: { Authorization: `Bearer ${anyAccessToken}` },
|
|
247
327
|
params: {
|
|
248
328
|
organizationId: anyOrganizationId,
|
|
249
329
|
applicationId: anyApplicationId,
|
|
@@ -251,48 +331,123 @@ describe('sabs service', () => {
|
|
|
251
331
|
}
|
|
252
332
|
});
|
|
253
333
|
});
|
|
334
|
+
|
|
335
|
+
test('raises error when organization id is empty', async () => {
|
|
336
|
+
const sabs = new SabsClient('http://localhost:3000');
|
|
337
|
+
await expect(
|
|
338
|
+
sabs.list({ organizationId: '', applicationId: 'anyApplicationId', directoryHash: 'anyDirectoryHash', accessToken: anyAccessToken })
|
|
339
|
+
).rejects.toThrow();
|
|
340
|
+
});
|
|
341
|
+
|
|
342
|
+
test('raises error when application id is empty', async () => {
|
|
343
|
+
const sabs = new SabsClient('http://localhost:3000');
|
|
344
|
+
await expect(
|
|
345
|
+
sabs.list({
|
|
346
|
+
organizationId: 'anyOrganizationId',
|
|
347
|
+
applicationId: '',
|
|
348
|
+
directoryHash: 'anyDirectoryHash',
|
|
349
|
+
accessToken: anyAccessToken
|
|
350
|
+
})
|
|
351
|
+
).rejects.toThrow();
|
|
352
|
+
});
|
|
353
|
+
|
|
354
|
+
test('raises error when directory hash is empty', async () => {
|
|
355
|
+
const sabs = new SabsClient('http://localhost:3000');
|
|
356
|
+
await expect(
|
|
357
|
+
sabs.list({
|
|
358
|
+
organizationId: 'anyOrganizationId',
|
|
359
|
+
applicationId: 'anyApplicationId',
|
|
360
|
+
directoryHash: '',
|
|
361
|
+
accessToken: anyAccessToken
|
|
362
|
+
})
|
|
363
|
+
).rejects.toThrow();
|
|
364
|
+
});
|
|
365
|
+
|
|
366
|
+
test('raises error when access token is empty', async () => {
|
|
367
|
+
const sabs = new SabsClient('http://localhost:3000');
|
|
368
|
+
await expect(
|
|
369
|
+
sabs.list({
|
|
370
|
+
organizationId: 'anyOrganizationId',
|
|
371
|
+
applicationId: 'anyApplicationId',
|
|
372
|
+
directoryHash: 'anyDirectoryHash',
|
|
373
|
+
accessToken: ''
|
|
374
|
+
})
|
|
375
|
+
).rejects.toThrow();
|
|
376
|
+
});
|
|
254
377
|
});
|
|
255
378
|
|
|
256
379
|
describe('terminate', () => {
|
|
257
|
-
test.each([
|
|
258
|
-
|
|
259
|
-
{ accessToken
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
380
|
+
test.each([{ accessToken: 'anyScopedJwt', expectedHeaders: { Authorization: 'Bearer anyScopedJwt' } }])(
|
|
381
|
+
'returns expected response with accessToken=$accessToken',
|
|
382
|
+
async ({ accessToken, expectedHeaders }) => {
|
|
383
|
+
const expectedBuildId = 'expectedBuildId';
|
|
384
|
+
const expectedStatus = BuildStatus.TIMED_OUT;
|
|
385
|
+
const expectedError = 'build timed out';
|
|
386
|
+
const expectedCreated = new Date();
|
|
387
|
+
const expectedUpdated = new Date();
|
|
388
|
+
|
|
389
|
+
const mockAxios = jest.spyOn(axios, 'request');
|
|
390
|
+
mockAxios.mockResolvedValue({
|
|
391
|
+
data: {
|
|
392
|
+
buildId: expectedBuildId,
|
|
393
|
+
status: expectedStatus,
|
|
394
|
+
error: expectedError,
|
|
395
|
+
created: expectedCreated,
|
|
396
|
+
updated: expectedUpdated
|
|
397
|
+
}
|
|
398
|
+
});
|
|
266
399
|
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
400
|
+
const anyBuildId = 'anyBuildId';
|
|
401
|
+
const anyStatus = BuildStatus.TIMED_OUT;
|
|
402
|
+
const anyError = 'build timed out';
|
|
403
|
+
|
|
404
|
+
const sabs = new SabsClient('http://localhost:3000');
|
|
405
|
+
const result = await sabs.terminate({
|
|
406
|
+
buildId: anyBuildId,
|
|
407
|
+
status: anyStatus,
|
|
408
|
+
buildKey: anyBuildKey,
|
|
409
|
+
error: anyError,
|
|
410
|
+
accessToken
|
|
411
|
+
});
|
|
412
|
+
|
|
413
|
+
expect(result).toEqual({
|
|
270
414
|
buildId: expectedBuildId,
|
|
271
415
|
status: expectedStatus,
|
|
272
416
|
error: expectedError,
|
|
273
417
|
created: expectedCreated,
|
|
274
418
|
updated: expectedUpdated
|
|
275
|
-
}
|
|
276
|
-
|
|
419
|
+
});
|
|
420
|
+
expect(mockAxios).toHaveBeenCalledWith({
|
|
421
|
+
method: 'POST',
|
|
422
|
+
url: `http://localhost:3000/v1/builds/${anyBuildId}/terminate`,
|
|
423
|
+
headers: expectedHeaders,
|
|
424
|
+
data: {
|
|
425
|
+
buildId: anyBuildId,
|
|
426
|
+
status: anyStatus,
|
|
427
|
+
error: anyError,
|
|
428
|
+
buildKey: anyBuildKey
|
|
429
|
+
}
|
|
430
|
+
});
|
|
431
|
+
}
|
|
432
|
+
);
|
|
433
|
+
|
|
434
|
+
test('raises error when request fails', async () => {
|
|
435
|
+
const mockAxios = jest.spyOn(axios, 'request');
|
|
436
|
+
mockAxios.mockRejectedValue(new Error('any error'));
|
|
277
437
|
|
|
278
438
|
const anyBuildId = 'anyBuildId';
|
|
279
439
|
const anyStatus = BuildStatus.TIMED_OUT;
|
|
280
440
|
const anyError = 'build timed out';
|
|
281
441
|
|
|
282
442
|
const sabs = new SabsClient('http://localhost:3000');
|
|
283
|
-
|
|
443
|
+
await expect(
|
|
444
|
+
sabs.terminate({ buildId: anyBuildId, status: anyStatus, buildKey: anyBuildKey, error: anyError, accessToken: anyAccessToken })
|
|
445
|
+
).rejects.toThrow();
|
|
284
446
|
|
|
285
|
-
expect(result).toEqual({
|
|
286
|
-
buildId: expectedBuildId,
|
|
287
|
-
status: expectedStatus,
|
|
288
|
-
error: expectedError,
|
|
289
|
-
created: expectedCreated,
|
|
290
|
-
updated: expectedUpdated
|
|
291
|
-
});
|
|
292
447
|
expect(mockAxios).toHaveBeenCalledWith({
|
|
293
448
|
method: 'POST',
|
|
449
|
+
headers: { Authorization: `Bearer ${anyAccessToken}` },
|
|
294
450
|
url: `http://localhost:3000/v1/builds/${anyBuildId}/terminate`,
|
|
295
|
-
headers: expectedHeaders,
|
|
296
451
|
data: {
|
|
297
452
|
buildId: anyBuildId,
|
|
298
453
|
status: anyStatus,
|
|
@@ -302,27 +457,56 @@ describe('sabs service', () => {
|
|
|
302
457
|
});
|
|
303
458
|
});
|
|
304
459
|
|
|
305
|
-
test('raises error when
|
|
306
|
-
const
|
|
307
|
-
|
|
460
|
+
test('raises error when build id is empty', async () => {
|
|
461
|
+
const sabs = new SabsClient('http://localhost:3000');
|
|
462
|
+
await expect(
|
|
463
|
+
sabs.terminate({
|
|
464
|
+
buildId: '',
|
|
465
|
+
status: BuildStatus.TIMED_OUT,
|
|
466
|
+
buildKey: anyBuildKey,
|
|
467
|
+
error: 'build timed out',
|
|
468
|
+
accessToken: anyAccessToken
|
|
469
|
+
})
|
|
470
|
+
).rejects.toThrow();
|
|
471
|
+
});
|
|
308
472
|
|
|
309
|
-
|
|
310
|
-
const
|
|
311
|
-
|
|
473
|
+
test('raises error when status is empty', async () => {
|
|
474
|
+
const sabs = new SabsClient('http://localhost:3000');
|
|
475
|
+
await expect(
|
|
476
|
+
sabs.terminate({
|
|
477
|
+
buildId: 'anyBuildId',
|
|
478
|
+
status: undefined as unknown as BuildStatus,
|
|
479
|
+
buildKey: anyBuildKey,
|
|
480
|
+
error: 'build timed out',
|
|
481
|
+
accessToken: anyAccessToken
|
|
482
|
+
})
|
|
483
|
+
).rejects.toThrow();
|
|
484
|
+
});
|
|
312
485
|
|
|
486
|
+
test('raises error when build key is empty', async () => {
|
|
313
487
|
const sabs = new SabsClient('http://localhost:3000');
|
|
314
|
-
await expect(
|
|
488
|
+
await expect(
|
|
489
|
+
sabs.terminate({
|
|
490
|
+
buildId: 'anyBuildId',
|
|
491
|
+
status: BuildStatus.TIMED_OUT,
|
|
492
|
+
buildKey: '',
|
|
493
|
+
error: 'build timed out',
|
|
494
|
+
accessToken: anyAccessToken
|
|
495
|
+
})
|
|
496
|
+
).rejects.toThrow();
|
|
497
|
+
});
|
|
315
498
|
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
buildId: anyBuildId,
|
|
321
|
-
status:
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
499
|
+
test('raises error when access token is empty', async () => {
|
|
500
|
+
const sabs = new SabsClient('http://localhost:3000');
|
|
501
|
+
await expect(
|
|
502
|
+
sabs.terminate({
|
|
503
|
+
buildId: 'anyBuildId',
|
|
504
|
+
status: BuildStatus.TIMED_OUT,
|
|
505
|
+
buildKey: anyBuildKey,
|
|
506
|
+
error: 'build timed out',
|
|
507
|
+
accessToken: ''
|
|
508
|
+
})
|
|
509
|
+
).rejects.toThrow();
|
|
326
510
|
});
|
|
327
511
|
});
|
|
328
512
|
|
|
@@ -356,7 +540,8 @@ describe('sabs service', () => {
|
|
|
356
540
|
const result = await sabs.bulkStatus({
|
|
357
541
|
organizationId: anyOrganizationId,
|
|
358
542
|
applicationId: anyApplicationId,
|
|
359
|
-
directoryHashes: anyDirectoryHashes
|
|
543
|
+
directoryHashes: anyDirectoryHashes,
|
|
544
|
+
accessToken: anyAccessToken
|
|
360
545
|
});
|
|
361
546
|
|
|
362
547
|
expect(result).toEqual({
|
|
@@ -377,6 +562,7 @@ describe('sabs service', () => {
|
|
|
377
562
|
});
|
|
378
563
|
expect(mockAxios).toHaveBeenCalledWith({
|
|
379
564
|
method: 'POST',
|
|
565
|
+
headers: { Authorization: `Bearer ${anyAccessToken}` },
|
|
380
566
|
url: `http://localhost:3000/v1/builds/${anyOrganizationId}/${anyApplicationId}/bulk-status`,
|
|
381
567
|
data: {
|
|
382
568
|
organizationId: anyOrganizationId,
|
|
@@ -385,6 +571,54 @@ describe('sabs service', () => {
|
|
|
385
571
|
}
|
|
386
572
|
});
|
|
387
573
|
});
|
|
574
|
+
|
|
575
|
+
test('raises error when access token is empty', async () => {
|
|
576
|
+
const sabs = new SabsClient('http://localhost:3000');
|
|
577
|
+
await expect(
|
|
578
|
+
sabs.bulkStatus({
|
|
579
|
+
organizationId: 'anyOrganizationId',
|
|
580
|
+
applicationId: 'anyApplicationId',
|
|
581
|
+
directoryHashes: ['anyDirectoryHash'],
|
|
582
|
+
accessToken: ''
|
|
583
|
+
})
|
|
584
|
+
).rejects.toThrow();
|
|
585
|
+
});
|
|
586
|
+
|
|
587
|
+
test('raises error when organization id is empty', async () => {
|
|
588
|
+
const sabs = new SabsClient('http://localhost:3000');
|
|
589
|
+
await expect(
|
|
590
|
+
sabs.bulkStatus({
|
|
591
|
+
organizationId: '',
|
|
592
|
+
applicationId: 'anyApplicationId',
|
|
593
|
+
directoryHashes: ['anyDirectoryHash'],
|
|
594
|
+
accessToken: anyAccessToken
|
|
595
|
+
})
|
|
596
|
+
).rejects.toThrow();
|
|
597
|
+
});
|
|
598
|
+
|
|
599
|
+
test('raises error when application id is empty', async () => {
|
|
600
|
+
const sabs = new SabsClient('http://localhost:3000');
|
|
601
|
+
await expect(
|
|
602
|
+
sabs.bulkStatus({
|
|
603
|
+
organizationId: 'anyOrganizationId',
|
|
604
|
+
applicationId: '',
|
|
605
|
+
directoryHashes: ['anyDirectoryHash'],
|
|
606
|
+
accessToken: anyAccessToken
|
|
607
|
+
})
|
|
608
|
+
).rejects.toThrow();
|
|
609
|
+
});
|
|
610
|
+
|
|
611
|
+
test('raises error when directory hashes is empty', async () => {
|
|
612
|
+
const sabs = new SabsClient('http://localhost:3000');
|
|
613
|
+
await expect(
|
|
614
|
+
sabs.bulkStatus({
|
|
615
|
+
organizationId: 'anyOrganizationId',
|
|
616
|
+
applicationId: 'anyApplicationId',
|
|
617
|
+
directoryHashes: [],
|
|
618
|
+
accessToken: anyAccessToken
|
|
619
|
+
})
|
|
620
|
+
).rejects.toThrow();
|
|
621
|
+
});
|
|
388
622
|
});
|
|
389
623
|
|
|
390
624
|
describe('liveEdit', () => {
|
|
@@ -392,6 +626,58 @@ describe('sabs service', () => {
|
|
|
392
626
|
const organizationId = 'anyOrganizationId';
|
|
393
627
|
const branch = 'anyBranch';
|
|
394
628
|
|
|
629
|
+
test('raises error when application id is empty', async () => {
|
|
630
|
+
const sabs = new SabsClient('http://localhost:3000');
|
|
631
|
+
await expect(
|
|
632
|
+
sabs.createLiveEdit({
|
|
633
|
+
applicationId: '',
|
|
634
|
+
organizationId: 'anyOrganizationId',
|
|
635
|
+
branch: 'anyBranch',
|
|
636
|
+
expiresIn: 1000,
|
|
637
|
+
accessToken: anyAccessToken
|
|
638
|
+
})
|
|
639
|
+
).rejects.toThrow();
|
|
640
|
+
});
|
|
641
|
+
|
|
642
|
+
test('raises error when organization id is empty', async () => {
|
|
643
|
+
const sabs = new SabsClient('http://localhost:3000');
|
|
644
|
+
await expect(
|
|
645
|
+
sabs.createLiveEdit({
|
|
646
|
+
applicationId: 'anyApplicationId',
|
|
647
|
+
organizationId: '',
|
|
648
|
+
branch: 'anyBranch',
|
|
649
|
+
expiresIn: 1000,
|
|
650
|
+
accessToken: anyAccessToken
|
|
651
|
+
})
|
|
652
|
+
).rejects.toThrow();
|
|
653
|
+
});
|
|
654
|
+
|
|
655
|
+
test('raises error when branch is empty', async () => {
|
|
656
|
+
const sabs = new SabsClient('http://localhost:3000');
|
|
657
|
+
await expect(
|
|
658
|
+
sabs.createLiveEdit({
|
|
659
|
+
applicationId: 'anyApplicationId',
|
|
660
|
+
organizationId: 'anyOrganizationId',
|
|
661
|
+
branch: '',
|
|
662
|
+
expiresIn: 1000,
|
|
663
|
+
accessToken: anyAccessToken
|
|
664
|
+
})
|
|
665
|
+
).rejects.toThrow();
|
|
666
|
+
});
|
|
667
|
+
|
|
668
|
+
test('raises error when access token is empty', async () => {
|
|
669
|
+
const sabs = new SabsClient('http://localhost:3000');
|
|
670
|
+
await expect(
|
|
671
|
+
sabs.createLiveEdit({
|
|
672
|
+
applicationId: 'anyApplicationId',
|
|
673
|
+
organizationId: 'anyOrganizationId',
|
|
674
|
+
branch: 'anyBranch',
|
|
675
|
+
expiresIn: 1000,
|
|
676
|
+
accessToken: ''
|
|
677
|
+
})
|
|
678
|
+
).rejects.toThrow();
|
|
679
|
+
});
|
|
680
|
+
|
|
395
681
|
test('createLiveEdit', async () => {
|
|
396
682
|
const mockAxios = jest.spyOn(axios, 'request');
|
|
397
683
|
const expiresInSeconds = 1000;
|
|
@@ -472,6 +758,16 @@ describe('sabs service', () => {
|
|
|
472
758
|
});
|
|
473
759
|
});
|
|
474
760
|
|
|
761
|
+
test('raises error when live edit id is empty', async () => {
|
|
762
|
+
const sabs = new SabsClient('http://localhost:3000');
|
|
763
|
+
await expect(sabs.terminateLiveEdit({ liveEditId: '', accessToken: anyAccessToken })).rejects.toThrow();
|
|
764
|
+
});
|
|
765
|
+
|
|
766
|
+
test('raises error when access token is empty', async () => {
|
|
767
|
+
const sabs = new SabsClient('http://localhost:3000');
|
|
768
|
+
await expect(sabs.terminateLiveEdit({ liveEditId: 'liveEditId', accessToken: '' })).rejects.toThrow();
|
|
769
|
+
});
|
|
770
|
+
|
|
475
771
|
test('terminateLiveEdit raises error when request fails', async () => {
|
|
476
772
|
const mockAxios = jest.spyOn(axios, 'request');
|
|
477
773
|
mockAxios.mockRejectedValue(new Error('any error'));
|
|
@@ -514,7 +810,7 @@ describe('sabs service', () => {
|
|
|
514
810
|
const expectedError = 'sabs service request failed: request failed\n[500] internal server error: "failed to process request"';
|
|
515
811
|
|
|
516
812
|
const sabs = new SabsClient('http://localhost:3000');
|
|
517
|
-
await expect(sabs.status({ buildId: anyBuildId })).rejects.toThrow(expectedError);
|
|
813
|
+
await expect(sabs.status({ buildId: anyBuildId, accessToken: anyAccessToken })).rejects.toThrow(expectedError);
|
|
518
814
|
});
|
|
519
815
|
|
|
520
816
|
test('re-raises error when error is not axios error', async () => {
|
|
@@ -526,7 +822,7 @@ describe('sabs service', () => {
|
|
|
526
822
|
const expectedError = 'sabs service request failed: unexpected error';
|
|
527
823
|
|
|
528
824
|
const sabs = new SabsClient('http://localhost:3000');
|
|
529
|
-
await expect(sabs.status({ buildId: anyBuildId })).rejects.toThrow(expectedError);
|
|
825
|
+
await expect(sabs.status({ buildId: anyBuildId, accessToken: anyAccessToken })).rejects.toThrow(expectedError);
|
|
530
826
|
});
|
|
531
827
|
});
|
|
532
828
|
});
|