Skip to content

Commit ece1bbd

Browse files
pyphiliakim
andauthored
fix: fix packed h5p schema to include integrationUrl (#2077)
* fix: fix packed h5p schema to include integrationUrl * refactor: add extended item --------- Co-authored-by: kim <kim.phanhoang@epfl.ch>
1 parent 721c16d commit ece1bbd

3 files changed

Lines changed: 91 additions & 5 deletions

File tree

src/services/item/item.controller.read.test.ts

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import { db } from '../../drizzle/db';
1111
import { assertIsDefined } from '../../utils/assertions';
1212
import { ItemNotFound, MemberCannotAccess } from '../../utils/errors';
1313
import { assertIsMemberForTest } from '../authentication';
14+
import { H5PItem } from './item';
1415
import { type PackedItem, PackedItemDTO } from './packedItem.dto';
1516
import { expectManyPackedItems, expectPackedItem, expectThumbnails } from './test/fixtures/items';
1617
import { Ordering, SortBy } from './types';
@@ -336,7 +337,6 @@ describe('Item routes tests', () => {
336337
],
337338
},
338339
// schema check
339-
340340
{
341341
name: 'app with settings',
342342
type: 'app',
@@ -947,6 +947,46 @@ describe('Item routes tests', () => {
947947
data.forEach((i) => expectThumbnails(i, MOCK_SIGNED_URL, false));
948948
});
949949

950+
it('Returns a child h5p successfully', async () => {
951+
const {
952+
actor,
953+
items: [parentItem],
954+
} = await seedFromJson({
955+
items: [
956+
{
957+
memberships: [{ account: 'actor', permission: 'admin' }],
958+
children: [
959+
{
960+
type: 'h5p',
961+
extra: {
962+
h5p: {
963+
contentId: 'content-id',
964+
h5pFilePath: 'file-path',
965+
contentFilePath: 'content-file-path',
966+
},
967+
},
968+
},
969+
],
970+
},
971+
],
972+
});
973+
assertIsDefined(actor);
974+
assertIsMemberForTest(actor);
975+
mockAuthenticate(actor);
976+
977+
const response = await app.inject({
978+
method: HttpMethod.Get,
979+
url: `/api/items/${parentItem.id}/children`,
980+
});
981+
982+
const data = response.json<PackedItem[]>();
983+
expect(response.statusCode).toBe(StatusCodes.OK);
984+
985+
expect(data).toHaveLength(1);
986+
// expect additionnal packed property
987+
expect((data[0] as H5PItem).extra.h5p.contentFilePath).toBeDefined();
988+
});
989+
950990
it('Returns successfully with thumbnails', async () => {
951991
const {
952992
actor,

src/services/item/item.schemas.packed.ts

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import { embeddedLinkItemSchemaRef } from './plugins/embeddedLink/link.schemas';
1414
import { etherpadItemSchemaRef } from './plugins/etherpad/etherpad.schemas';
1515
import { fileItemSchemaRef } from './plugins/file/itemFile.schema';
1616
import { folderItemSchemaRef } from './plugins/folder/folder.schemas';
17-
import { h5pItemSchemaRef } from './plugins/html/h5p/h5p.schemas';
17+
import { h5pExtendedItemSchema, h5pItemSchemaRef } from './plugins/html/h5p/h5p.schemas';
1818
import { itemVisibilitySchemaRef } from './plugins/itemVisibility/itemVisibility.schemas';
1919
import { pageItemSchemaRef } from './plugins/page/page.schemas';
2020
import { shortcutItemSchemaRef } from './plugins/shortcut/shortcut.schemas';
@@ -69,7 +69,32 @@ export const packedItemSchemaRef = registerSchemaAsRef(
6969
],
7070
{
7171
discriminator: 'type',
72-
description: 'Item with additional information',
72+
description: 'Item with additional information for simple display',
73+
},
74+
),
75+
);
76+
77+
export const extendedItemSchemaRef = registerSchemaAsRef(
78+
'extendedItem',
79+
'Extended Item',
80+
Type.Intersect(
81+
[
82+
Type.Union([
83+
appItemSchemaRef,
84+
documentItemSchemaRef,
85+
embeddedLinkItemSchemaRef,
86+
etherpadItemSchemaRef,
87+
fileItemSchemaRef,
88+
folderItemSchemaRef,
89+
h5pExtendedItemSchema,
90+
pageItemSchemaRef,
91+
shortcutItemSchemaRef,
92+
]),
93+
packedSchema,
94+
],
95+
{
96+
discriminator: 'type',
97+
description: 'Item with extended information useful for complete display',
7398
},
7499
),
75100
);
@@ -83,7 +108,7 @@ export const getOne = {
83108
params: customType.StrictObject({
84109
id: customType.UUID(),
85110
}),
86-
response: { [StatusCodes.OK]: packedItemSchemaRef, '4xx': errorSchemaRef },
111+
response: { [StatusCodes.OK]: extendedItemSchemaRef, '4xx': errorSchemaRef },
87112
} as const satisfies FastifySchema;
88113

89114
export const getAccessible = {
@@ -139,7 +164,7 @@ export const getChildren = {
139164
}),
140165
),
141166
response: {
142-
[StatusCodes.OK]: Type.Array(packedItemSchemaRef),
167+
[StatusCodes.OK]: Type.Array(extendedItemSchemaRef),
143168
'4xx': errorSchemaRef,
144169
},
145170
} as const satisfies FastifySchema;

src/services/item/plugins/html/h5p/h5p.schemas.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,27 @@ const h5pItemSchema = Type.Composite([
2929
),
3030
]);
3131

32+
export const h5pExtendedItemSchema = Type.Composite([
33+
itemCommonSchema,
34+
customType.StrictObject(
35+
{
36+
type: Type.Literal('h5p'),
37+
extra: customType.StrictObject({
38+
h5p: customType.StrictObject({
39+
contentId: Type.String(),
40+
h5pFilePath: Type.String(),
41+
contentFilePath: Type.String(),
42+
integrationUrl: Type.String({ description: 'url of the h5p integration' }),
43+
}),
44+
}),
45+
},
46+
{
47+
title: 'H5P Extended Item',
48+
description: 'Extended item of type H5P.',
49+
},
50+
),
51+
]);
52+
3253
export const h5pItemSchemaRef = registerSchemaAsRef('h5pItem', 'H5P Item', h5pItemSchema);
3354

3455
export const h5pImport = {

0 commit comments

Comments
 (0)