Skip to content

Commit

Permalink
feat(api): use toDomainForVerification method in element-repository WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
reibecca committed May 17, 2024
1 parent 7981dbe commit 3d4dfee
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ async function getById({ moduleId, elementId, moduleDatasource }) {
throw new NotFoundError();
}

const module = Module.toDomain(moduleData);
const module = Module.toDomainForVerification(moduleData);
const grain = module.getGrainByElementId(elementId);
return grain.getElementById(elementId);
} catch (e) {
Expand Down
2 changes: 2 additions & 0 deletions api/src/devcomp/infrastructure/repositories/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { injectDependencies } from '../../../shared/infrastructure/utils/dependency-injection.js';
import moduleDatasource from '../datasources/learning-content/module-datasource.js';
import * as elementAnswerRepository from './element-answer-repository.js';
import * as elementRepository from './element-repository.js';
import * as moduleRepository from './module-repository.js';
import * as passageRepository from './passage-repository.js';
import * as trainingRepository from './training-repository.js';
Expand All @@ -12,6 +13,7 @@ import * as userSavedTutorialRepository from './user-saved-tutorial-repository.j

const repositoriesWithoutInjectedDependencies = {
elementAnswerRepository,
elementRepository,
moduleRepository,
passageRepository,
trainingRepository,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Text } from '../../../../src/devcomp/domain/models/element/Text.js';
import { QCUForAnswerVerification } from '../../../../src/devcomp/domain/models/element/QCU-for-answer-verification.js';
import moduleDatasource from '../../../../src/devcomp/infrastructure/datasources/learning-content/module-datasource.js';
import * as elementRepository from '../../../../src/devcomp/infrastructure/repositories/element-repository.js';
import { NotFoundError } from '../../../../src/shared/domain/errors.js';
Expand All @@ -8,20 +8,34 @@ describe('Integration | DevComp | Repositories | ElementRepository', function ()
describe('#getById', function () {
it('should return the element', async function () {
// given
const moduleId = 'adresse-ip-publique-et-vous';
const elementId = '67b68f2a-349d-4df7-90a5-c9f5dc930a1a';
const element = new Text({
const moduleId = 'didacticiel-modulix';
const elementId = '71de6394-ff88-4de3-8834-a40057a50ff4';
const element = new QCUForAnswerVerification({
id: elementId,
type: 'text',
content:
'<p> Voici la page de résultats d\'une recherche en ligne sur des recettes végétariennes.<span aria-hidden="true">🥗</span>️<br>Le moteur de recherche indique que l\'utilisateur se trouve actuellement vers Toulouse.</p>',
type: 'qcu',
instruction: '<p>Pix évalue 16 compétences numériques différentes.</p>',
proposals: [
{
id: '1',
content: 'Vrai',
},
{
id: '2',
content: 'Faux',
},
],
feedbacks: {
valid: '<p>Correct&#8239;! Ces 16 compétences sont rangées dans 5 domaines.</p>',
invalid: '<p>Incorrect. Retourner voir la vidéo si besoin&nbsp;<span aria-hidden="true">👆</span>️!</p>',
},
solution: '1',
});

// when
const foundElement = await elementRepository.getById({ moduleId, elementId, moduleDatasource });

// then
expect(foundElement).to.be.instanceof(Text);
expect(foundElement).to.be.instanceof(QCUForAnswerVerification);
expect(foundElement).to.deep.equal(element);
});

Expand Down

0 comments on commit 3d4dfee

Please sign in to comment.