Skip to content

Commit

Permalink
feat(api): add Expand in ModuleFactory
Browse files Browse the repository at this point in the history
Co-authored-by: Clément Latzarus <[email protected]>
Co-authored-by: Eric Lim <[email protected]>
  • Loading branch information
3 people committed Dec 20, 2024
1 parent 46a0d93 commit 1de7c0b
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 0 deletions.
12 changes: 12 additions & 0 deletions api/src/devcomp/infrastructure/factories/module-factory.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { ComponentStepper } from '../../domain/models/component/ComponentStepper
import { Step } from '../../domain/models/component/Step.js';
import { Download } from '../../domain/models/element/Download.js';
import { Embed } from '../../domain/models/element/Embed.js';
import { Expand } from '../../domain/models/element/Expand.js';
import { Card } from '../../domain/models/element/flashcards/Card.js';
import { Flashcards } from '../../domain/models/element/flashcards/Flashcards.js';
import { Image } from '../../domain/models/element/Image.js';
Expand Down Expand Up @@ -91,6 +92,8 @@ export class ModuleFactory {
return ModuleFactory.#buildDownload(element);
case 'embed':
return ModuleFactory.#buildEmbed(element);
case 'expand':
return ModuleFactory.#buildExpand(element);
case 'image':
return ModuleFactory.#buildImage(element);
case 'separator':
Expand All @@ -115,6 +118,7 @@ export class ModuleFactory {
return undefined;
}
}

static #buildDownload(element) {
return new Download({
id: element.id,
Expand All @@ -133,6 +137,14 @@ export class ModuleFactory {
});
}

static #buildExpand(element) {
return new Expand({
id: element.id,
title: element.title,
content: element.content,
});
}

static #buildImage(element) {
return new Image({
id: element.id,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -877,6 +877,53 @@ describe('Unit | Devcomp | Infrastructure | Factories | Module ', function () {
const expectedFlashcards = moduleData.grains[0].components[0].element;
validateFlashcards(flashcards, expectedFlashcards);
});

it('should instantiate a Module with a ComponentElement which contains a Expand Element', function () {
// given
const givenData = {
id: '6282925d-4775-4bca-b513-4c3009ec5886',
slug: 'title',
title: 'title',
isBeta: true,
details: {
image: 'https://images.pix.fr/modulix/placeholder-details.svg',
description: 'Description',
duration: 5,
level: 'Débutant',
tabletSupport: 'comfortable',
objectives: ['Objective 1'],
},
grains: [
{
id: 'f312c33d-e7c9-4a69-9ba0-913957b8f7dd',
type: 'lesson',
title: 'title',
components: [
{
type: 'element',
element: {
id: '71de6394-ff88-4de3-8834-a40057a50ff4',
type: 'expand',
title: "Plus d'info sur la poésie",
content: '<p>La poésie c’est cool</p>',
},
},
],
},
],
};

// when
const module = ModuleFactory.build(givenData);

// then
const expand = module.grains[0].components[0].element;
const expectedExpand = givenData.grains[0].components[0].element;
expect(expand.id).to.equal(expectedExpand.id);
expect(expand.content).to.equal(expectedExpand.content);
expect(expand.title).to.equal(expectedExpand.title);
expect(expand.type).to.equal(expectedExpand.type);
});
});

describe('With ComponentStepper', function () {
Expand Down

0 comments on commit 1de7c0b

Please sign in to comment.