Skip to content

Commit

Permalink
✨ api: update partially an assessmentResult
Browse files Browse the repository at this point in the history
  • Loading branch information
Steph0 authored and matthieu-octo committed Jul 4, 2024
1 parent 35d9a02 commit 24204cd
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { cpfExportsStorage } from '../../infrastructure/storage/cpf-exports-stor
import { cpfReceiptsStorage } from '../../infrastructure/storage/cpf-receipts-storage.js';

/**
* @typedef {import('../../infrastructure/repositories/index.js').AssessmentResultJuryCommentRepository} AssessmentResultJuryCommentRepository
* @typedef {import('../../infrastructure/repositories/index.js').AssessmentResultRepository} AssessmentResultRepository
* @typedef {import('../../infrastructure/repositories/index.js').CertificationCourseRepository} CertificationCourseRepository
* @typedef {import('../../infrastructure/repositories/index.js').CertificationOfficerRepository} CertificationOfficerRepository
* @typedef {import('../../infrastructure/repositories/index.js').FinalizedSessionRepository} FinalizedSessionRepository
Expand All @@ -32,7 +32,7 @@ import { cpfReceiptsStorage } from '../../infrastructure/storage/cpf-receipts-st
* Using {@link https://jsdoc.app/tags-type "Closure Compiler's syntax"} to document injected dependencies
*
* @typedef {assessmentRepository} AssessmentRepository
* @typedef {assessmentResultJuryCommentRepository} AssessmentResultJuryCommentRepository
* @typedef {assessmentResultJuryCommentRepository} AssessmentResultRepository
* @typedef {certificationBadgesService} CertificationBadgesService
* @typedef {certificationCourseRepository} CertificationCourseRepository
* @typedef {certificationChallengeLiveAlertRepository} CertificationChallengeLiveAlertRepository
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
/**
* @typedef {import ('./index.js').AssessmentResultJuryCommentRepository} AssessmentResultJuryCommentRepository
* @typedef {import ('./index.js').AssessmentResultRepository} AssessmentResultRepository
*/

/**
* @param {Object} params
* @param {number} params.certificationCourseId
* @param {string} params.assessmentResultCommentByJury
* @param {number} params.juryId
* @param {AssessmentResultJuryCommentRepository} params.assessmentResultJuryCommentRepository
* @param {AssessmentResultRepository} params.assessmentResultJuryCommentRepository
*/
const updateJuryComment = async function ({
certificationCourseId,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
/**
* @typedef {import ('../../../../shared/domain/models/AssessmentResult.js').AssessmentResult} AssessmentResult
*/

import { knex } from '../../../../../db/knex-database-connection.js';
import { NotFoundError } from '../../../../shared/domain/errors.js';
import { AssessmentResultJuryComment } from '../../domain/models/AssessmentResultJuryComment.js';
Expand All @@ -20,8 +24,14 @@ const getLatestAssessmentResultJuryComment = async function ({ certificationCour
return new AssessmentResultJuryComment(result);
};

const update = async function ({ id, juryId, commentByJury }) {
return knex('assessment-results').update({ juryId, commentByJury }).where({ id });
/**
* @param {object} params
* @param {AssessmentResult} params.assessmentResult
*/
const update = async function ({ assessmentResult }) {
await knex('assessment-results')
.update({ commentByJury: assessmentResult.commentByJury, juryId: assessmentResult.juryId })
.where({ id: assessmentResult.id });
};

export { getLatestAssessmentResultJuryComment, update };
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { injectDependencies } from '../../../../shared/infrastructure/utils/depe
import * as certificationChallengeLiveAlertRepository from '../../../shared/infrastructure/repositories/certification-challenge-live-alert-repository.js';
import * as certificationCourseRepository from '../../../shared/infrastructure/repositories/certification-course-repository.js';
import * as certificationReportRepository from '../../../shared/infrastructure/repositories/certification-report-repository.js';
import * as assessmentResultJuryCommentRepository from './assessment-result-jury-comment-repository.js';
import * as assessmentResultRepository from './assessment-result-repository.js';
import * as certificationOfficerRepository from './certification-officer-repository.js';
import * as finalizedSessionRepository from './finalized-session-repository.js';
import * as jurySessionRepository from './jury-session-repository.js';
Expand All @@ -19,7 +19,7 @@ import * as supervisorAccessRepository from './supervisor-access-repository.js';
* Using {@link https://jsdoc.app/tags-type "Closure Compiler's syntax"} to document injected dependencies
*
* @typedef {assessmentRepository} AssessmentRepository
* @typedef {assessmentResultJuryCommentRepository} AssessmentResultJuryCommentRepository
* @typedef {assessmentResultRepository} AssessmentResultRepository
* @typedef {certificationCourseRepository} CertificationCourseRepository
* @typedef {certificationChallengeLiveAlertRepository} CertificationChallengeLiveAlertRepository
* @typedef {certificationOfficerRepository} CertificationOfficerRepository
Expand All @@ -36,7 +36,7 @@ import * as supervisorAccessRepository from './supervisor-access-repository.js';
*/
const repositoriesWithoutInjectedDependencies = {
assessmentRepository,
assessmentResultJuryCommentRepository,
assessmentResultRepository,
certificationCourseRepository,
certificationChallengeLiveAlertRepository,
certificationOfficerRepository,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { AssessmentResultJuryComment } from '../../../../../../src/certification/session-management/domain/models/AssessmentResultJuryComment.js';
import * as assessmentResultJuryCommentRepository from '../../../../../../src/certification/session-management/infrastructure/repositories/assessment-result-jury-comment-repository.js';
import * as assessmentResultJuryCommentRepository from '../../../../../../src/certification/session-management/infrastructure/repositories/assessment-result-repository.js';
import { NotFoundError } from '../../../../../../src/shared/domain/errors.js';
import { databaseBuilder, expect, knex } from '../../../../../test-helper.js';
import { databaseBuilder, domainBuilder, expect, knex } from '../../../../../test-helper.js';

describe('Integration | Repository | Certification | Session-management | AssessmentResultJuryCommentRepository', function () {
describe('Integration | Repository | Certification | Session-management | AssessmentResultRepository', function () {
describe('#getLatestAssessmentResult', function () {
it('should return the latest assessment result Jury Comment', async function () {
// given
Expand Down Expand Up @@ -43,29 +43,34 @@ describe('Integration | Repository | Certification | Session-management | Assess
});
});

describe('#save', function () {
it('should save the jury id and comment only', async function () {
describe('#update', function () {
it('should save the jury internal note and the juryId', async function () {
// given
databaseBuilder.factory.buildUser({ id: 21 });
databaseBuilder.factory.buildUser({ id: 22 });
databaseBuilder.factory.buildCertificationCourse({ id: 55 });
databaseBuilder.factory.buildAssessment({ id: 51, certificationCourseId: 55 });
const assessmentResult = databaseBuilder.factory.buildAssessmentResult({
const { id: oldJuryId } = databaseBuilder.factory.buildUser({ id: 10 });
const { id: newJuryId } = databaseBuilder.factory.buildUser({ id: 1000 });
databaseBuilder.factory.buildAssessmentResult({
id: 11,
commentByJury: 'Old',
commentByAutoJury: 'otherComment',
juryId: 21,
assessmentId: 51,
juryId: oldJuryId,
});
await databaseBuilder.commit();
const newCommentByJury = 'New';
const assessmentResult = domainBuilder.buildAssessmentResult({
id: 11,
commentByJury: newCommentByJury,
juryId: newJuryId,
});

// when
const latestAssessmentResultData = { id: 11, commentByJury: 'New', juryId: 22 };
await assessmentResultJuryCommentRepository.update(latestAssessmentResultData);
await assessmentResultJuryCommentRepository.update({ assessmentResult });

// then
const expected = await knex('assessment-results').select('*').where({ id: 11 }).first();
expect({ ...assessmentResult, ...latestAssessmentResultData }).to.deep.equal(expected);
const { commentByJury, juryId } = await knex('assessment-results').select('*').where({ id: 11 }).first();
expect(commentByJury).to.equal(newCommentByJury);
expect(juryId).to.equal(newJuryId);
});
});
});

0 comments on commit 24204cd

Please sign in to comment.