Skip to content

Commit 942a31e

Browse files
[TECH] Arrêter d'utiliser l'Orm-model Bookshelf Answer (PIX-2833)
2 parents cf9ba5f + b8fcd3b commit 942a31e

11 files changed

+38
-857
lines changed

api/lib/domain/services/challenge-service.js

-60
This file was deleted.

api/lib/domain/services/solution-service.js

-93
This file was deleted.

api/lib/infrastructure/repositories/solution-repository.js

-10
This file was deleted.

api/tests/acceptance/application/answers/answer-controller-save_test.js

+18-23
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
const { expect, knex, databaseBuilder, mockLearningContent, generateValidRequestAuthorizationHeader } = require('../../../test-helper');
22
const createServer = require('../../../../server');
3-
const BookshelfAnswer = require('../../../../lib/infrastructure/orm-models/Answer');
43
const { FRENCH_FRANCE, ENGLISH_SPOKEN } = require('../../../../lib/domain/constants').LOCALE;
54

65
describe('Acceptance | Controller | answer-controller-save', () => {
@@ -122,8 +121,8 @@ describe('Acceptance | Controller | answer-controller-save', () => {
122121
await server.inject(postAnswersOptions);
123122

124123
// then .
125-
const afterAnswersNumber = await BookshelfAnswer.count();
126-
expect(afterAnswersNumber).to.equal(1);
124+
const { count } = await knex('answers').count().first();
125+
expect(count).to.equal(1);
127126
});
128127

129128
it('should add a new answer with timeSpent into the database', async () => {
@@ -132,10 +131,8 @@ describe('Acceptance | Controller | answer-controller-save', () => {
132131

133132
// then
134133
const answer = response.result.data;
135-
136-
const model = await BookshelfAnswer.where({ id: answer.id }).fetch();
137-
138-
expect(model.get('timeSpent')).not.to.be.null;
134+
const { timeSpent } = await knex('answers').where({ id: answer.id }).first();
135+
expect(timeSpent).not.to.be.null;
139136
});
140137

141138
it('should return persisted answer', async () => {
@@ -144,23 +141,21 @@ describe('Acceptance | Controller | answer-controller-save', () => {
144141

145142
// then
146143
const answer = response.result.data;
147-
148-
const model = await BookshelfAnswer.where({ id: answer.id }).fetch();
149-
150-
expect(model.id).to.be.a('number');
151-
expect(model.get('value')).to.equal(postAnswersOptions.payload.data.attributes.value);
152-
expect(model.get('result')).to.equal('ok');
153-
expect(model.get('resultDetails')).to.equal('null\n');
154-
expect(model.get('assessmentId')).to.equal(postAnswersOptions.payload.data.relationships.assessment.data.id);
155-
expect(model.get('challengeId')).to.equal(postAnswersOptions.payload.data.relationships.challenge.data.id);
156-
157-
expect(answer.id).to.equal(model.id.toString());
144+
const answerDB = await knex('answers').where({ id: answer.id }).first();
145+
expect(answerDB.id).to.be.a('number');
146+
expect(answerDB.value).to.equal(postAnswersOptions.payload.data.attributes.value);
147+
expect(answerDB.result).to.equal('ok');
148+
expect(answerDB.resultDetails).to.equal('null\n');
149+
expect(answerDB.assessmentId).to.equal(postAnswersOptions.payload.data.relationships.assessment.data.id);
150+
expect(answerDB.challengeId).to.equal(postAnswersOptions.payload.data.relationships.challenge.data.id);
151+
152+
expect(answer.id).to.equal(answerDB.id.toString());
158153
expect(answer.id).to.equal(response.result.data.id.toString());
159-
expect(answer.attributes.value).to.equal(model.get('value'));
160-
expect(answer.attributes.result).to.equal(model.get('result'));
161-
expect(answer.attributes['result-details']).to.equal(model.get('resultDetails'));
162-
expect(answer.relationships.assessment.data.id).to.equal(model.get('assessmentId').toString());
163-
expect(answer.relationships.challenge.data.id).to.equal(model.get('challengeId'));
154+
expect(answer.attributes.value).to.equal(answerDB.value);
155+
expect(answer.attributes.result).to.equal(answerDB.result);
156+
expect(answer.attributes['result-details']).to.equal(answerDB.resultDetails);
157+
expect(answer.relationships.assessment.data.id).to.equal(answerDB.assessmentId.toString());
158+
expect(answer.relationships.challenge.data.id).to.equal(answerDB.challengeId);
164159
});
165160

166161
[

api/tests/integration/domain/services/smart-random/solution-service-function-revalidate_test.js

-103
This file was deleted.

0 commit comments

Comments
 (0)