@appsemble/node-utils 0.30.14-test.6 → 0.32.1-test.15

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.
Files changed (89) hide show
  1. package/README.md +3 -3
  2. package/app.js +8 -0
  3. package/assets.d.ts +16 -0
  4. package/assets.js +65 -0
  5. package/authentication.d.ts +1 -1
  6. package/container/helpers.d.ts +1 -1
  7. package/container/helpers.js +1 -0
  8. package/container/logs.js +8 -5
  9. package/container/operations.js +22 -14
  10. package/container/scale.js +3 -2
  11. package/container/specs.js +1 -1
  12. package/fs.js +4 -0
  13. package/getAppsembleMessages.js +2 -0
  14. package/getMessagesUtil.js +5 -4
  15. package/getValidTrainings.d.ts +8 -0
  16. package/getValidTrainings.js +47 -0
  17. package/icon.js +5 -0
  18. package/index.d.ts +5 -1
  19. package/index.js +5 -1
  20. package/interceptors.js +1 -1
  21. package/koa.d.ts +13 -1
  22. package/koa.js +17 -1
  23. package/logger.js +5 -3
  24. package/middleware/loggerMiddleware.js +1 -0
  25. package/odata.js +2 -1
  26. package/package.json +22 -14
  27. package/parsers.d.ts +1 -0
  28. package/parsers.js +130 -0
  29. package/render.js +1 -1
  30. package/resource.d.ts +18 -3
  31. package/resource.js +50 -10
  32. package/s3.d.ts +18 -0
  33. package/s3.js +131 -0
  34. package/server/controllers/common/apps/assets/createGetAppAssetByIdController.js +4 -3
  35. package/server/controllers/common/apps/groups/createGetAppGroupsController.js +2 -2
  36. package/server/controllers/common/apps/messages/createGetAppMessagesController.js +2 -0
  37. package/server/controllers/common/apps/resources/createCreateAppResourceController.js +16 -2
  38. package/server/controllers/common/apps/resources/createDeleteAppResourceController.js +2 -2
  39. package/server/controllers/common/apps/resources/createGetAppResourceByIdController.js +3 -3
  40. package/server/controllers/common/apps/resources/createQueryAppResourcesController.js +1 -1
  41. package/server/controllers/common/apps/resources/createUpdateAppResourceController.js +6 -3
  42. package/server/controllers/common/apps/variables/createGetAppVariablesController.js +2 -2
  43. package/server/controllers/main/apps/assets/createCreateAppAssetController.js +4 -4
  44. package/server/controllers/main/apps/resources/createDeleteAppSeedResourcesController.js +2 -2
  45. package/server/routes/appRouter/blockAssetHandler.js +5 -3
  46. package/server/routes/appRouter/blockCssHandler.js +5 -3
  47. package/server/routes/appRouter/bulmaHandler.js +1 -0
  48. package/server/routes/appRouter/cssHandler.js +2 -2
  49. package/server/routes/appRouter/iconHandler.js +4 -1
  50. package/server/routes/appRouter/indexHandler.js +3 -1
  51. package/server/routes/appRouter/manifestHandler.js +2 -2
  52. package/server/routes/appRouter/readmeHandler.js +4 -3
  53. package/server/routes/appRouter/robotsHandler.js +2 -2
  54. package/server/routes/appRouter/screenshotHandler.js +4 -3
  55. package/server/routes/appRouter/serviceWorkerHandler.js +2 -2
  56. package/server/types.d.ts +22 -7
  57. package/server/types.js +7 -1
  58. package/server/utils/actions.js +16 -10
  59. package/server/utils/resources.js +4 -1
  60. package/tinyRouter.js +3 -3
  61. package/uploads.d.ts +2 -0
  62. package/uploads.js +27 -0
  63. package/versions.d.ts +3 -0
  64. package/versions.js +7 -0
  65. package/AppsembleError.test.d.ts +0 -1
  66. package/AppsembleError.test.js +0 -7
  67. package/basicAuth.test.d.ts +0 -1
  68. package/basicAuth.test.js +0 -7
  69. package/formData.test.d.ts +0 -1
  70. package/formData.test.js +0 -93
  71. package/fs.test.d.ts +0 -1
  72. package/fs.test.js +0 -75
  73. package/handleError.test.d.ts +0 -1
  74. package/handleError.test.js +0 -33
  75. package/interceptors.test.d.ts +0 -1
  76. package/interceptors.test.js +0 -83
  77. package/logger.test.d.ts +0 -1
  78. package/logger.test.js +0 -37
  79. package/middleware/error.test.d.ts +0 -1
  80. package/middleware/error.test.js +0 -59
  81. package/middleware/loggerMiddleware.test.d.ts +0 -1
  82. package/middleware/loggerMiddleware.test.js +0 -120
  83. package/readFileOrString.test.d.ts +0 -1
  84. package/readFileOrString.test.js +0 -12
  85. package/server/controllers/common/apps/resources/resources.test.d.ts +0 -1
  86. package/server/controllers/common/apps/resources/resources.test.js +0 -580
  87. package/tinyRouter.test.d.ts +0 -1
  88. package/tinyRouter.test.js +0 -83
  89. package/versions.cjs +0 -4
@@ -1,580 +0,0 @@
1
- import { defaultLocale, remap } from '@appsemble/utils';
2
- import { beforeEach, describe, expect, it, vi } from 'vitest';
3
- import { createCountAppResourcesController } from './createCountAppResourcesController.js';
4
- import { createCreateAppResourceController } from './createCreateAppResourceController.js';
5
- import { createGetAppResourceByIdController } from './createGetAppResourceByIdController.js';
6
- import { createQueryAppResourcesController } from './createQueryAppResourcesController.js';
7
- import { getRemapperContext } from '../../../../../app.js';
8
- import { getResourceDefinition } from '../../../../../resource.js';
9
- let mockGetApp;
10
- let mockGetAppResources;
11
- let mockGetAppResource;
12
- let mockParseQuery;
13
- let mockGetAppUrl;
14
- let mockGetAppMessages;
15
- let mockGetAppVariables;
16
- let mockCreateAppResourcesWithAssets;
17
- let mockGetAppAssets;
18
- let mockCheckAppPermissions;
19
- let mockGetCurrentAppMember;
20
- let mockCtx;
21
- let mockCtxIs;
22
- describe('createQueryResources', () => {
23
- beforeEach(() => {
24
- mockGetApp = vi.fn();
25
- mockGetAppResources = vi.fn();
26
- mockParseQuery = vi.fn();
27
- mockGetAppUrl = vi.fn();
28
- mockGetAppMessages = vi.fn();
29
- mockGetAppVariables = vi.fn();
30
- mockCheckAppPermissions = vi.fn();
31
- mockGetCurrentAppMember = vi.fn();
32
- mockCtx = {
33
- pathParams: { appId: 1, resourceType: 'mockResourceType' },
34
- queryParams: { $select: 'field1, field2', $skip: 0, $top: 10 },
35
- user: { id: 'mockUserId', name: 'John Doe', primaryEmail: 'john@example.com' },
36
- };
37
- });
38
- it('should fetch app and resources with correct parameters', async () => {
39
- const mockApp = {
40
- id: 1,
41
- definition: {
42
- resources: {
43
- mockResourceType: { id: 'id', schema: {} },
44
- },
45
- },
46
- };
47
- const mockResources = [{ id: 1 }, { id: 2 }];
48
- const mockParsedQuery = {
49
- order: [
50
- ['mockField1', 'mockOrderAsc'],
51
- ['mockField2', 'mockOrderDesc'],
52
- ],
53
- where: { mockField: 'mockValue' },
54
- };
55
- mockGetApp.mockResolvedValue(mockApp);
56
- mockGetAppResources.mockResolvedValue(mockResources);
57
- mockParseQuery.mockReturnValue(mockParsedQuery);
58
- const middleware = createQueryAppResourcesController({
59
- getApp: mockGetApp,
60
- getAppResources: mockGetAppResources,
61
- parseQuery: mockParseQuery,
62
- checkAppPermissions: mockCheckAppPermissions,
63
- });
64
- await middleware(mockCtx, vi.fn());
65
- expect(mockGetApp).toHaveBeenCalledWith(expect.objectContaining({
66
- context: expect.objectContaining({
67
- pathParams: expect.objectContaining({ appId: 1 }),
68
- }),
69
- query: expect.objectContaining({ where: { id: 1 } }),
70
- }));
71
- expect(mockGetAppResources).toHaveBeenCalledWith(expect.objectContaining({
72
- app: {
73
- definition: {
74
- resources: {
75
- mockResourceType: {
76
- id: 'id',
77
- schema: {},
78
- },
79
- },
80
- },
81
- id: 1,
82
- },
83
- context: expect.objectContaining({
84
- pathParams: expect.objectContaining({
85
- appId: 1,
86
- resourceType: 'mockResourceType',
87
- }),
88
- queryParams: expect.objectContaining({
89
- $select: 'field1, field2',
90
- $skip: 0,
91
- $top: 10,
92
- }),
93
- user: expect.objectContaining({
94
- id: 'mockUserId',
95
- name: 'John Doe',
96
- primaryEmail: 'john@example.com',
97
- }),
98
- }),
99
- findOptions: expect.objectContaining({
100
- attributes: ['field1', 'field2'],
101
- limit: 10,
102
- offset: 0,
103
- order: expect.arrayContaining([
104
- ['mockField1', 'mockOrderAsc'],
105
- ['mockField2', 'mockOrderDesc'],
106
- ]),
107
- where: expect.objectContaining({
108
- and: expect.arrayContaining([
109
- expect.objectContaining({ mockField: 'mockValue' }),
110
- expect.objectContaining({
111
- AppId: 1,
112
- expires: expect.objectContaining({
113
- or: expect.arrayContaining([{ gt: expect.any(Date) }, null]),
114
- }),
115
- type: 'mockResourceType',
116
- }),
117
- ]),
118
- }),
119
- }),
120
- type: 'mockResourceType',
121
- }));
122
- });
123
- it('should set the response body to resources when no view is specified', async () => {
124
- const mockApp = {
125
- id: 1,
126
- definition: {
127
- resources: {
128
- mockResourceType: { id: 'id', schema: {} },
129
- },
130
- },
131
- };
132
- const mockResources = [{ id: 1 }, { id: 2 }];
133
- const mockParsedQuery = {
134
- order: [
135
- ['mockField1', 'mockOrderAsc'],
136
- ['mockField2', 'mockOrderDesc'],
137
- ],
138
- where: { mockField: 'mockValue' },
139
- };
140
- mockGetApp.mockResolvedValue(mockApp);
141
- mockGetAppResources.mockResolvedValue(mockResources);
142
- mockParseQuery.mockReturnValue(mockParsedQuery);
143
- const middleware = createQueryAppResourcesController({
144
- getApp: mockGetApp,
145
- getAppResources: mockGetAppResources,
146
- parseQuery: mockParseQuery,
147
- checkAppPermissions: mockCheckAppPermissions,
148
- });
149
- await middleware(mockCtx, vi.fn());
150
- expect(mockCtx.body).toStrictEqual(mockResources);
151
- });
152
- it('should set the response body to remapped resources when view is specified', async () => {
153
- const mockApp = {
154
- id: 1,
155
- definition: {
156
- resources: {
157
- mockResourceType: { id: 'id', schema: {}, views: { view: {} } },
158
- },
159
- },
160
- };
161
- const mockResources = [{ id: 1 }, { id: 2 }];
162
- const mockParsedQuery = {
163
- order: [
164
- ['mockField1', 'mockOrderAsc'],
165
- ['mockField2', 'mockOrderDesc'],
166
- ],
167
- where: { mockField: 'mockValue' },
168
- };
169
- const mockAppUrl = new URL('https://localhost');
170
- const mockAppMessages = [{ language: 'eng', messages: {} }];
171
- const mockAppVariables = [{ name: 'variable', value: 'variable' }];
172
- mockGetApp.mockResolvedValue(mockApp);
173
- mockGetAppResources.mockResolvedValue(mockResources);
174
- mockParseQuery.mockReturnValue(mockParsedQuery);
175
- mockGetAppUrl.mockResolvedValue(mockAppUrl);
176
- mockGetAppMessages.mockResolvedValue(mockAppMessages);
177
- mockGetAppVariables.mockResolvedValue(mockAppVariables);
178
- mockCtx.queryParams.view = 'view';
179
- const options = {
180
- getApp: mockGetApp,
181
- getAppResources: mockGetAppResources,
182
- parseQuery: mockParseQuery,
183
- getAppUrl: mockGetAppUrl,
184
- getAppMessages: mockGetAppMessages,
185
- getAppVariables: mockGetAppVariables,
186
- getCurrentAppMember: mockGetCurrentAppMember,
187
- checkAppPermissions: mockCheckAppPermissions,
188
- };
189
- const resourceDefinition = getResourceDefinition(mockApp.definition, 'mockResourceType', mockCtx, 'view');
190
- const remapperContext = await getRemapperContext(mockApp, mockApp.definition.defaultLanguage || defaultLocale, options, mockCtx);
191
- const remappedResources = mockResources.map((resource) => remap(resourceDefinition.views.view.remap, resource, remapperContext));
192
- const middleware = createQueryAppResourcesController(options);
193
- await middleware(mockCtx, vi.fn());
194
- expect(mockCtx.body).toStrictEqual(remappedResources);
195
- });
196
- });
197
- describe('createCountResources', () => {
198
- beforeEach(() => {
199
- mockGetApp = vi.fn();
200
- mockGetAppResources = vi.fn();
201
- mockParseQuery = vi.fn();
202
- mockCtx = {
203
- pathParams: { appId: 1, resourceType: 'mockResourceType' },
204
- queryParams: {},
205
- user: { id: 'mockUserId', name: 'John Doe', primaryEmail: 'john@example.com' },
206
- };
207
- });
208
- it('should fetch app and resources with correct parameters', async () => {
209
- const mockApp = {
210
- id: 1,
211
- definition: {
212
- resources: {
213
- mockResourceType: { id: 'id', schema: {} },
214
- },
215
- },
216
- };
217
- const mockResources = [{ id: 1 }, { id: 2 }];
218
- const mockParsedQuery = {
219
- order: [
220
- ['mockField1', 'mockOrderAsc'],
221
- ['mockField2', 'mockOrderDesc'],
222
- ],
223
- where: { mockField: 'mockValue' },
224
- };
225
- mockGetApp.mockResolvedValue(mockApp);
226
- mockGetAppResources.mockResolvedValue(mockResources);
227
- mockParseQuery.mockReturnValue(mockParsedQuery);
228
- const middleware = createCountAppResourcesController({
229
- getApp: mockGetApp,
230
- getAppResources: mockGetAppResources,
231
- parseQuery: mockParseQuery,
232
- checkAppPermissions: mockCheckAppPermissions,
233
- });
234
- await middleware(mockCtx, vi.fn());
235
- expect(mockGetApp).toHaveBeenCalledWith(expect.objectContaining({
236
- context: expect.objectContaining({
237
- pathParams: expect.objectContaining({ appId: 1 }),
238
- }),
239
- query: expect.objectContaining({ where: { id: 1 } }),
240
- }));
241
- expect(mockGetAppResources).toHaveBeenCalledWith(expect.objectContaining({
242
- app: {
243
- definition: {
244
- resources: {
245
- mockResourceType: {
246
- id: 'id',
247
- schema: {},
248
- },
249
- },
250
- },
251
- id: 1,
252
- },
253
- context: expect.objectContaining({
254
- pathParams: expect.objectContaining({
255
- appId: 1,
256
- resourceType: 'mockResourceType',
257
- }),
258
- user: expect.objectContaining({
259
- id: 'mockUserId',
260
- name: 'John Doe',
261
- primaryEmail: 'john@example.com',
262
- }),
263
- }),
264
- findOptions: expect.objectContaining({
265
- where: expect.objectContaining({
266
- and: expect.arrayContaining([
267
- expect.objectContaining({ mockField: 'mockValue' }),
268
- expect.objectContaining({
269
- AppId: 1,
270
- expires: expect.objectContaining({
271
- or: expect.arrayContaining([{ gt: expect.any(Date) }, null]),
272
- }),
273
- type: 'mockResourceType',
274
- }),
275
- ]),
276
- }),
277
- }),
278
- type: 'mockResourceType',
279
- }));
280
- });
281
- it('should set the response body to resources count', async () => {
282
- const mockApp = {
283
- id: 1,
284
- definition: {
285
- resources: {
286
- mockResourceType: { id: 'id', schema: {} },
287
- },
288
- },
289
- };
290
- const mockResources = [{ id: 1 }, { id: 2 }];
291
- const mockParsedQuery = {
292
- order: [
293
- ['mockField1', 'mockOrderAsc'],
294
- ['mockField2', 'mockOrderDesc'],
295
- ],
296
- where: { mockField: 'mockValue' },
297
- };
298
- mockGetApp.mockResolvedValue(mockApp);
299
- mockGetAppResources.mockResolvedValue(mockResources);
300
- mockParseQuery.mockReturnValue(mockParsedQuery);
301
- const middleware = createCountAppResourcesController({
302
- getApp: mockGetApp,
303
- getAppResources: mockGetAppResources,
304
- parseQuery: mockParseQuery,
305
- checkAppPermissions: mockCheckAppPermissions,
306
- });
307
- await middleware(mockCtx, vi.fn());
308
- expect(mockCtx.body).toStrictEqual(mockResources.length);
309
- });
310
- });
311
- describe('createGetResourceById', () => {
312
- beforeEach(() => {
313
- mockGetApp = vi.fn();
314
- mockGetAppResource = vi.fn();
315
- mockGetAppUrl = vi.fn();
316
- mockGetAppMessages = vi.fn();
317
- mockGetAppVariables = vi.fn();
318
- mockCtx = {
319
- pathParams: { appId: 1, resourceId: 1, resourceType: 'mockResourceType' },
320
- user: { id: 'mockUserId', name: 'John Doe', primaryEmail: 'john@example.com' },
321
- queryParams: {},
322
- };
323
- });
324
- it('should fetch app and resource with correct parameters', async () => {
325
- const mockApp = {
326
- id: 1,
327
- definition: {
328
- resources: {
329
- mockResourceType: { id: 'id', schema: {} },
330
- },
331
- },
332
- };
333
- const mockResource = { id: 1 };
334
- mockGetApp.mockResolvedValue(mockApp);
335
- mockGetAppResource.mockResolvedValue(mockResource);
336
- const middleware = createGetAppResourceByIdController({
337
- getApp: mockGetApp,
338
- getAppResource: mockGetAppResource,
339
- parseQuery: mockParseQuery,
340
- checkAppPermissions: mockCheckAppPermissions,
341
- });
342
- await middleware(mockCtx, vi.fn());
343
- expect(mockGetApp).toHaveBeenCalledWith(expect.objectContaining({
344
- context: expect.objectContaining({
345
- pathParams: expect.objectContaining({ appId: 1 }),
346
- }),
347
- query: expect.objectContaining({ where: { id: 1 } }),
348
- }));
349
- expect(mockGetAppResource).toHaveBeenCalledWith(expect.objectContaining({
350
- app: {
351
- definition: {
352
- resources: {
353
- mockResourceType: {
354
- id: 'id',
355
- schema: {},
356
- },
357
- },
358
- },
359
- id: 1,
360
- },
361
- id: 1,
362
- type: 'mockResourceType',
363
- context: expect.objectContaining({
364
- pathParams: expect.objectContaining({
365
- appId: 1,
366
- resourceType: 'mockResourceType',
367
- }),
368
- user: expect.objectContaining({
369
- id: 'mockUserId',
370
- name: 'John Doe',
371
- primaryEmail: 'john@example.com',
372
- }),
373
- }),
374
- findOptions: expect.objectContaining({
375
- where: expect.objectContaining({
376
- id: 1,
377
- type: 'mockResourceType',
378
- AppId: 1,
379
- expires: expect.objectContaining({
380
- or: expect.arrayContaining([{ gt: expect.any(Date) }, null]),
381
- }),
382
- }),
383
- }),
384
- }));
385
- });
386
- it('should set the response body to resource when no view is specified', async () => {
387
- const mockApp = {
388
- id: 1,
389
- definition: {
390
- resources: {
391
- mockResourceType: { id: 'id', schema: {} },
392
- },
393
- },
394
- };
395
- const mockResource = { id: 1 };
396
- mockGetApp.mockResolvedValue(mockApp);
397
- mockGetAppResource.mockResolvedValue(mockResource);
398
- const middleware = createGetAppResourceByIdController({
399
- getApp: mockGetApp,
400
- getAppResource: mockGetAppResource,
401
- checkAppPermissions: mockCheckAppPermissions,
402
- parseQuery: mockParseQuery,
403
- });
404
- await middleware(mockCtx, vi.fn());
405
- expect(mockCtx.body).toStrictEqual(mockResource);
406
- });
407
- it('should set the response body to remapped resource when view is specified', async () => {
408
- const mockApp = {
409
- id: 1,
410
- definition: {
411
- resources: {
412
- mockResourceType: { id: 'id', schema: {}, views: { view: {} } },
413
- },
414
- },
415
- };
416
- const mockResource = { id: 1 };
417
- const mockAppUrl = new URL('https://localhost');
418
- const mockAppMessages = [{ language: 'eng', messages: {} }];
419
- const mockAppVariables = [{ name: 'variable', value: 'variable' }];
420
- mockGetApp.mockResolvedValue(mockApp);
421
- mockGetAppResource.mockResolvedValue(mockResource);
422
- mockGetAppUrl.mockResolvedValue(mockAppUrl);
423
- mockGetAppMessages.mockResolvedValue(mockAppMessages);
424
- mockGetAppVariables.mockResolvedValue(mockAppVariables);
425
- mockCtx.queryParams = { view: 'view' };
426
- const options = {
427
- getApp: mockGetApp,
428
- getAppResource: mockGetAppResource,
429
- getAppUrl: mockGetAppUrl,
430
- getAppMessages: mockGetAppMessages,
431
- getAppVariables: mockGetAppVariables,
432
- checkAppPermissions: mockCheckAppPermissions,
433
- getCurrentAppMember: mockGetCurrentAppMember,
434
- };
435
- const resourceDefinition = getResourceDefinition(mockApp.definition, 'mockResourceType', mockCtx, 'view');
436
- const remapperContext = await getRemapperContext(mockApp, mockApp.definition.defaultLanguage || defaultLocale, options, mockCtx);
437
- const remappedResource = remap(resourceDefinition.views.view.remap, mockResource, remapperContext);
438
- const middleware = createGetAppResourceByIdController(options);
439
- await middleware(mockCtx, vi.fn());
440
- expect(mockCtx.body).toStrictEqual(remappedResource);
441
- });
442
- });
443
- describe('createCreateResource', () => {
444
- beforeEach(() => {
445
- mockGetApp = vi.fn();
446
- mockCreateAppResourcesWithAssets = vi.fn();
447
- mockGetAppAssets = vi.fn();
448
- mockCtxIs = vi.fn();
449
- mockCtx = {
450
- pathParams: { appId: 1, resourceType: 'mockResourceType' },
451
- user: { id: 'mockUserId', name: 'John Doe', primaryEmail: 'john@example.com' },
452
- is: mockCtxIs,
453
- request: {},
454
- queryParams: {},
455
- };
456
- });
457
- it('should fetch app and create multiple resources', async () => {
458
- const mockApp = {
459
- id: 1,
460
- definition: {
461
- resources: {
462
- mockResourceType: { id: 'id', schema: {} },
463
- },
464
- },
465
- };
466
- const mockResources = [{ id: 1 }, { id: 2 }];
467
- mockCtx.request.body = { resource: mockResources };
468
- mockGetApp.mockResolvedValue(mockApp);
469
- mockCtxIs.mockReturnValue('multipart/form-data');
470
- mockCreateAppResourcesWithAssets.mockResolvedValue(mockResources);
471
- mockGetAppAssets.mockResolvedValue([]);
472
- const middleware = createCreateAppResourceController({
473
- getApp: mockGetApp,
474
- createAppResourcesWithAssets: mockCreateAppResourcesWithAssets,
475
- getAppAssets: mockGetAppAssets,
476
- checkAppPermissions: mockCheckAppPermissions,
477
- getCurrentAppMember: mockGetCurrentAppMember,
478
- parseQuery: mockParseQuery,
479
- });
480
- await middleware(mockCtx, vi.fn());
481
- expect(mockGetApp).toHaveBeenCalledWith(expect.objectContaining({
482
- context: expect.objectContaining({
483
- pathParams: expect.objectContaining({ appId: 1 }),
484
- }),
485
- query: expect.objectContaining({ where: { id: 1 } }),
486
- }));
487
- expect(mockCreateAppResourcesWithAssets).toHaveBeenCalledWith(expect.objectContaining({
488
- app: expect.objectContaining({
489
- definition: expect.objectContaining({
490
- resources: expect.objectContaining({
491
- mockResourceType: expect.objectContaining({
492
- id: 'id',
493
- schema: {},
494
- }),
495
- }),
496
- }),
497
- id: 1,
498
- }),
499
- context: expect.objectContaining({
500
- request: expect.objectContaining({
501
- body: {
502
- resource: mockResources,
503
- },
504
- }),
505
- pathParams: expect.objectContaining({
506
- appId: 1,
507
- resourceType: 'mockResourceType',
508
- }),
509
- user: expect.objectContaining({
510
- id: 'mockUserId',
511
- name: 'John Doe',
512
- primaryEmail: 'john@example.com',
513
- }),
514
- }),
515
- }));
516
- expect(mockCtx.body).toStrictEqual(mockResources);
517
- });
518
- it('should fetch app and create a single resource', async () => {
519
- const mockApp = {
520
- id: 1,
521
- definition: {
522
- resources: {
523
- mockResourceType: { id: 'id', schema: {} },
524
- },
525
- },
526
- };
527
- const mockResources = [{ id: 1 }];
528
- mockCtx.request.body = { resource: mockResources[0] };
529
- mockGetApp.mockResolvedValue(mockApp);
530
- mockCtxIs.mockReturnValue('multipart/form-data');
531
- mockCreateAppResourcesWithAssets.mockResolvedValue(mockResources);
532
- mockGetAppAssets.mockResolvedValue([]);
533
- const middleware = createCreateAppResourceController({
534
- getApp: mockGetApp,
535
- createAppResourcesWithAssets: mockCreateAppResourcesWithAssets,
536
- getAppAssets: mockGetAppAssets,
537
- checkAppPermissions: mockCheckAppPermissions,
538
- getCurrentAppMember: mockGetCurrentAppMember,
539
- parseQuery: mockParseQuery,
540
- });
541
- await middleware(mockCtx, vi.fn());
542
- expect(mockGetApp).toHaveBeenCalledWith(expect.objectContaining({
543
- context: expect.objectContaining({
544
- pathParams: expect.objectContaining({ appId: 1 }),
545
- }),
546
- query: expect.objectContaining({ where: { id: 1 } }),
547
- }));
548
- expect(mockCreateAppResourcesWithAssets).toHaveBeenCalledWith(expect.objectContaining({
549
- app: expect.objectContaining({
550
- definition: expect.objectContaining({
551
- resources: expect.objectContaining({
552
- mockResourceType: expect.objectContaining({
553
- id: 'id',
554
- schema: {},
555
- }),
556
- }),
557
- }),
558
- id: 1,
559
- }),
560
- context: expect.objectContaining({
561
- request: expect.objectContaining({
562
- body: {
563
- resource: mockResources[0],
564
- },
565
- }),
566
- pathParams: expect.objectContaining({
567
- appId: 1,
568
- resourceType: 'mockResourceType',
569
- }),
570
- user: expect.objectContaining({
571
- id: 'mockUserId',
572
- name: 'John Doe',
573
- primaryEmail: 'john@example.com',
574
- }),
575
- }),
576
- }));
577
- expect(mockCtx.body).toStrictEqual(mockResources[0]);
578
- });
579
- });
580
- //# sourceMappingURL=resources.test.js.map
@@ -1 +0,0 @@
1
- export {};
@@ -1,83 +0,0 @@
1
- import { noop } from '@appsemble/utils';
2
- import { request, setTestApp } from 'axios-test-instance';
3
- import Koa from 'koa';
4
- import { beforeEach, expect, it, vi } from 'vitest';
5
- import { errorMiddleware } from './index.js';
6
- import { tinyRouter } from './tinyRouter.js';
7
- let app;
8
- let context;
9
- beforeEach(async () => {
10
- app = new Koa();
11
- app.silent = true;
12
- app.use((ctx, next) => {
13
- context = ctx;
14
- return next();
15
- });
16
- await setTestApp(app);
17
- });
18
- it('should assign the match group to params', async () => {
19
- app.use(tinyRouter([
20
- {
21
- route: /^\/(?<foo>.+)\/(?<bar>.+)/,
22
- get: noop,
23
- },
24
- ]));
25
- await request.get('/1/2');
26
- expect(context.params).toStrictEqual({ foo: '1', bar: '2' });
27
- });
28
- it('should throw method not allowed if a URL is matched, but not for the given method', async () => {
29
- app.use(errorMiddleware());
30
- app.use(tinyRouter([
31
- {
32
- route: '/',
33
- get: noop,
34
- },
35
- ]));
36
- await request.post('/');
37
- expect(context.status).toBe(405);
38
- });
39
- it('should fall back to the any handler if it exists', async () => {
40
- const any = vi.fn();
41
- app.use(tinyRouter([
42
- {
43
- route: '/',
44
- any,
45
- },
46
- ]));
47
- await request.post('/');
48
- expect(any).toHaveBeenCalledWith(context, expect.any(Function));
49
- });
50
- it('should pick method specific middleware over any', async () => {
51
- const any = vi.fn();
52
- const get = vi.fn();
53
- app.use(tinyRouter([
54
- {
55
- route: '/',
56
- any,
57
- get,
58
- },
59
- ]));
60
- await request.get('/');
61
- expect(any).not.toHaveBeenCalled();
62
- expect(get).toHaveBeenCalledWith(context, expect.any(Function));
63
- });
64
- it('should not call next if there are matching routes', async () => {
65
- const middleware = vi.fn();
66
- app.use(tinyRouter([
67
- {
68
- route: '/',
69
- get: noop,
70
- },
71
- ]));
72
- app.use(middleware);
73
- await request.get('/');
74
- expect(middleware).not.toHaveBeenCalled();
75
- });
76
- it('should call next if there are no matching routes', async () => {
77
- const middleware = vi.fn();
78
- app.use(tinyRouter([]));
79
- app.use(middleware);
80
- await request.get('/');
81
- expect(middleware).toHaveBeenCalledWith(context, expect.any(Function));
82
- });
83
- //# sourceMappingURL=tinyRouter.test.js.map
package/versions.cjs DELETED
@@ -1,4 +0,0 @@
1
- // Ts-node doesn’t understand this if it’s written as TypeScript.
2
- module.exports.faVersion = require('@fortawesome/fontawesome-free/package.json').version;
3
- module.exports.bulmaVersion = require('bulma/package.json').version;
4
- module.exports.version = require('./package.json').version;