arocapi 1.1.0 → 1.2.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.
Files changed (127) hide show
  1. package/README.md +334 -8
  2. package/dist/app.d.ts +19 -1
  3. package/dist/app.js +35 -28
  4. package/dist/app.js.map +1 -1
  5. package/dist/app.test.js +124 -0
  6. package/dist/app.test.js.map +1 -0
  7. package/dist/index.dev.js +146 -0
  8. package/dist/index.dev.js.map +1 -0
  9. package/dist/routes/crate.d.ts +7 -0
  10. package/dist/routes/crate.js +99 -0
  11. package/dist/routes/crate.js.map +1 -0
  12. package/dist/routes/crate.test.d.ts +1 -0
  13. package/dist/routes/crate.test.js +360 -0
  14. package/dist/routes/crate.test.js.map +1 -0
  15. package/dist/routes/entities.d.ts +6 -1
  16. package/dist/routes/entities.js +51 -39
  17. package/dist/routes/entities.js.map +1 -1
  18. package/dist/routes/entities.test.d.ts +1 -0
  19. package/dist/routes/entities.test.js +245 -0
  20. package/dist/routes/entities.test.js.map +1 -0
  21. package/dist/routes/entity.d.ts +6 -1
  22. package/dist/routes/entity.js +28 -7
  23. package/dist/routes/entity.js.map +1 -1
  24. package/dist/routes/entity.test.d.ts +1 -0
  25. package/dist/routes/entity.test.js +109 -0
  26. package/dist/routes/entity.test.js.map +1 -0
  27. package/dist/routes/file.d.ts +7 -0
  28. package/dist/routes/file.js +111 -0
  29. package/dist/routes/file.js.map +1 -0
  30. package/dist/routes/file.test.d.ts +1 -0
  31. package/dist/routes/file.test.js +319 -0
  32. package/dist/routes/file.test.js.map +1 -0
  33. package/dist/routes/files.d.ts +8 -0
  34. package/dist/routes/files.js +61 -0
  35. package/dist/routes/files.js.map +1 -0
  36. package/dist/routes/files.test.d.ts +1 -0
  37. package/dist/routes/files.test.js +244 -0
  38. package/dist/routes/files.test.js.map +1 -0
  39. package/dist/routes/search.d.ts +6 -1
  40. package/dist/routes/search.js +43 -17
  41. package/dist/routes/search.js.map +1 -1
  42. package/dist/routes/search.test.d.ts +1 -0
  43. package/dist/routes/search.test.js +698 -0
  44. package/dist/routes/search.test.js.map +1 -0
  45. package/dist/test/helpers/fastify.d.ts +9 -0
  46. package/dist/test/helpers/fastify.js +24 -0
  47. package/dist/test/helpers/fastify.js.map +1 -0
  48. package/dist/test/integration.setup.d.ts +58 -0
  49. package/dist/test/integration.setup.js +181 -0
  50. package/dist/test/integration.setup.js.map +1 -0
  51. package/dist/test/integration.test.d.ts +1 -0
  52. package/dist/test/integration.test.js +337 -0
  53. package/dist/test/integration.test.js.map +1 -0
  54. package/dist/transformers/default.d.ts +45 -0
  55. package/dist/transformers/default.js +46 -0
  56. package/dist/transformers/default.js.map +1 -0
  57. package/dist/transformers/default.test.d.ts +1 -0
  58. package/dist/transformers/default.test.js +177 -0
  59. package/dist/transformers/default.test.js.map +1 -0
  60. package/dist/transformers/transformer.test.d.ts +1 -0
  61. package/dist/transformers/transformer.test.js +176 -0
  62. package/dist/transformers/transformer.test.js.map +1 -0
  63. package/dist/types/fileHandlers.d.ts +41 -0
  64. package/dist/types/fileHandlers.js +2 -0
  65. package/dist/types/fileHandlers.js.map +1 -0
  66. package/dist/types/transformers.d.ts +10 -0
  67. package/dist/types/transformers.js +2 -0
  68. package/dist/types/transformers.js.map +1 -0
  69. package/dist/utils/errors.d.ts +23 -0
  70. package/dist/utils/errors.js +21 -0
  71. package/dist/utils/errors.js.map +1 -0
  72. package/dist/utils/errors.test.d.ts +1 -0
  73. package/dist/utils/errors.test.js +66 -0
  74. package/dist/utils/errors.test.js.map +1 -0
  75. package/package.json +34 -25
  76. package/prisma/migrations/20250827033956_record_type_scalar/migration.sql +10 -0
  77. package/prisma/migrations/20250923032753_api_refactor/migration.sql +39 -0
  78. package/prisma/migrations/20250923223119_entity_type_to_string/migration.sql +8 -0
  79. package/prisma/migrations/20251020140329_add_meta_column/migration.sql +2 -0
  80. package/prisma/migrations/20251027010713_add_file_table/migration.sql +17 -0
  81. package/prisma/migrations/20251027221138_add_file_id_to_entity/migration.sql +2 -0
  82. package/prisma/models/entity.prisma +16 -12
  83. package/prisma/models/file.prisma +20 -0
  84. package/prisma.config.ts +6 -1
  85. package/src/__snapshots__/app.test.ts.snap +8 -0
  86. package/src/app.test.ts +158 -0
  87. package/src/app.ts +97 -35
  88. package/src/index.dev.ts +196 -0
  89. package/src/reset.d.ts +1 -0
  90. package/src/routes/__snapshots__/entities.test.ts.snap +68 -0
  91. package/src/routes/__snapshots__/entity.test.ts.snap +66 -0
  92. package/src/routes/__snapshots__/search.test.ts.snap +139 -0
  93. package/src/routes/crate.test.ts +441 -0
  94. package/src/routes/crate.ts +141 -0
  95. package/src/routes/entities.test.ts +284 -0
  96. package/src/routes/entities.ts +64 -45
  97. package/src/routes/entity.test.ts +132 -0
  98. package/src/routes/entity.ts +57 -22
  99. package/src/routes/file.test.ts +399 -0
  100. package/src/routes/file.ts +153 -0
  101. package/src/routes/files.test.ts +303 -0
  102. package/src/routes/files.ts +87 -0
  103. package/src/routes/search.test.ts +807 -0
  104. package/src/routes/search.ts +66 -23
  105. package/src/test/__snapshots__/integration.test.ts.snap +18 -0
  106. package/src/test/helpers/fastify.ts +39 -0
  107. package/src/test/integration.setup.ts +200 -0
  108. package/src/test/integration.test.ts +411 -0
  109. package/src/transformers/default.test.ts +199 -0
  110. package/src/transformers/default.ts +165 -0
  111. package/src/transformers/transformer.test.ts +233 -0
  112. package/src/types/fileHandlers.ts +65 -0
  113. package/src/types/transformers.ts +52 -0
  114. package/src/utils/errors.test.ts +75 -0
  115. package/src/utils/errors.ts +45 -0
  116. package/dist/index.js +0 -25
  117. package/dist/index.js.map +0 -1
  118. package/dist/scripts/loadEntities.js +0 -170
  119. package/dist/scripts/loadEntities.js.map +0 -1
  120. package/dist/type.d.ts +0 -6
  121. package/dist/type.js +0 -2
  122. package/dist/type.js.map +0 -1
  123. package/src/index.ts +0 -35
  124. package/src/scripts/loadEntities.ts +0 -223
  125. package/src/type.ts +0 -7
  126. /package/dist/{scripts/loadEntities.d.ts → app.test.d.ts} +0 -0
  127. /package/dist/{index.d.ts → index.dev.d.ts} +0 -0
@@ -0,0 +1,411 @@
1
+ import { afterAll, afterEach, beforeAll, beforeEach, describe, expect, it } from 'vitest';
2
+ import type { AuthorisedEntity } from '../transformers/default.js';
3
+ import type { StandardErrorResponse } from '../utils/errors.js';
4
+ import {
5
+ cleanupTestData,
6
+ getTestApp,
7
+ seedTestData,
8
+ setupIntegrationTests,
9
+ teardownIntegrationTests,
10
+ } from './integration.setup.js';
11
+
12
+ describe('Integration Tests', () => {
13
+ beforeAll(async () => {
14
+ await setupIntegrationTests();
15
+ });
16
+
17
+ afterAll(async () => {
18
+ await teardownIntegrationTests();
19
+ });
20
+
21
+ beforeEach(async () => {
22
+ await seedTestData();
23
+ });
24
+
25
+ afterEach(async () => {
26
+ await cleanupTestData();
27
+ });
28
+
29
+ describe('GET /entity/:id', () => {
30
+ it('should return entity from database', async () => {
31
+ const app = getTestApp();
32
+
33
+ const response = await app.inject({
34
+ method: 'GET',
35
+ url: `/entity/${encodeURIComponent('http://example.com/entity/1')}`,
36
+ });
37
+ const body = JSON.parse(response.body);
38
+
39
+ expect(response.statusCode).toBe(200);
40
+ expect(body).toMatchSnapshot();
41
+ });
42
+
43
+ it('should return File entity from database', async () => {
44
+ const app = getTestApp();
45
+
46
+ const response = await app.inject({
47
+ method: 'GET',
48
+ url: `/entity/${encodeURIComponent('http://example.com/entity/4')}`,
49
+ });
50
+ const body = JSON.parse(response.body) as AuthorisedEntity;
51
+
52
+ expect(response.statusCode).toBe(200);
53
+ expect(body.id).toBe('http://example.com/entity/4');
54
+ expect(body.name).toBe('test-audio.wav');
55
+ expect(body.entityType).toBe('http://schema.org/MediaObject');
56
+ expect(body.memberOf).toBe('http://example.com/entity/2');
57
+ expect(body.rootCollection).toBe('http://example.com/entity/1');
58
+ });
59
+
60
+ it('should return 404 for non-existent entity', async () => {
61
+ const app = getTestApp();
62
+
63
+ const response = await app.inject({
64
+ method: 'GET',
65
+ url: '/entity/http://example.com/entity/nonexistent',
66
+ });
67
+ const body = JSON.parse(response.body) as StandardErrorResponse;
68
+
69
+ expect(response.statusCode).toBe(404);
70
+ expect(body.error).toBe('Not Found');
71
+ });
72
+ });
73
+
74
+ describe('GET /entities', () => {
75
+ it('should return all entities with pagination', async () => {
76
+ const app = getTestApp();
77
+
78
+ const response = await app.inject({
79
+ method: 'GET',
80
+ url: '/entities',
81
+ });
82
+ const body = JSON.parse(response.body) as { total: number; entities: AuthorisedEntity[] };
83
+
84
+ expect(response.statusCode).toBe(200);
85
+ expect(body.total).toBe(5);
86
+ expect(body.entities).toHaveLength(5);
87
+ expect(body.entities[0]).toEqual({
88
+ id: 'http://example.com/entity/1',
89
+ name: 'Test Collection',
90
+ description: 'First test entity',
91
+ entityType: 'http://pcdm.org/models#Collection',
92
+ memberOf: null,
93
+ rootCollection: null,
94
+ metadataLicenseId: 'https://creativecommons.org/licenses/by/4.0/',
95
+ contentLicenseId: 'https://creativecommons.org/licenses/by/4.0/',
96
+ access: {
97
+ metadata: true,
98
+ content: true,
99
+ },
100
+ });
101
+ });
102
+
103
+ it('should filter entities by memberOf', async () => {
104
+ const app = getTestApp();
105
+
106
+ const response = await app.inject({
107
+ method: 'GET',
108
+ url: '/entities',
109
+ query: {
110
+ memberOf: 'http://example.com/entity/1',
111
+ },
112
+ });
113
+ const body = JSON.parse(response.body) as { total: number; entities: AuthorisedEntity[] };
114
+
115
+ expect(response.statusCode).toBe(200);
116
+ expect(body.total).toBe(3);
117
+ expect(body.entities).toHaveLength(3);
118
+ expect(body.entities[0].id).toBe('http://example.com/entity/2');
119
+ });
120
+
121
+ it('should filter entities by entityType', async () => {
122
+ const app = getTestApp();
123
+
124
+ const response = await app.inject({
125
+ method: 'GET',
126
+ url: '/entities',
127
+ query: {
128
+ entityType: 'http://schema.org/Person',
129
+ },
130
+ });
131
+ const body = JSON.parse(response.body) as { total: number; entities: AuthorisedEntity[] };
132
+
133
+ expect(response.statusCode).toBe(200);
134
+ expect(body.total).toBe(1);
135
+ expect(body.entities).toHaveLength(1);
136
+ expect(body.entities[0].id).toBe('http://example.com/entity/3');
137
+ });
138
+
139
+ it('should filter entities by File entityType', async () => {
140
+ const app = getTestApp();
141
+
142
+ const response = await app.inject({
143
+ method: 'GET',
144
+ url: '/entities',
145
+ query: {
146
+ entityType: 'http://schema.org/MediaObject',
147
+ },
148
+ });
149
+ const body = JSON.parse(response.body) as { total: number; entities: AuthorisedEntity[] };
150
+
151
+ expect(response.statusCode).toBe(200);
152
+ expect(body.total).toBe(2);
153
+ expect(body.entities).toHaveLength(2);
154
+ expect(body.entities[0].entityType).toBe('http://schema.org/MediaObject');
155
+ expect(body.entities[1].entityType).toBe('http://schema.org/MediaObject');
156
+ });
157
+
158
+ it('should filter File entities by memberOf (Object parent)', async () => {
159
+ const app = getTestApp();
160
+
161
+ const response = await app.inject({
162
+ method: 'GET',
163
+ url: '/entities',
164
+ query: {
165
+ memberOf: 'http://example.com/entity/2',
166
+ entityType: 'http://schema.org/MediaObject',
167
+ },
168
+ });
169
+ const body = JSON.parse(response.body) as { total: number; entities: AuthorisedEntity[] };
170
+
171
+ expect(response.statusCode).toBe(200);
172
+ expect(body.total).toBe(1);
173
+ expect(body.entities).toHaveLength(1);
174
+ expect(body.entities[0].id).toBe('http://example.com/entity/4');
175
+ expect(body.entities[0].name).toBe('test-audio.wav');
176
+ expect(body.entities[0].memberOf).toBe('http://example.com/entity/2');
177
+ });
178
+
179
+ it('should filter File entities by memberOf (Collection parent)', async () => {
180
+ const app = getTestApp();
181
+
182
+ const response = await app.inject({
183
+ method: 'GET',
184
+ url: '/entities',
185
+ query: {
186
+ memberOf: 'http://example.com/entity/1',
187
+ entityType: 'http://schema.org/MediaObject',
188
+ },
189
+ });
190
+ const body = JSON.parse(response.body) as { total: number; entities: AuthorisedEntity[] };
191
+
192
+ expect(response.statusCode).toBe(200);
193
+ expect(body.total).toBe(1);
194
+ expect(body.entities).toHaveLength(1);
195
+ expect(body.entities[0].id).toBe('http://example.com/entity/5');
196
+ expect(body.entities[0].name).toBe('collection-metadata.csv');
197
+ expect(body.entities[0].memberOf).toBe('http://example.com/entity/1');
198
+ });
199
+
200
+ it('should handle pagination', async () => {
201
+ const app = getTestApp();
202
+
203
+ const response = await app.inject({
204
+ method: 'GET',
205
+ url: '/entities',
206
+ query: {
207
+ limit: '2',
208
+ offset: '1',
209
+ },
210
+ });
211
+ const body = JSON.parse(response.body) as { total: number; entities: AuthorisedEntity[] };
212
+
213
+ expect(response.statusCode).toBe(200);
214
+ expect(body.total).toBe(5);
215
+ expect(body.entities).toHaveLength(2);
216
+ });
217
+
218
+ it('should sort entities by name', async () => {
219
+ const app = getTestApp();
220
+
221
+ const response = await app.inject({
222
+ method: 'GET',
223
+ url: '/entities',
224
+ query: {
225
+ sort: 'name',
226
+ order: 'desc',
227
+ },
228
+ });
229
+ const body = JSON.parse(response.body) as { total: number; entities: AuthorisedEntity[] };
230
+
231
+ expect(response.statusCode).toBe(200);
232
+ expect(body.entities[0].name).toBe('test-audio.wav');
233
+ expect(body.entities[1].name).toBe('Test Person');
234
+ expect(body.entities[2].name).toBe('Test Object');
235
+ });
236
+ });
237
+
238
+ describe('POST /search', () => {
239
+ it('should perform basic search', async () => {
240
+ const app = getTestApp();
241
+
242
+ const response = await app.inject({
243
+ method: 'POST',
244
+ url: '/search',
245
+ payload: {
246
+ query: 'test',
247
+ searchType: 'basic',
248
+ },
249
+ });
250
+ const body = JSON.parse(response.body) as { total: number; entities: AuthorisedEntity[] };
251
+
252
+ expect(response.statusCode).toBe(200);
253
+ expect(body.total).toBeGreaterThan(0);
254
+ expect(body.entities).toBeDefined();
255
+ expect(Array.isArray(body.entities)).toBe(true);
256
+ });
257
+
258
+ it('should handle search with no results', async () => {
259
+ const app = getTestApp();
260
+
261
+ const response = await app.inject({
262
+ method: 'POST',
263
+ url: '/search',
264
+ payload: {
265
+ query: 'nonexistentterm',
266
+ searchType: 'basic',
267
+ },
268
+ });
269
+ const body = JSON.parse(response.body) as { total: number; entities: AuthorisedEntity[] };
270
+
271
+ expect(response.statusCode).toBe(200);
272
+ expect(body.total).toBe(0);
273
+ expect(body.entities).toHaveLength(0);
274
+ });
275
+
276
+ it('should return aggregations', async () => {
277
+ const app = getTestApp();
278
+
279
+ const response = await app.inject({
280
+ method: 'POST',
281
+ url: '/search',
282
+ payload: {
283
+ query: 'test',
284
+ searchType: 'basic',
285
+ },
286
+ });
287
+ const body = JSON.parse(response.body) as { total: number; entities: AuthorisedEntity[]; facets: null };
288
+
289
+ expect(response.statusCode).toBe(200);
290
+ expect(body.facets).toBeDefined();
291
+ });
292
+
293
+ it('should handle search pagination', async () => {
294
+ const app = getTestApp();
295
+
296
+ const response = await app.inject({
297
+ method: 'POST',
298
+ url: '/search',
299
+ payload: {
300
+ query: 'test',
301
+ limit: 1,
302
+ offset: 0,
303
+ },
304
+ });
305
+ const body = JSON.parse(response.body) as { total: number; entities: AuthorisedEntity[] };
306
+
307
+ expect(response.statusCode).toBe(200);
308
+ expect(body.entities.length).toBeLessThanOrEqual(1);
309
+ });
310
+
311
+ it('should sort entities by id', async () => {
312
+ const app = getTestApp();
313
+
314
+ const response = await app.inject({
315
+ method: 'POST',
316
+ url: '/search',
317
+ payload: {
318
+ query: 'test',
319
+ sort: 'id',
320
+ },
321
+ });
322
+ const body = JSON.parse(response.body) as { total: number; entities: AuthorisedEntity[] };
323
+
324
+ expect(response.statusCode).toBe(200);
325
+ expect(body.entities[0].name).toBe('Test Collection');
326
+ expect(body.entities[1].name).toBe('Test Object');
327
+ expect(body.entities[2].name).toBe('Test Person');
328
+ });
329
+
330
+ it('should filter search results by File entityType', async () => {
331
+ const app = getTestApp();
332
+
333
+ const response = await app.inject({
334
+ method: 'POST',
335
+ url: '/search',
336
+ payload: {
337
+ query: 'test',
338
+ searchType: 'basic',
339
+ filters: {
340
+ entityType: ['http://schema.org/MediaObject'],
341
+ },
342
+ },
343
+ });
344
+ const body = JSON.parse(response.body) as { total: number; entities: AuthorisedEntity[] };
345
+
346
+ expect(response.statusCode).toBe(200);
347
+ expect(body.entities.every((e) => e.entityType === 'http://schema.org/MediaObject')).toBe(true);
348
+ });
349
+
350
+ it('should search for File entities by name', async () => {
351
+ const app = getTestApp();
352
+
353
+ const response = await app.inject({
354
+ method: 'POST',
355
+ url: '/search',
356
+ payload: {
357
+ query: 'audio',
358
+ searchType: 'basic',
359
+ },
360
+ });
361
+ const body = JSON.parse(response.body) as { total: number; entities: AuthorisedEntity[] };
362
+
363
+ expect(response.statusCode).toBe(200);
364
+ expect(body.total).toBeGreaterThan(0);
365
+ const audioFile = body.entities.find((e) => e.name === 'test-audio.wav');
366
+ expect(audioFile).toBeDefined();
367
+ expect(audioFile?.entityType).toBe('http://schema.org/MediaObject');
368
+ });
369
+ });
370
+
371
+ describe('Error Handling', () => {
372
+ it('should handle invalid entity ID format', async () => {
373
+ const app = getTestApp();
374
+
375
+ const response = await app.inject({
376
+ method: 'GET',
377
+ url: '/entity/invalid-id',
378
+ });
379
+ const body = JSON.parse(response.body) as StandardErrorResponse;
380
+
381
+ expect(response.statusCode).toBe(400);
382
+ expect(body.error.code).toBe('VALIDATION_ERROR');
383
+ });
384
+
385
+ it('should handle invalid query parameters for entities', async () => {
386
+ const app = getTestApp();
387
+
388
+ const response = await app.inject({
389
+ method: 'GET',
390
+ url: '/entities',
391
+ query: {
392
+ limit: '-1',
393
+ },
394
+ });
395
+
396
+ expect(response.statusCode).toBe(400);
397
+ });
398
+
399
+ it('should handle missing search query', async () => {
400
+ const app = getTestApp();
401
+
402
+ const response = await app.inject({
403
+ method: 'POST',
404
+ url: '/search',
405
+ payload: {},
406
+ });
407
+
408
+ expect(response.statusCode).toBe(400);
409
+ });
410
+ });
411
+ });
@@ -0,0 +1,199 @@
1
+ import { describe, expect, it } from 'vitest';
2
+ import type { Entity } from '../generated/prisma/client.js';
3
+ import { AllPublicAccessTransformer, baseEntityTransformer } from './default.js';
4
+
5
+ describe('baseEntityTransformer', () => {
6
+ it('should transform entity to standard entity shape', () => {
7
+ const entity: Entity = {
8
+ id: 1,
9
+ rocrateId: 'http://example.com/entity/123',
10
+ name: 'Test Entity',
11
+ description: 'A test entity description',
12
+ entityType: 'http://pcdm.org/models#Collection',
13
+ fileId: null,
14
+ memberOf: 'http://example.com/parent',
15
+ rootCollection: 'http://example.com/root',
16
+ metadataLicenseId: 'https://creativecommons.org/licenses/by/4.0/',
17
+ contentLicenseId: 'https://creativecommons.org/licenses/by-sa/4.0/',
18
+ createdAt: new Date('2025-01-01'),
19
+ updatedAt: new Date('2025-01-02'),
20
+ rocrate: { '@context': 'test' },
21
+ meta: { test: 'data' },
22
+ };
23
+
24
+ const result = baseEntityTransformer(entity);
25
+
26
+ expect(result).toEqual({
27
+ id: 'http://example.com/entity/123',
28
+ name: 'Test Entity',
29
+ description: 'A test entity description',
30
+ entityType: 'http://pcdm.org/models#Collection',
31
+ memberOf: 'http://example.com/parent',
32
+ rootCollection: 'http://example.com/root',
33
+ metadataLicenseId: 'https://creativecommons.org/licenses/by/4.0/',
34
+ contentLicenseId: 'https://creativecommons.org/licenses/by-sa/4.0/',
35
+ });
36
+ });
37
+
38
+ it('should handle null memberOf and rootCollection', () => {
39
+ const entity: Entity = {
40
+ id: 1,
41
+ rocrateId: 'http://example.com/collection',
42
+ name: 'Top Collection',
43
+ description: 'A top-level collection',
44
+ entityType: 'http://pcdm.org/models#Collection',
45
+ fileId: null,
46
+ memberOf: null,
47
+ rootCollection: null,
48
+ metadataLicenseId: 'https://creativecommons.org/licenses/by/4.0/',
49
+ contentLicenseId: 'https://creativecommons.org/licenses/by/4.0/',
50
+ createdAt: new Date(),
51
+ updatedAt: new Date(),
52
+ rocrate: {},
53
+ meta: null,
54
+ };
55
+
56
+ const result = baseEntityTransformer(entity);
57
+
58
+ expect(result.memberOf).toBeNull();
59
+ expect(result.rootCollection).toBeNull();
60
+ });
61
+
62
+ it('should exclude database-specific fields', () => {
63
+ const entity: Entity = {
64
+ id: 1,
65
+ rocrateId: 'http://example.com/entity/456',
66
+ name: 'Test',
67
+ description: 'Test',
68
+ entityType: 'http://pcdm.org/models#Object',
69
+ fileId: null,
70
+ memberOf: null,
71
+ rootCollection: null,
72
+ metadataLicenseId: 'https://creativecommons.org/licenses/by/4.0/',
73
+ contentLicenseId: 'https://creativecommons.org/licenses/by/4.0/',
74
+ createdAt: new Date(),
75
+ updatedAt: new Date(),
76
+ rocrate: { test: 'value' },
77
+ meta: { storage: 'path' },
78
+ };
79
+
80
+ const result = baseEntityTransformer(entity);
81
+
82
+ // Result should have 'id' (mapped from rocrateId), but not the numeric database id
83
+ expect(result.id).toBe('http://example.com/entity/456');
84
+ expect(result).not.toHaveProperty('createdAt');
85
+ expect(result).not.toHaveProperty('updatedAt');
86
+ expect(result).not.toHaveProperty('rocrate');
87
+ expect(result).not.toHaveProperty('meta');
88
+ expect(Object.keys(result)).toEqual([
89
+ 'id',
90
+ 'name',
91
+ 'description',
92
+ 'entityType',
93
+ 'memberOf',
94
+ 'rootCollection',
95
+ 'metadataLicenseId',
96
+ 'contentLicenseId',
97
+ ]);
98
+ });
99
+
100
+ it('should handle File entity (MediaObject) with fileId', () => {
101
+ const entity: Entity = {
102
+ id: 1,
103
+ rocrateId: 'http://example.com/file/audio.wav',
104
+ name: 'Audio File',
105
+ description: 'An audio recording',
106
+ entityType: 'http://schema.org/MediaObject',
107
+ fileId: 'http://example.com/files/audio.wav',
108
+ memberOf: 'http://example.com/collection',
109
+ rootCollection: 'http://example.com/collection',
110
+ metadataLicenseId: 'https://creativecommons.org/licenses/by/4.0/',
111
+ contentLicenseId: 'https://creativecommons.org/licenses/by/4.0/',
112
+ createdAt: new Date(),
113
+ updatedAt: new Date(),
114
+ rocrate: {},
115
+ meta: null,
116
+ };
117
+
118
+ const result = baseEntityTransformer(entity);
119
+
120
+ expect(result).toEqual({
121
+ id: 'http://example.com/file/audio.wav',
122
+ name: 'Audio File',
123
+ description: 'An audio recording',
124
+ entityType: 'http://schema.org/MediaObject',
125
+ fileId: 'http://example.com/files/audio.wav',
126
+ memberOf: 'http://example.com/collection',
127
+ rootCollection: 'http://example.com/collection',
128
+ metadataLicenseId: 'https://creativecommons.org/licenses/by/4.0/',
129
+ contentLicenseId: 'https://creativecommons.org/licenses/by/4.0/',
130
+ });
131
+ expect(result.fileId).toBe('http://example.com/files/audio.wav');
132
+ });
133
+ });
134
+
135
+ describe('AllPublicAccessTransformer', () => {
136
+ it('should grant full access to metadata and content', () => {
137
+ const standardEntity = {
138
+ id: 'http://example.com/entity/123',
139
+ name: 'Test Entity',
140
+ description: 'A test entity',
141
+ entityType: 'http://schema.org/MediaObject',
142
+ memberOf: 'http://example.com/parent',
143
+ rootCollection: 'http://example.com/root',
144
+ metadataLicenseId: 'https://creativecommons.org/licenses/by/4.0/',
145
+ contentLicenseId: 'https://creativecommons.org/licenses/by/4.0/',
146
+ };
147
+
148
+ const result = AllPublicAccessTransformer(standardEntity);
149
+
150
+ expect(result).toEqual({
151
+ ...standardEntity,
152
+ access: {
153
+ metadata: true,
154
+ content: true,
155
+ },
156
+ });
157
+ });
158
+
159
+ it('should preserve all standard entity fields', () => {
160
+ const standardEntity = {
161
+ id: 'http://example.com/entity/789',
162
+ name: 'Another Entity',
163
+ description: 'Another description',
164
+ entityType: 'http://schema.org/Person',
165
+ memberOf: null,
166
+ rootCollection: null,
167
+ metadataLicenseId: 'https://creativecommons.org/publicdomain/zero/1.0/',
168
+ contentLicenseId: 'https://creativecommons.org/publicdomain/zero/1.0/',
169
+ };
170
+
171
+ const result = AllPublicAccessTransformer(standardEntity);
172
+
173
+ expect(result.id).toBe(standardEntity.id);
174
+ expect(result.name).toBe(standardEntity.name);
175
+ expect(result.description).toBe(standardEntity.description);
176
+ expect(result.entityType).toBe(standardEntity.entityType);
177
+ expect(result.memberOf).toBe(standardEntity.memberOf);
178
+ expect(result.rootCollection).toBe(standardEntity.rootCollection);
179
+ expect(result.metadataLicenseId).toBe(standardEntity.metadataLicenseId);
180
+ expect(result.contentLicenseId).toBe(standardEntity.contentLicenseId);
181
+ });
182
+
183
+ it('should not add contentAuthorizationUrl for public access', () => {
184
+ const standardEntity = {
185
+ id: 'http://example.com/entity/public',
186
+ name: 'Public Entity',
187
+ description: 'Fully public',
188
+ entityType: 'http://pcdm.org/models#Collection',
189
+ memberOf: null,
190
+ rootCollection: null,
191
+ metadataLicenseId: 'https://creativecommons.org/licenses/by/4.0/',
192
+ contentLicenseId: 'https://creativecommons.org/licenses/by/4.0/',
193
+ };
194
+
195
+ const result = AllPublicAccessTransformer(standardEntity);
196
+
197
+ expect(result.access.contentAuthorizationUrl).toBeUndefined();
198
+ });
199
+ });