@pwrdrvr/microapps-router-lib 0.4.0-alpha.9 → 1.0.2
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/get-app-info.d.ts +9 -0
- package/dist/get-app-info.d.ts.map +1 -0
- package/dist/get-app-info.js +25 -0
- package/dist/get-app-info.js.map +1 -0
- package/dist/get-route.d.ts +83 -0
- package/dist/get-route.d.ts.map +1 -0
- package/dist/get-route.js +171 -0
- package/dist/get-route.js.map +1 -0
- package/dist/index.d.ts +5 -96
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +11 -372
- package/dist/index.js.map +1 -1
- package/dist/load-app-frame.d.ts +8 -0
- package/dist/load-app-frame.d.ts.map +1 -0
- package/dist/load-app-frame.js +38 -0
- package/dist/load-app-frame.js.map +1 -0
- package/dist/normalize-path-prefix.d.ts +8 -0
- package/dist/normalize-path-prefix.d.ts.map +1 -0
- package/dist/normalize-path-prefix.js +21 -0
- package/dist/normalize-path-prefix.js.map +1 -0
- package/dist/redirect-default-file.d.ts +18 -0
- package/dist/redirect-default-file.d.ts.map +1 -0
- package/dist/redirect-default-file.js +54 -0
- package/dist/redirect-default-file.js.map +1 -0
- package/dist/route-app.d.ts +23 -0
- package/dist/route-app.d.ts.map +1 -0
- package/dist/route-app.js +169 -0
- package/dist/route-app.js.map +1 -0
- package/package.json +5 -3
- package/src/get-app-info.spec.ts +77 -0
- package/src/get-app-info.ts +31 -0
- package/src/get-route.spec.ts +585 -0
- package/src/get-route.ts +282 -0
- package/src/index.ts +5 -537
- package/src/load-app-frame.spec.ts +51 -0
- package/src/load-app-frame.ts +36 -0
- package/src/normalize-path-prefix.spec.ts +27 -0
- package/src/normalize-path-prefix.ts +18 -0
- package/src/redirect-default-file.spec.ts +98 -0
- package/src/redirect-default-file.ts +79 -0
- package/src/route-app.spec.ts +128 -0
- package/src/route-app.ts +202 -0
- package/src/index.spec.ts +0 -322
- /package/src/{index.prefix.spec.ts → get-route.prefix.spec.ts} +0 -0
|
@@ -0,0 +1,585 @@
|
|
|
1
|
+
/// <reference types="jest" />
|
|
2
|
+
import 'jest-dynalite/withDb';
|
|
3
|
+
import * as dynamodb from '@aws-sdk/client-dynamodb';
|
|
4
|
+
import { Application, DBManager, Version, Rules } from '@pwrdrvr/microapps-datalib';
|
|
5
|
+
import { GetRoute } from './index';
|
|
6
|
+
|
|
7
|
+
let dynamoClient: dynamodb.DynamoDBClient;
|
|
8
|
+
let dbManager: DBManager;
|
|
9
|
+
|
|
10
|
+
const TEST_TABLE_NAME = 'microapps';
|
|
11
|
+
|
|
12
|
+
describe('router - without prefix', () => {
|
|
13
|
+
beforeAll(() => {
|
|
14
|
+
dynamoClient = new dynamodb.DynamoDBClient({
|
|
15
|
+
endpoint: process.env.MOCK_DYNAMODB_ENDPOINT,
|
|
16
|
+
tls: false,
|
|
17
|
+
region: 'local',
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
// Init the DB manager to point it at the right table
|
|
21
|
+
dbManager = new DBManager({ dynamoClient, tableName: TEST_TABLE_NAME });
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
describe('StartupType: iframe', () => {
|
|
25
|
+
it('should serve appframe with version and default file substitued', async () => {
|
|
26
|
+
const app = new Application({
|
|
27
|
+
AppName: 'Bat',
|
|
28
|
+
DisplayName: 'Bat App',
|
|
29
|
+
});
|
|
30
|
+
await app.Save(dbManager);
|
|
31
|
+
|
|
32
|
+
const version = new Version({
|
|
33
|
+
AppName: 'Bat',
|
|
34
|
+
DefaultFile: 'bat.html',
|
|
35
|
+
IntegrationID: 'abcd',
|
|
36
|
+
SemVer: '3.2.1-beta.1',
|
|
37
|
+
Status: 'deployed',
|
|
38
|
+
Type: 'lambda',
|
|
39
|
+
});
|
|
40
|
+
await version.Save(dbManager);
|
|
41
|
+
|
|
42
|
+
const rules = new Rules({
|
|
43
|
+
AppName: 'Bat',
|
|
44
|
+
Version: 0,
|
|
45
|
+
RuleSet: { default: { SemVer: '3.2.1-beta.1', AttributeName: '', AttributeValue: '' } },
|
|
46
|
+
});
|
|
47
|
+
await rules.Save(dbManager);
|
|
48
|
+
|
|
49
|
+
// Call the handler
|
|
50
|
+
const response = await GetRoute({
|
|
51
|
+
dbManager,
|
|
52
|
+
rawPath: '/bat/',
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
expect(response).toHaveProperty('statusCode');
|
|
56
|
+
expect(response.statusCode).toBe(200);
|
|
57
|
+
expect(response).toBeDefined();
|
|
58
|
+
expect(response.iFrameAppVersionPath).toBe('/bat/3.2.1-beta.1/bat.html');
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
it('should serve appframe with appver query string and default file substitued', async () => {
|
|
62
|
+
const AppName = 'BatAppVer';
|
|
63
|
+
const app = new Application({
|
|
64
|
+
AppName,
|
|
65
|
+
DisplayName: 'Bat App',
|
|
66
|
+
});
|
|
67
|
+
await app.Save(dbManager);
|
|
68
|
+
|
|
69
|
+
const version = new Version({
|
|
70
|
+
AppName,
|
|
71
|
+
DefaultFile: 'bat.html',
|
|
72
|
+
IntegrationID: 'abcd',
|
|
73
|
+
SemVer: '3.2.1-beta.1',
|
|
74
|
+
Status: 'deployed',
|
|
75
|
+
Type: 'lambda',
|
|
76
|
+
});
|
|
77
|
+
await version.Save(dbManager);
|
|
78
|
+
const version2 = new Version({
|
|
79
|
+
AppName,
|
|
80
|
+
DefaultFile: 'bat.html',
|
|
81
|
+
IntegrationID: 'abcd',
|
|
82
|
+
SemVer: '3.2.1-beta.2',
|
|
83
|
+
Status: 'deployed',
|
|
84
|
+
Type: 'lambda',
|
|
85
|
+
});
|
|
86
|
+
await version2.Save(dbManager);
|
|
87
|
+
|
|
88
|
+
const rules = new Rules({
|
|
89
|
+
AppName,
|
|
90
|
+
Version: 0,
|
|
91
|
+
RuleSet: { default: { SemVer: '3.2.1-beta.1', AttributeName: '', AttributeValue: '' } },
|
|
92
|
+
});
|
|
93
|
+
await rules.Save(dbManager);
|
|
94
|
+
|
|
95
|
+
// Call the handler
|
|
96
|
+
const response = await GetRoute({
|
|
97
|
+
dbManager,
|
|
98
|
+
rawPath: '/batappver/',
|
|
99
|
+
queryStringParameters: new URLSearchParams('appver=3.2.1-beta.2'),
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
expect(response).toHaveProperty('statusCode');
|
|
103
|
+
expect(response.statusCode).toBe(200);
|
|
104
|
+
expect(response).toBeDefined();
|
|
105
|
+
expect(response.iFrameAppVersionPath).toBe('/batappver/3.2.1-beta.2/bat.html');
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
it('static app - request to app/x.y.z should redirect to defaultFile', async () => {
|
|
109
|
+
const app = new Application({
|
|
110
|
+
AppName: 'Bat',
|
|
111
|
+
DisplayName: 'Bat App',
|
|
112
|
+
});
|
|
113
|
+
await app.Save(dbManager);
|
|
114
|
+
|
|
115
|
+
const version = new Version({
|
|
116
|
+
AppName: 'Bat',
|
|
117
|
+
DefaultFile: 'bat.html',
|
|
118
|
+
IntegrationID: 'abcd',
|
|
119
|
+
SemVer: '3.2.1-beta.1',
|
|
120
|
+
Status: 'deployed',
|
|
121
|
+
Type: 'static',
|
|
122
|
+
StartupType: 'iframe',
|
|
123
|
+
});
|
|
124
|
+
await version.Save(dbManager);
|
|
125
|
+
|
|
126
|
+
const rules = new Rules({
|
|
127
|
+
AppName: 'Bat',
|
|
128
|
+
Version: 0,
|
|
129
|
+
RuleSet: { default: { SemVer: '3.2.1-beta.1', AttributeName: '', AttributeValue: '' } },
|
|
130
|
+
});
|
|
131
|
+
await rules.Save(dbManager);
|
|
132
|
+
|
|
133
|
+
// Call the handler
|
|
134
|
+
const response = await GetRoute({ dbManager, rawPath: '/bat/3.2.1-beta.1' });
|
|
135
|
+
|
|
136
|
+
expect(response).toHaveProperty('statusCode');
|
|
137
|
+
expect(response.statusCode).toBe(302);
|
|
138
|
+
expect(response.redirectLocation).toBeDefined();
|
|
139
|
+
expect(response.redirectLocation).toBe('/bat/3.2.1-beta.1/bat.html');
|
|
140
|
+
}, 60000);
|
|
141
|
+
|
|
142
|
+
it('static app - request to app/x.y.z/ should not redirect if no defaultFile', async () => {
|
|
143
|
+
const app = new Application({
|
|
144
|
+
AppName: 'Bat',
|
|
145
|
+
DisplayName: 'Bat App',
|
|
146
|
+
});
|
|
147
|
+
await app.Save(dbManager);
|
|
148
|
+
|
|
149
|
+
const version = new Version({
|
|
150
|
+
AppName: 'Bat',
|
|
151
|
+
IntegrationID: 'abcd',
|
|
152
|
+
SemVer: '3.2.1-beta.2',
|
|
153
|
+
Status: 'deployed',
|
|
154
|
+
Type: 'static',
|
|
155
|
+
StartupType: 'iframe',
|
|
156
|
+
});
|
|
157
|
+
await version.Save(dbManager);
|
|
158
|
+
|
|
159
|
+
const rules = new Rules({
|
|
160
|
+
AppName: 'Bat',
|
|
161
|
+
Version: 0,
|
|
162
|
+
RuleSet: { default: { SemVer: '3.2.1-beta.2', AttributeName: '', AttributeValue: '' } },
|
|
163
|
+
});
|
|
164
|
+
await rules.Save(dbManager);
|
|
165
|
+
|
|
166
|
+
// Call the handler
|
|
167
|
+
const response = await GetRoute({ dbManager, rawPath: '/bat/3.2.1-beta.2/' });
|
|
168
|
+
|
|
169
|
+
expect(response).toHaveProperty('appName');
|
|
170
|
+
expect(response.appName).toBe('bat');
|
|
171
|
+
expect(response).toHaveProperty('semVer');
|
|
172
|
+
expect(response.semVer).toBe('3.2.1-beta.2');
|
|
173
|
+
});
|
|
174
|
+
|
|
175
|
+
it('static app - request to app/some.html should create iframe with path after version', async () => {
|
|
176
|
+
const app = new Application({
|
|
177
|
+
AppName: 'Bat',
|
|
178
|
+
DisplayName: 'Bat App',
|
|
179
|
+
});
|
|
180
|
+
await app.Save(dbManager);
|
|
181
|
+
|
|
182
|
+
const version = new Version({
|
|
183
|
+
AppName: 'Bat',
|
|
184
|
+
DefaultFile: 'bat.html',
|
|
185
|
+
IntegrationID: 'abcd',
|
|
186
|
+
SemVer: '3.2.1-beta.1',
|
|
187
|
+
Status: 'deployed',
|
|
188
|
+
Type: 'static',
|
|
189
|
+
StartupType: 'iframe',
|
|
190
|
+
});
|
|
191
|
+
await version.Save(dbManager);
|
|
192
|
+
|
|
193
|
+
const rules = new Rules({
|
|
194
|
+
AppName: 'Bat',
|
|
195
|
+
Version: 0,
|
|
196
|
+
RuleSet: { default: { SemVer: '3.2.1-beta.1', AttributeName: '', AttributeValue: '' } },
|
|
197
|
+
});
|
|
198
|
+
await rules.Save(dbManager);
|
|
199
|
+
|
|
200
|
+
// Call the handler
|
|
201
|
+
const response = await GetRoute({ dbManager, rawPath: '/bat/some.html' });
|
|
202
|
+
|
|
203
|
+
expect(response).toHaveProperty('statusCode');
|
|
204
|
+
expect(response.statusCode).toBe(200);
|
|
205
|
+
expect(response.redirectLocation).not.toBeDefined();
|
|
206
|
+
expect(response.iFrameAppVersionPath).toBe('/bat/3.2.1-beta.1/some.html');
|
|
207
|
+
});
|
|
208
|
+
|
|
209
|
+
it('static app - request to app/x.y.z/ should redirect to defaultFile', async () => {
|
|
210
|
+
const app = new Application({
|
|
211
|
+
AppName: 'Bat',
|
|
212
|
+
DisplayName: 'Bat App',
|
|
213
|
+
});
|
|
214
|
+
await app.Save(dbManager);
|
|
215
|
+
|
|
216
|
+
const version = new Version({
|
|
217
|
+
AppName: 'Bat',
|
|
218
|
+
DefaultFile: 'bat.html',
|
|
219
|
+
IntegrationID: 'abcd',
|
|
220
|
+
SemVer: '3.2.1-beta.1',
|
|
221
|
+
Status: 'deployed',
|
|
222
|
+
Type: 'static',
|
|
223
|
+
StartupType: 'iframe',
|
|
224
|
+
});
|
|
225
|
+
await version.Save(dbManager);
|
|
226
|
+
|
|
227
|
+
const rules = new Rules({
|
|
228
|
+
AppName: 'Bat',
|
|
229
|
+
Version: 0,
|
|
230
|
+
RuleSet: { default: { SemVer: '3.2.1-beta.1', AttributeName: '', AttributeValue: '' } },
|
|
231
|
+
});
|
|
232
|
+
await rules.Save(dbManager);
|
|
233
|
+
|
|
234
|
+
// Call the handler
|
|
235
|
+
const response = await GetRoute({ dbManager, rawPath: '/bat/3.2.1-beta.1/' });
|
|
236
|
+
|
|
237
|
+
expect(response).toHaveProperty('statusCode');
|
|
238
|
+
expect(response.statusCode).toBe(302);
|
|
239
|
+
expect(response.redirectLocation).toBeDefined();
|
|
240
|
+
expect(response.redirectLocation).toBe('/bat/3.2.1-beta.1/bat.html');
|
|
241
|
+
});
|
|
242
|
+
|
|
243
|
+
it('static app - request to app/notVersion should load app frame with /notVersion suffix', async () => {
|
|
244
|
+
const AppName = 'Bat123';
|
|
245
|
+
const app = new Application({
|
|
246
|
+
AppName,
|
|
247
|
+
DisplayName: 'Bat App',
|
|
248
|
+
});
|
|
249
|
+
await app.Save(dbManager);
|
|
250
|
+
|
|
251
|
+
const version = new Version({
|
|
252
|
+
AppName,
|
|
253
|
+
DefaultFile: 'bat.html',
|
|
254
|
+
IntegrationID: 'abcd',
|
|
255
|
+
SemVer: '3.2.1-beta.1',
|
|
256
|
+
Status: 'deployed',
|
|
257
|
+
Type: 'static',
|
|
258
|
+
StartupType: 'iframe',
|
|
259
|
+
});
|
|
260
|
+
await version.Save(dbManager);
|
|
261
|
+
|
|
262
|
+
const rules = new Rules({
|
|
263
|
+
AppName,
|
|
264
|
+
Version: 0,
|
|
265
|
+
RuleSet: { default: { SemVer: '3.2.1-beta.1', AttributeName: '', AttributeValue: '' } },
|
|
266
|
+
});
|
|
267
|
+
await rules.Save(dbManager);
|
|
268
|
+
|
|
269
|
+
// Call the handler
|
|
270
|
+
const response = await GetRoute({ dbManager, rawPath: `/${AppName}/notVersion` });
|
|
271
|
+
|
|
272
|
+
expect(response).toHaveProperty('statusCode');
|
|
273
|
+
expect(response.statusCode).toBe(200);
|
|
274
|
+
expect(response).toBeDefined();
|
|
275
|
+
expect(response.iFrameAppVersionPath).toBe(`/${AppName}/3.2.1-beta.1/notVersion`);
|
|
276
|
+
});
|
|
277
|
+
|
|
278
|
+
it('should serve appframe with no default file', async () => {
|
|
279
|
+
const AppName = 'Bat124';
|
|
280
|
+
const app = new Application({
|
|
281
|
+
AppName,
|
|
282
|
+
DisplayName: 'Bat App',
|
|
283
|
+
});
|
|
284
|
+
await app.Save(dbManager);
|
|
285
|
+
|
|
286
|
+
const version = new Version({
|
|
287
|
+
AppName,
|
|
288
|
+
DefaultFile: '',
|
|
289
|
+
IntegrationID: 'abcd',
|
|
290
|
+
SemVer: '3.2.1-beta1',
|
|
291
|
+
Status: 'deployed',
|
|
292
|
+
Type: 'lambda',
|
|
293
|
+
StartupType: 'iframe',
|
|
294
|
+
});
|
|
295
|
+
await version.Save(dbManager);
|
|
296
|
+
|
|
297
|
+
const rules = new Rules({
|
|
298
|
+
AppName,
|
|
299
|
+
Version: 0,
|
|
300
|
+
RuleSet: { default: { SemVer: '3.2.1-beta1', AttributeName: '', AttributeValue: '' } },
|
|
301
|
+
});
|
|
302
|
+
await rules.Save(dbManager);
|
|
303
|
+
|
|
304
|
+
// Call the handler
|
|
305
|
+
const response = await GetRoute({ dbManager, rawPath: `/${AppName}/` });
|
|
306
|
+
|
|
307
|
+
expect(response).toBeDefined();
|
|
308
|
+
expect(response).toHaveProperty('statusCode');
|
|
309
|
+
expect(response.statusCode).toBe(200);
|
|
310
|
+
expect(response.iFrameAppVersionPath).toBe(`/${AppName}/3.2.1-beta1`);
|
|
311
|
+
});
|
|
312
|
+
|
|
313
|
+
it('should serve appframe with sub-route', async () => {
|
|
314
|
+
const AppName = 'Bat125';
|
|
315
|
+
const app = new Application({
|
|
316
|
+
AppName,
|
|
317
|
+
DisplayName: 'Bat App',
|
|
318
|
+
});
|
|
319
|
+
await app.Save(dbManager);
|
|
320
|
+
|
|
321
|
+
const version = new Version({
|
|
322
|
+
AppName,
|
|
323
|
+
DefaultFile: '',
|
|
324
|
+
IntegrationID: 'abcd',
|
|
325
|
+
SemVer: '3.2.1-beta2',
|
|
326
|
+
Status: 'deployed',
|
|
327
|
+
Type: 'lambda',
|
|
328
|
+
StartupType: 'iframe',
|
|
329
|
+
});
|
|
330
|
+
await version.Save(dbManager);
|
|
331
|
+
|
|
332
|
+
const rules = new Rules({
|
|
333
|
+
AppName,
|
|
334
|
+
Version: 0,
|
|
335
|
+
RuleSet: { default: { SemVer: '3.2.1-beta2', AttributeName: '', AttributeValue: '' } },
|
|
336
|
+
});
|
|
337
|
+
await rules.Save(dbManager);
|
|
338
|
+
|
|
339
|
+
// Call the handler
|
|
340
|
+
const response = await GetRoute({ dbManager, rawPath: `/${AppName}/demo/grid` });
|
|
341
|
+
|
|
342
|
+
expect(response).toBeDefined();
|
|
343
|
+
expect(response).toHaveProperty('statusCode');
|
|
344
|
+
expect(response.statusCode).toBe(200);
|
|
345
|
+
expect(response.iFrameAppVersionPath).toBe(`/${AppName}/3.2.1-beta2/demo/grid`);
|
|
346
|
+
});
|
|
347
|
+
|
|
348
|
+
it('should serve appframe with sub-route', async () => {
|
|
349
|
+
const AppName = 'Bat126';
|
|
350
|
+
const app = new Application({
|
|
351
|
+
AppName,
|
|
352
|
+
DisplayName: 'Bat App',
|
|
353
|
+
});
|
|
354
|
+
await app.Save(dbManager);
|
|
355
|
+
|
|
356
|
+
const version = new Version({
|
|
357
|
+
AppName,
|
|
358
|
+
DefaultFile: 'someFile.html',
|
|
359
|
+
IntegrationID: 'abcd',
|
|
360
|
+
SemVer: '3.2.1-beta3',
|
|
361
|
+
Status: 'deployed',
|
|
362
|
+
Type: 'lambda',
|
|
363
|
+
StartupType: 'iframe',
|
|
364
|
+
});
|
|
365
|
+
await version.Save(dbManager);
|
|
366
|
+
|
|
367
|
+
const rules = new Rules({
|
|
368
|
+
AppName,
|
|
369
|
+
Version: 0,
|
|
370
|
+
RuleSet: { default: { SemVer: '3.2.1-beta3', AttributeName: '', AttributeValue: '' } },
|
|
371
|
+
});
|
|
372
|
+
await rules.Save(dbManager);
|
|
373
|
+
|
|
374
|
+
// Call the handler
|
|
375
|
+
const response = await GetRoute({ dbManager, rawPath: `/${AppName}/demo` });
|
|
376
|
+
|
|
377
|
+
expect(response).toBeDefined();
|
|
378
|
+
expect(response).toHaveProperty('statusCode');
|
|
379
|
+
expect(response.statusCode).toBe(200);
|
|
380
|
+
expect(response.iFrameAppVersionPath).toBe(`/${AppName}/3.2.1-beta3/demo`);
|
|
381
|
+
});
|
|
382
|
+
|
|
383
|
+
it('should return 404 for /favicon.ico', async () => {
|
|
384
|
+
const app = new Application({
|
|
385
|
+
AppName: 'Bat',
|
|
386
|
+
DisplayName: 'Bat App',
|
|
387
|
+
});
|
|
388
|
+
await app.Save(dbManager);
|
|
389
|
+
|
|
390
|
+
const version = new Version({
|
|
391
|
+
AppName: 'Bat',
|
|
392
|
+
DefaultFile: 'someFile.html',
|
|
393
|
+
IntegrationID: 'abcd',
|
|
394
|
+
SemVer: '3.2.1-beta3',
|
|
395
|
+
Status: 'deployed',
|
|
396
|
+
Type: 'lambda',
|
|
397
|
+
StartupType: 'iframe',
|
|
398
|
+
});
|
|
399
|
+
await version.Save(dbManager);
|
|
400
|
+
|
|
401
|
+
const rules = new Rules({
|
|
402
|
+
AppName: 'Bat',
|
|
403
|
+
Version: 0,
|
|
404
|
+
RuleSet: { default: { SemVer: '3.2.1-beta3', AttributeName: '', AttributeValue: '' } },
|
|
405
|
+
});
|
|
406
|
+
await rules.Save(dbManager);
|
|
407
|
+
|
|
408
|
+
// Call the handler
|
|
409
|
+
const response = await GetRoute({ dbManager, rawPath: '/favicon.ico' });
|
|
410
|
+
|
|
411
|
+
expect(response).toBeDefined();
|
|
412
|
+
expect(response).toHaveProperty('statusCode');
|
|
413
|
+
expect(response.statusCode).toBe(404);
|
|
414
|
+
});
|
|
415
|
+
});
|
|
416
|
+
|
|
417
|
+
describe('StartupType: direct', () => {
|
|
418
|
+
it('should serve direct app with sub-route', async () => {
|
|
419
|
+
const AppName = 'DirectBat126';
|
|
420
|
+
const app = new Application({
|
|
421
|
+
AppName,
|
|
422
|
+
DisplayName: 'Bat App',
|
|
423
|
+
});
|
|
424
|
+
await app.Save(dbManager);
|
|
425
|
+
|
|
426
|
+
const version = new Version({
|
|
427
|
+
AppName,
|
|
428
|
+
DefaultFile: 'someFile.html',
|
|
429
|
+
IntegrationID: 'abcd',
|
|
430
|
+
SemVer: '3.2.1-beta3',
|
|
431
|
+
Status: 'deployed',
|
|
432
|
+
Type: 'lambda-url',
|
|
433
|
+
StartupType: 'direct',
|
|
434
|
+
URL: 'https://abc123.lambda-url.us-east-1.on.aws',
|
|
435
|
+
LambdaARN: 'arn:aws:lambda:us-east-1:123456789012:function:my-function',
|
|
436
|
+
});
|
|
437
|
+
await version.Save(dbManager);
|
|
438
|
+
|
|
439
|
+
const rules = new Rules({
|
|
440
|
+
AppName,
|
|
441
|
+
Version: 0,
|
|
442
|
+
RuleSet: { default: { SemVer: '3.2.1-beta3', AttributeName: '', AttributeValue: '' } },
|
|
443
|
+
});
|
|
444
|
+
await rules.Save(dbManager);
|
|
445
|
+
|
|
446
|
+
// Call the handler
|
|
447
|
+
const response = await GetRoute({ dbManager, rawPath: `/${AppName}/demo` });
|
|
448
|
+
|
|
449
|
+
expect(response).toBeDefined();
|
|
450
|
+
expect(response).toHaveProperty('statusCode');
|
|
451
|
+
expect(response.statusCode).toBe(200);
|
|
452
|
+
expect(response.appName).toBe(AppName);
|
|
453
|
+
expect(response.semVer).toBe('3.2.1-beta3');
|
|
454
|
+
expect(response.url).toBe('https://abc123.lambda-url.us-east-1.on.aws');
|
|
455
|
+
});
|
|
456
|
+
|
|
457
|
+
describe('/_next/data/ no-basePath', () => {
|
|
458
|
+
const testCases = [
|
|
459
|
+
{
|
|
460
|
+
AppName: 'DirectBatNextData',
|
|
461
|
+
SemVer: '3.2.1-beta3',
|
|
462
|
+
Locales: ['en'],
|
|
463
|
+
LambdaFunctionURL: 'https://abc123.lambda-url.us-east-1.on.aws',
|
|
464
|
+
RawPath: '/_next/data/3.2.1-beta3/directbatnextdata/demo.json',
|
|
465
|
+
},
|
|
466
|
+
{
|
|
467
|
+
AppName: 'AnotherAppName',
|
|
468
|
+
SemVer: '1.0.0',
|
|
469
|
+
Locales: ['en'],
|
|
470
|
+
LambdaFunctionURL: 'https://abc124.lambda-url.us-east-1.on.aws',
|
|
471
|
+
RawPath: '/_next/data/1.0.0/anotherappname.json',
|
|
472
|
+
},
|
|
473
|
+
{
|
|
474
|
+
AppName: 'AppWithLocales',
|
|
475
|
+
SemVer: '1.0.0',
|
|
476
|
+
Locales: ['en', 'sv'],
|
|
477
|
+
LambdaFunctionURL: 'https://abc125.lambda-url.us-east-1.on.aws',
|
|
478
|
+
RawPath: '/_next/data/1.0.0/sv/appwithlocales.json',
|
|
479
|
+
},
|
|
480
|
+
{
|
|
481
|
+
AppName: 'ComplicatedLocales',
|
|
482
|
+
SemVer: '1.0.0',
|
|
483
|
+
Locales: ['en', 'en-US', 'sv', 'zh-Hant'],
|
|
484
|
+
LambdaFunctionURL: 'https://abc125.lambda-url.us-east-1.on.aws',
|
|
485
|
+
RawPath: '/_next/data/1.0.0/en-US/complicatedlocales.json',
|
|
486
|
+
},
|
|
487
|
+
{
|
|
488
|
+
AppName: 'ComplicatedLocales',
|
|
489
|
+
SemVer: '1.0.0',
|
|
490
|
+
Locales: ['en', 'en-US', 'sv', 'zh-Hant'],
|
|
491
|
+
LambdaFunctionURL: 'https://abc125.lambda-url.us-east-1.on.aws',
|
|
492
|
+
RawPath: '/_next/data/1.0.0/en-US/complicatedlocales/index.json',
|
|
493
|
+
},
|
|
494
|
+
// Add more test cases as needed
|
|
495
|
+
];
|
|
496
|
+
|
|
497
|
+
it.each(testCases)(
|
|
498
|
+
'should serve direct app with $RawPath route',
|
|
499
|
+
async ({ AppName, SemVer, LambdaFunctionURL, Locales = [], RawPath }) => {
|
|
500
|
+
const app = new Application({
|
|
501
|
+
AppName,
|
|
502
|
+
DisplayName: 'Bat App',
|
|
503
|
+
});
|
|
504
|
+
await app.Save(dbManager);
|
|
505
|
+
|
|
506
|
+
const version = new Version({
|
|
507
|
+
AppName,
|
|
508
|
+
DefaultFile: 'someFile.html',
|
|
509
|
+
IntegrationID: 'abcd',
|
|
510
|
+
SemVer,
|
|
511
|
+
Status: 'deployed',
|
|
512
|
+
Type: 'lambda-url',
|
|
513
|
+
StartupType: 'direct',
|
|
514
|
+
URL: LambdaFunctionURL,
|
|
515
|
+
LambdaARN: 'arn:aws:lambda:us-east-1:123456789012:function:my-function',
|
|
516
|
+
});
|
|
517
|
+
await version.Save(dbManager);
|
|
518
|
+
|
|
519
|
+
const rules = new Rules({
|
|
520
|
+
AppName,
|
|
521
|
+
Version: 0,
|
|
522
|
+
RuleSet: { default: { SemVer, AttributeName: '', AttributeValue: '' } },
|
|
523
|
+
});
|
|
524
|
+
await rules.Save(dbManager);
|
|
525
|
+
|
|
526
|
+
// Call the handler
|
|
527
|
+
const response = await GetRoute({
|
|
528
|
+
dbManager,
|
|
529
|
+
locales: Locales,
|
|
530
|
+
rawPath: RawPath,
|
|
531
|
+
});
|
|
532
|
+
|
|
533
|
+
expect(response).toBeDefined();
|
|
534
|
+
expect(response).toHaveProperty('statusCode');
|
|
535
|
+
expect(response.appName).toBe(AppName.toLowerCase());
|
|
536
|
+
expect(response.semVer).toBe(SemVer);
|
|
537
|
+
expect(response.statusCode).toBe(200);
|
|
538
|
+
expect(response.url).toBe(LambdaFunctionURL);
|
|
539
|
+
},
|
|
540
|
+
);
|
|
541
|
+
});
|
|
542
|
+
|
|
543
|
+
it('should serve direct app with /_next/data/[semver]/[appname]/route route', async () => {
|
|
544
|
+
const AppName = 'DirectBatNextData';
|
|
545
|
+
const app = new Application({
|
|
546
|
+
AppName,
|
|
547
|
+
DisplayName: 'Bat App',
|
|
548
|
+
});
|
|
549
|
+
await app.Save(dbManager);
|
|
550
|
+
|
|
551
|
+
const version = new Version({
|
|
552
|
+
AppName,
|
|
553
|
+
DefaultFile: 'someFile.html',
|
|
554
|
+
IntegrationID: 'abcd',
|
|
555
|
+
SemVer: '3.2.1-beta3',
|
|
556
|
+
Status: 'deployed',
|
|
557
|
+
Type: 'lambda-url',
|
|
558
|
+
StartupType: 'direct',
|
|
559
|
+
URL: 'https://abc123.lambda-url.us-east-1.on.aws',
|
|
560
|
+
LambdaARN: 'arn:aws:lambda:us-east-1:123456789012:function:my-function',
|
|
561
|
+
});
|
|
562
|
+
await version.Save(dbManager);
|
|
563
|
+
|
|
564
|
+
const rules = new Rules({
|
|
565
|
+
AppName,
|
|
566
|
+
Version: 0,
|
|
567
|
+
RuleSet: { default: { SemVer: '3.2.1-beta3', AttributeName: '', AttributeValue: '' } },
|
|
568
|
+
});
|
|
569
|
+
await rules.Save(dbManager);
|
|
570
|
+
|
|
571
|
+
// Call the handler
|
|
572
|
+
const response = await GetRoute({
|
|
573
|
+
dbManager,
|
|
574
|
+
rawPath: `/_next/data/3.2.1-beta3/${AppName}/demo`,
|
|
575
|
+
});
|
|
576
|
+
|
|
577
|
+
expect(response).toBeDefined();
|
|
578
|
+
expect(response).toHaveProperty('statusCode');
|
|
579
|
+
expect(response.appName).toBe(AppName);
|
|
580
|
+
expect(response.semVer).toBe('3.2.1-beta3');
|
|
581
|
+
expect(response.statusCode).toBe(200);
|
|
582
|
+
expect(response.url).toBe('https://abc123.lambda-url.us-east-1.on.aws');
|
|
583
|
+
});
|
|
584
|
+
});
|
|
585
|
+
});
|