arocapi 5.0.0-beta.5 → 5.0.0-beta.7
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/LICENSE.md +1 -1
- package/README.md +2 -2
- package/dist/app.d.ts +22 -17
- package/dist/app.js +22 -16
- package/dist/app.js.map +1 -1
- package/dist/routes/capabilities.d.ts +2 -2
- package/dist/routes/capabilities.js +2 -2
- package/dist/routes/capabilities.js.map +1 -1
- package/dist/routes/entities.js +8 -9
- package/dist/routes/entities.js.map +1 -1
- package/dist/routes/file.d.ts +2 -2
- package/dist/routes/file.js +25 -72
- package/dist/routes/file.js.map +1 -1
- package/dist/routes/metadata.d.ts +5 -5
- package/dist/routes/metadata.js +22 -61
- package/dist/routes/metadata.js.map +1 -1
- package/dist/routes/search.d.ts +2 -4
- package/dist/routes/search.js +75 -97
- package/dist/routes/search.js.map +1 -1
- package/dist/search/advanced.d.ts +8 -0
- package/dist/search/advanced.js +198 -0
- package/dist/search/advanced.js.map +1 -0
- package/dist/search/backend.d.ts +95 -0
- package/dist/search/backend.js +5 -0
- package/dist/search/backend.js.map +1 -0
- package/dist/search/fields.d.ts +63 -0
- package/dist/search/fields.js +203 -0
- package/dist/search/fields.js.map +1 -0
- package/dist/search/opensearch/advanced.d.ts +4 -0
- package/dist/search/opensearch/advanced.js +28 -0
- package/dist/search/opensearch/advanced.js.map +1 -0
- package/dist/search/opensearch/opensearch.d.ts +16 -0
- package/dist/search/opensearch/opensearch.js +187 -0
- package/dist/search/opensearch/opensearch.js.map +1 -0
- package/dist/search/opensearch/visibility.d.ts +3 -0
- package/dist/search/opensearch/visibility.js +27 -0
- package/dist/search/opensearch/visibility.js.map +1 -0
- package/dist/search/postgres/advanced.d.ts +7 -0
- package/dist/search/postgres/advanced.js +54 -0
- package/dist/search/postgres/advanced.js.map +1 -0
- package/dist/search/postgres/facets.d.ts +2 -0
- package/dist/search/postgres/facets.js +27 -0
- package/dist/search/postgres/facets.js.map +1 -0
- package/dist/search/postgres/geo.d.ts +6 -0
- package/dist/search/postgres/geo.js +42 -0
- package/dist/search/postgres/geo.js.map +1 -0
- package/dist/search/postgres/postgres.d.ts +19 -0
- package/dist/search/postgres/postgres.js +157 -0
- package/dist/search/postgres/postgres.js.map +1 -0
- package/dist/search/postgres/values.d.ts +8 -0
- package/dist/search/postgres/values.js +20 -0
- package/dist/search/postgres/values.js.map +1 -0
- package/dist/search/postgres/visibility.d.ts +4 -0
- package/dist/search/postgres/visibility.js +38 -0
- package/dist/search/postgres/visibility.js.map +1 -0
- package/dist/search/requestFilters.d.ts +39 -0
- package/dist/search/requestFilters.js +125 -0
- package/dist/search/requestFilters.js.map +1 -0
- package/dist/search/visibility.d.ts +51 -0
- package/dist/search/visibility.js +100 -0
- package/dist/search/visibility.js.map +1 -0
- package/dist/storage/backend.d.ts +58 -0
- package/dist/storage/backend.js +2 -0
- package/dist/storage/backend.js.map +1 -0
- package/dist/storage/deliver.d.ts +12 -0
- package/dist/storage/deliver.js +34 -0
- package/dist/storage/deliver.js.map +1 -0
- package/dist/storage/directory/directory.d.ts +6 -0
- package/dist/storage/directory/directory.js +24 -0
- package/dist/storage/directory/directory.js.map +1 -0
- package/dist/storage/entity-meta/entity-meta.d.ts +5 -0
- package/dist/storage/entity-meta/entity-meta.js +14 -0
- package/dist/storage/entity-meta/entity-meta.js.map +1 -0
- package/dist/storage/location.d.ts +20 -0
- package/dist/storage/location.js +40 -0
- package/dist/storage/location.js.map +1 -0
- package/dist/storage/ocfl/ocfl.d.ts +7 -0
- package/dist/storage/ocfl/ocfl.js +79 -0
- package/dist/storage/ocfl/ocfl.js.map +1 -0
- package/dist/storage/ocfl/ocflFs.d.ts +7 -0
- package/dist/storage/ocfl/ocflFs.js +33 -0
- package/dist/storage/ocfl/ocflFs.js.map +1 -0
- package/dist/storage/results.d.ts +7 -0
- package/dist/storage/results.js +22 -0
- package/dist/storage/results.js.map +1 -0
- package/dist/storage/s3/s3.d.ts +10 -0
- package/dist/storage/s3/s3.js +47 -0
- package/dist/storage/s3/s3.js.map +1 -0
- package/dist/types/visibility.d.ts +3 -2
- package/dist/utils/visibility.js +1 -1
- package/dist/utils/visibility.js.map +1 -1
- package/package.json +66 -26
- package/prisma/models/entity.prisma +9 -8
- package/prisma/models/entitySearch.prisma +21 -0
- package/prisma/models/file.prisma +3 -3
- package/src/app.ts +85 -48
- package/src/routes/capabilities.ts +4 -4
- package/src/routes/entities.ts +10 -9
- package/src/routes/file.ts +23 -99
- package/src/routes/metadata.ts +24 -86
- package/src/routes/search.ts +104 -118
- package/src/search/advanced.ts +258 -0
- package/src/search/backend.ts +91 -0
- package/src/search/fields.ts +320 -0
- package/src/search/opensearch/advanced.ts +36 -0
- package/src/search/opensearch/opensearch.ts +290 -0
- package/src/search/opensearch/visibility.ts +38 -0
- package/src/search/postgres/advanced.ts +76 -0
- package/src/search/postgres/facets.ts +34 -0
- package/src/search/postgres/geo.ts +58 -0
- package/src/search/postgres/postgres.ts +232 -0
- package/src/search/postgres/values.ts +33 -0
- package/src/search/postgres/visibility.ts +54 -0
- package/src/search/requestFilters.ts +178 -0
- package/src/search/visibility.ts +193 -0
- package/src/storage/backend.ts +75 -0
- package/src/storage/deliver.ts +65 -0
- package/src/storage/directory/directory.ts +39 -0
- package/src/storage/entity-meta/entity-meta.ts +25 -0
- package/src/storage/location.ts +85 -0
- package/src/storage/ocfl/ocfl.ts +129 -0
- package/src/storage/ocfl/ocflFs.ts +67 -0
- package/src/storage/results.ts +32 -0
- package/src/storage/s3/s3.ts +79 -0
- package/src/types/visibility.ts +6 -3
- package/src/utils/visibility.ts +1 -1
- package/dist/app.test.d.ts +0 -1
- package/dist/app.test.js +0 -67
- package/dist/app.test.js.map +0 -1
- package/dist/errorHandling.test.d.ts +0 -1
- package/dist/errorHandling.test.js +0 -222
- package/dist/errorHandling.test.js.map +0 -1
- package/dist/index.dev.d.ts +0 -1
- package/dist/index.dev.js +0 -157
- package/dist/index.dev.js.map +0 -1
- package/dist/routes/capabilities.test.d.ts +0 -1
- package/dist/routes/capabilities.test.js +0 -81
- package/dist/routes/capabilities.test.js.map +0 -1
- package/dist/routes/crate.test.d.ts +0 -1
- package/dist/routes/crate.test.js +0 -390
- package/dist/routes/crate.test.js.map +0 -1
- package/dist/routes/entities.test.d.ts +0 -1
- package/dist/routes/entities.test.js +0 -277
- package/dist/routes/entities.test.js.map +0 -1
- package/dist/routes/entity.test.d.ts +0 -1
- package/dist/routes/entity.test.js +0 -136
- package/dist/routes/entity.test.js.map +0 -1
- package/dist/routes/file.test.d.ts +0 -1
- package/dist/routes/file.test.js +0 -435
- package/dist/routes/file.test.js.map +0 -1
- package/dist/routes/files.test.d.ts +0 -1
- package/dist/routes/files.test.js +0 -245
- package/dist/routes/files.test.js.map +0 -1
- package/dist/routes/search.test.d.ts +0 -1
- package/dist/routes/search.test.js +0 -833
- package/dist/routes/search.test.js.map +0 -1
- package/dist/test/helpers/fastify.d.ts +0 -9
- package/dist/test/helpers/fastify.js +0 -17
- package/dist/test/helpers/fastify.js.map +0 -1
- package/dist/test/integration.setup.d.ts +0 -47
- package/dist/test/integration.setup.js +0 -195
- package/dist/test/integration.setup.js.map +0 -1
- package/dist/test/integration.test.d.ts +0 -1
- package/dist/test/integration.test.js +0 -762
- package/dist/test/integration.test.js.map +0 -1
- package/dist/transformers/default.test.d.ts +0 -1
- package/dist/transformers/default.test.js +0 -225
- package/dist/transformers/default.test.js.map +0 -1
- package/dist/transformers/transformer.test.d.ts +0 -1
- package/dist/transformers/transformer.test.js +0 -165
- package/dist/transformers/transformer.test.js.map +0 -1
- package/dist/types/fileHandlers.d.ts +0 -37
- package/dist/types/fileHandlers.js +0 -2
- package/dist/types/fileHandlers.js.map +0 -1
- package/dist/utils/errors.test.d.ts +0 -1
- package/dist/utils/errors.test.js +0 -79
- package/dist/utils/errors.test.js.map +0 -1
- package/dist/utils/queryBuilder.d.ts +0 -47
- package/dist/utils/queryBuilder.js +0 -107
- package/dist/utils/queryBuilder.js.map +0 -1
- package/prisma.config.ts +0 -9
- package/src/app.test.ts +0 -91
- package/src/errorHandling.test.ts +0 -288
- package/src/index.dev.ts +0 -202
- package/src/reset.d.ts +0 -1
- package/src/routes/__snapshots__/capabilities.test.ts.snap +0 -34
- package/src/routes/__snapshots__/entities.test.ts.snap +0 -96
- package/src/routes/__snapshots__/entity.test.ts.snap +0 -74
- package/src/routes/__snapshots__/search.test.ts.snap +0 -165
- package/src/routes/capabilities.test.ts +0 -102
- package/src/routes/crate.test.ts +0 -484
- package/src/routes/entities.test.ts +0 -324
- package/src/routes/entity.test.ts +0 -166
- package/src/routes/file.test.ts +0 -538
- package/src/routes/files.test.ts +0 -304
- package/src/routes/search.test.ts +0 -959
- package/src/test/__snapshots__/integration.test.ts.snap +0 -18
- package/src/test/helpers/fastify.ts +0 -26
- package/src/test/integration.setup.ts +0 -220
- package/src/test/integration.test.ts +0 -953
- package/src/transformers/default.test.ts +0 -276
- package/src/transformers/transformer.test.ts +0 -226
- package/src/types/fileHandlers.ts +0 -57
- package/src/utils/errors.test.ts +0 -90
- package/src/utils/queryBuilder.ts +0 -157
package/src/routes/files.test.ts
DELETED
|
@@ -1,304 +0,0 @@
|
|
|
1
|
-
import { afterEach, beforeEach, describe, expect, it } from 'vitest';
|
|
2
|
-
import type { AccessFunction, FileTransformer } from '../app.js';
|
|
3
|
-
import { fastify, fastifyAfter, fastifyBefore, prisma } from '../test/helpers/fastify.js';
|
|
4
|
-
import { AllPublicAccess } from '../utils/access.js';
|
|
5
|
-
import type { StandardErrorResponse } from '../utils/errors.js';
|
|
6
|
-
import { AllVisibleEntityFilter } from '../utils/visibility.js';
|
|
7
|
-
import filesRoute from './files.js';
|
|
8
|
-
|
|
9
|
-
describe('Files Route', () => {
|
|
10
|
-
const mockEntity = (id: string, name: string) => ({
|
|
11
|
-
id,
|
|
12
|
-
name,
|
|
13
|
-
description: '',
|
|
14
|
-
entityType: 'http://schema.org/MediaObject',
|
|
15
|
-
memberOf: null,
|
|
16
|
-
rootCollection: null,
|
|
17
|
-
metadataLicenseId: 'https://creativecommons.org/licenses/by/4.0/',
|
|
18
|
-
contentLicenseId: 'https://creativecommons.org/licenses/by/4.0/',
|
|
19
|
-
meta: {},
|
|
20
|
-
createdAt: new Date('2025-01-01'),
|
|
21
|
-
updatedAt: new Date('2025-01-01'),
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
beforeEach(async () => {
|
|
25
|
-
await fastifyBefore();
|
|
26
|
-
await fastify.register(filesRoute, {
|
|
27
|
-
entityVisibilityFilter: AllVisibleEntityFilter,
|
|
28
|
-
prisma,
|
|
29
|
-
access: AllPublicAccess,
|
|
30
|
-
});
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
afterEach(async () => {
|
|
34
|
-
await fastifyAfter();
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
const mockFile1 = {
|
|
38
|
-
id: 'http://example.com/file1.wav',
|
|
39
|
-
filename: 'file1.wav',
|
|
40
|
-
mediaType: 'audio/wav',
|
|
41
|
-
size: BigInt(1024),
|
|
42
|
-
meta: {},
|
|
43
|
-
createdAt: new Date('2025-01-01'),
|
|
44
|
-
updatedAt: new Date('2025-01-01'),
|
|
45
|
-
entity: mockEntity('http://example.com/file1.wav', 'file1.wav'),
|
|
46
|
-
};
|
|
47
|
-
|
|
48
|
-
const mockFile2 = {
|
|
49
|
-
id: 'http://example.com/file2.txt',
|
|
50
|
-
filename: 'file2.txt',
|
|
51
|
-
mediaType: 'text/plain',
|
|
52
|
-
size: BigInt(512),
|
|
53
|
-
meta: {},
|
|
54
|
-
createdAt: new Date('2025-01-02'),
|
|
55
|
-
updatedAt: new Date('2025-01-02'),
|
|
56
|
-
entity: mockEntity('http://example.com/file2.txt', 'file2.txt'),
|
|
57
|
-
};
|
|
58
|
-
|
|
59
|
-
describe('GET /files', () => {
|
|
60
|
-
it('should list all files successfully', async () => {
|
|
61
|
-
prisma.file.findMany.mockResolvedValue([mockFile1, mockFile2]);
|
|
62
|
-
prisma.file.count.mockResolvedValue(2);
|
|
63
|
-
|
|
64
|
-
const response = await fastify.inject({
|
|
65
|
-
method: 'GET',
|
|
66
|
-
url: '/files',
|
|
67
|
-
});
|
|
68
|
-
|
|
69
|
-
expect(response.statusCode).toBe(200);
|
|
70
|
-
const body = JSON.parse(response.body) as { total: number; files: unknown[] };
|
|
71
|
-
expect(body.total).toBe(2);
|
|
72
|
-
expect(body.files).toHaveLength(2);
|
|
73
|
-
expect(body.files[0]).toMatchObject({
|
|
74
|
-
id: 'http://example.com/file1.wav',
|
|
75
|
-
filename: 'file1.wav',
|
|
76
|
-
mediaType: 'audio/wav',
|
|
77
|
-
size: 1024,
|
|
78
|
-
access: {
|
|
79
|
-
content: true,
|
|
80
|
-
},
|
|
81
|
-
});
|
|
82
|
-
expect(prisma.file.findMany).toHaveBeenCalledWith(
|
|
83
|
-
expect.objectContaining({ include: { entity: { omit: { meta: true } } } }),
|
|
84
|
-
);
|
|
85
|
-
});
|
|
86
|
-
|
|
87
|
-
it('should filter files by memberOf', async () => {
|
|
88
|
-
prisma.file.findMany.mockResolvedValue([mockFile1]);
|
|
89
|
-
prisma.file.count.mockResolvedValue(1);
|
|
90
|
-
|
|
91
|
-
const response = await fastify.inject({
|
|
92
|
-
method: 'GET',
|
|
93
|
-
url: '/files?memberOf=http://example.com/collection/1',
|
|
94
|
-
});
|
|
95
|
-
|
|
96
|
-
expect(response.statusCode).toBe(200);
|
|
97
|
-
const body = JSON.parse(response.body) as { total: number; files: unknown[] };
|
|
98
|
-
expect(body.total).toBe(1);
|
|
99
|
-
expect(body.files).toHaveLength(1);
|
|
100
|
-
expect(body.files[0]).toMatchObject({
|
|
101
|
-
id: 'http://example.com/file1.wav',
|
|
102
|
-
filename: 'file1.wav',
|
|
103
|
-
});
|
|
104
|
-
expect(prisma.file.findMany).toHaveBeenCalledWith(
|
|
105
|
-
expect.objectContaining({
|
|
106
|
-
where: { entity: { AND: [{ memberOf: 'http://example.com/collection/1' }, {}] } },
|
|
107
|
-
}),
|
|
108
|
-
);
|
|
109
|
-
});
|
|
110
|
-
|
|
111
|
-
it('should support pagination with limit and offset', async () => {
|
|
112
|
-
prisma.file.findMany.mockResolvedValue([mockFile2]);
|
|
113
|
-
prisma.file.count.mockResolvedValue(2);
|
|
114
|
-
|
|
115
|
-
const response = await fastify.inject({
|
|
116
|
-
method: 'GET',
|
|
117
|
-
url: '/files?limit=1&offset=1',
|
|
118
|
-
});
|
|
119
|
-
|
|
120
|
-
expect(response.statusCode).toBe(200);
|
|
121
|
-
const body = JSON.parse(response.body) as { total: number; files: unknown[] };
|
|
122
|
-
expect(body.total).toBe(2);
|
|
123
|
-
expect(body.files).toHaveLength(1);
|
|
124
|
-
expect(prisma.file.findMany).toHaveBeenCalledWith(
|
|
125
|
-
expect.objectContaining({
|
|
126
|
-
skip: 1,
|
|
127
|
-
take: 1,
|
|
128
|
-
}),
|
|
129
|
-
);
|
|
130
|
-
});
|
|
131
|
-
|
|
132
|
-
it('should support sorting by filename ascending', async () => {
|
|
133
|
-
prisma.file.findMany.mockResolvedValue([mockFile1, mockFile2]);
|
|
134
|
-
prisma.file.count.mockResolvedValue(2);
|
|
135
|
-
|
|
136
|
-
const response = await fastify.inject({
|
|
137
|
-
method: 'GET',
|
|
138
|
-
url: '/files?sort=filename&order=asc',
|
|
139
|
-
});
|
|
140
|
-
|
|
141
|
-
expect(response.statusCode).toBe(200);
|
|
142
|
-
expect(prisma.file.findMany).toHaveBeenCalledWith(
|
|
143
|
-
expect.objectContaining({
|
|
144
|
-
orderBy: { filename: 'asc' },
|
|
145
|
-
}),
|
|
146
|
-
);
|
|
147
|
-
});
|
|
148
|
-
|
|
149
|
-
it('should support sorting by id directly', async () => {
|
|
150
|
-
prisma.file.findMany.mockResolvedValue([mockFile1, mockFile2]);
|
|
151
|
-
prisma.file.count.mockResolvedValue(2);
|
|
152
|
-
|
|
153
|
-
const response = await fastify.inject({
|
|
154
|
-
method: 'GET',
|
|
155
|
-
url: '/files?sort=id&order=desc',
|
|
156
|
-
});
|
|
157
|
-
|
|
158
|
-
expect(response.statusCode).toBe(200);
|
|
159
|
-
expect(prisma.file.findMany).toHaveBeenCalledWith(
|
|
160
|
-
expect.objectContaining({
|
|
161
|
-
orderBy: { id: 'desc' },
|
|
162
|
-
}),
|
|
163
|
-
);
|
|
164
|
-
});
|
|
165
|
-
|
|
166
|
-
it('should return empty list when no files found', async () => {
|
|
167
|
-
prisma.file.findMany.mockResolvedValue([]);
|
|
168
|
-
prisma.file.count.mockResolvedValue(0);
|
|
169
|
-
|
|
170
|
-
const response = await fastify.inject({
|
|
171
|
-
method: 'GET',
|
|
172
|
-
url: '/files',
|
|
173
|
-
});
|
|
174
|
-
|
|
175
|
-
expect(response.statusCode).toBe(200);
|
|
176
|
-
const body = JSON.parse(response.body) as { total: number; files: unknown[] };
|
|
177
|
-
expect(body.total).toBe(0);
|
|
178
|
-
expect(body.files).toHaveLength(0);
|
|
179
|
-
});
|
|
180
|
-
|
|
181
|
-
it('should return 500 when database error occurs', async () => {
|
|
182
|
-
prisma.file.findMany.mockRejectedValue(new Error('Database connection failed'));
|
|
183
|
-
|
|
184
|
-
const response = await fastify.inject({
|
|
185
|
-
method: 'GET',
|
|
186
|
-
url: '/files',
|
|
187
|
-
});
|
|
188
|
-
const body = JSON.parse(response.body) as { error: { code: string } };
|
|
189
|
-
|
|
190
|
-
expect(response.statusCode).toBe(500);
|
|
191
|
-
expect(body.error.code).toBe('INTERNAL_ERROR');
|
|
192
|
-
});
|
|
193
|
-
|
|
194
|
-
it('should validate limit parameter', async () => {
|
|
195
|
-
const response = await fastify.inject({
|
|
196
|
-
method: 'GET',
|
|
197
|
-
url: '/files?limit=2000',
|
|
198
|
-
});
|
|
199
|
-
const body = JSON.parse(response.body) as StandardErrorResponse;
|
|
200
|
-
|
|
201
|
-
expect(response.statusCode).toBe(400);
|
|
202
|
-
expect(body.error.code).toBe('VALIDATION_ERROR');
|
|
203
|
-
});
|
|
204
|
-
|
|
205
|
-
it('should validate memberOf parameter format', async () => {
|
|
206
|
-
const response = await fastify.inject({
|
|
207
|
-
method: 'GET',
|
|
208
|
-
url: '/files?memberOf=invalid-url',
|
|
209
|
-
});
|
|
210
|
-
const body = JSON.parse(response.body) as StandardErrorResponse;
|
|
211
|
-
|
|
212
|
-
expect(response.statusCode).toBe(400);
|
|
213
|
-
expect(body.error.code).toBe('VALIDATION_ERROR');
|
|
214
|
-
});
|
|
215
|
-
|
|
216
|
-
it('should validate sort parameter', async () => {
|
|
217
|
-
const response = await fastify.inject({
|
|
218
|
-
method: 'GET',
|
|
219
|
-
url: '/files?sort=invalid',
|
|
220
|
-
});
|
|
221
|
-
const body = JSON.parse(response.body) as StandardErrorResponse;
|
|
222
|
-
|
|
223
|
-
expect(response.statusCode).toBe(400);
|
|
224
|
-
expect(body.error.code).toBe('VALIDATION_ERROR');
|
|
225
|
-
});
|
|
226
|
-
});
|
|
227
|
-
|
|
228
|
-
describe('Custom File Transformers', () => {
|
|
229
|
-
it('should apply custom file transformers', async () => {
|
|
230
|
-
await fastifyBefore();
|
|
231
|
-
|
|
232
|
-
// Custom transformer that adds extra fields
|
|
233
|
-
const customTransformer: FileTransformer = (file) => ({
|
|
234
|
-
...file,
|
|
235
|
-
customField: 'test-value',
|
|
236
|
-
uppercaseFilename: file.filename.toUpperCase(),
|
|
237
|
-
});
|
|
238
|
-
|
|
239
|
-
await fastify.register(filesRoute, {
|
|
240
|
-
entityVisibilityFilter: AllVisibleEntityFilter,
|
|
241
|
-
prisma,
|
|
242
|
-
access: AllPublicAccess,
|
|
243
|
-
fileTransformers: [customTransformer],
|
|
244
|
-
});
|
|
245
|
-
|
|
246
|
-
prisma.file.findMany.mockResolvedValue([mockFile1]);
|
|
247
|
-
prisma.file.count.mockResolvedValue(1);
|
|
248
|
-
|
|
249
|
-
const response = await fastify.inject({
|
|
250
|
-
method: 'GET',
|
|
251
|
-
url: '/files',
|
|
252
|
-
});
|
|
253
|
-
|
|
254
|
-
expect(response.statusCode).toBe(200);
|
|
255
|
-
const body = JSON.parse(response.body) as { files: unknown[] };
|
|
256
|
-
expect(body.files[0]).toMatchObject({
|
|
257
|
-
id: 'http://example.com/file1.wav',
|
|
258
|
-
filename: 'file1.wav',
|
|
259
|
-
customField: 'test-value',
|
|
260
|
-
uppercaseFilename: 'FILE1.WAV',
|
|
261
|
-
});
|
|
262
|
-
|
|
263
|
-
await fastifyAfter();
|
|
264
|
-
});
|
|
265
|
-
|
|
266
|
-
it('should attach the content access of each file entity', async () => {
|
|
267
|
-
await fastifyBefore();
|
|
268
|
-
|
|
269
|
-
const access: AccessFunction = (entity) =>
|
|
270
|
-
entity.id === 'http://example.com/file1.wav'
|
|
271
|
-
? {
|
|
272
|
-
metadata: false,
|
|
273
|
-
content: false,
|
|
274
|
-
metadataAuthorizationUrl: 'https://example.com/request-metadata',
|
|
275
|
-
contentAuthorizationUrl: 'https://example.com/request-access',
|
|
276
|
-
}
|
|
277
|
-
: { metadata: true, content: true };
|
|
278
|
-
|
|
279
|
-
await fastify.register(filesRoute, {
|
|
280
|
-
entityVisibilityFilter: AllVisibleEntityFilter,
|
|
281
|
-
prisma,
|
|
282
|
-
access,
|
|
283
|
-
});
|
|
284
|
-
|
|
285
|
-
prisma.file.findMany.mockResolvedValue([mockFile1, mockFile2]);
|
|
286
|
-
prisma.file.count.mockResolvedValue(2);
|
|
287
|
-
|
|
288
|
-
const response = await fastify.inject({
|
|
289
|
-
method: 'GET',
|
|
290
|
-
url: '/files',
|
|
291
|
-
});
|
|
292
|
-
|
|
293
|
-
expect(response.statusCode).toBe(200);
|
|
294
|
-
const body = JSON.parse(response.body) as { files: Array<{ access: unknown }> };
|
|
295
|
-
expect(body.files[0].access).toEqual({
|
|
296
|
-
content: false,
|
|
297
|
-
contentAuthorizationUrl: 'https://example.com/request-access',
|
|
298
|
-
});
|
|
299
|
-
expect(body.files[1].access).toEqual({ content: true });
|
|
300
|
-
|
|
301
|
-
await fastifyAfter();
|
|
302
|
-
});
|
|
303
|
-
});
|
|
304
|
-
});
|