From 6e93f66a24285cc7c39d31850bea64475e895497 Mon Sep 17 00:00:00 2001 From: AndreiaPena Date: Mon, 9 Dec 2024 16:28:33 +0100 Subject: [PATCH] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20api:=20set=20updatedAt=20w?= =?UTF-8?q?hen=20certification=20course=20is=20update?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: GUL --- .../certification-course-repository.js | 10 ++-- .../certification-course-repository_test.js | 47 ++++++++----------- 2 files changed, 24 insertions(+), 33 deletions(-) diff --git a/api/src/certification/shared/infrastructure/repositories/certification-course-repository.js b/api/src/certification/shared/infrastructure/repositories/certification-course-repository.js index 266090c9fdf..94df2d62629 100644 --- a/api/src/certification/shared/infrastructure/repositories/certification-course-repository.js +++ b/api/src/certification/shared/infrastructure/repositories/certification-course-repository.js @@ -1,14 +1,14 @@ import _ from 'lodash'; import { knex } from '../../../../../db/knex-database-connection.js'; -import { - logErrorWithCorrelationIds, - logInfoWithCorrelationIds, -} from '../../../../../src/shared/infrastructure/monitoring-tools.js'; import { config } from '../../../../shared/config.js'; import { DomainTransaction } from '../../../../shared/domain/DomainTransaction.js'; import { NotFoundError } from '../../../../shared/domain/errors.js'; import { Assessment } from '../../../../shared/domain/models/index.js'; +import { + logErrorWithCorrelationIds, + logInfoWithCorrelationIds, +} from '../../../../shared/infrastructure/monitoring-tools.js'; import { ComplementaryCertificationCourse } from '../../../session-management/domain/models/ComplementaryCertificationCourse.js'; import { CertificationCourse } from '../../domain/models/CertificationCourse.js'; import { CertificationIssueReport } from '../../domain/models/CertificationIssueReport.js'; @@ -212,7 +212,7 @@ async function update({ certificationCourse, noTransaction = false }) { const certificationCourseData = _pickUpdatableProperties(certificationCourse); const nbOfUpdatedCertificationCourses = await knexConn('certification-courses') - .update(certificationCourseData) + .update({ ...certificationCourseData, updatedAt: new Date() }) .where({ id: certificationCourseData.id }); if (nbOfUpdatedCertificationCourses === 0) { diff --git a/api/tests/certification/shared/integration/infrastructure/repositories/certification-course-repository_test.js b/api/tests/certification/shared/integration/infrastructure/repositories/certification-course-repository_test.js index 1676fc071ee..fe1e543175d 100644 --- a/api/tests/certification/shared/integration/infrastructure/repositories/certification-course-repository_test.js +++ b/api/tests/certification/shared/integration/infrastructure/repositories/certification-course-repository_test.js @@ -361,14 +361,15 @@ describe('Integration | Repository | Certification Course', function () { }); describe('#update', function () { - let certificationCourse; + let certificationCourse, certificationCourseData; beforeEach(async function () { // given const userId = databaseBuilder.factory.buildUser({}).id; - const certificationCourseData = databaseBuilder.factory.buildCertificationCourse({ + certificationCourseData = databaseBuilder.factory.buildCertificationCourse({ userId, isCancelled: false, + updatedAt: new Date('2020-12-01'), }); certificationCourse = domainBuilder.buildCertificationCourse(certificationCourseData); await databaseBuilder.commit(); @@ -408,36 +409,26 @@ describe('Integration | Repository | Certification Course', function () { // then const unpersistedUpdatedCertificationCourseDTO = unpersistedUpdatedCertificationCourse.toDTO(); - const persistedUpdatedCertificationCourse = await certificationCourseRepository.get({ - id: unpersistedUpdatedCertificationCourseDTO.id, - }); - const persistedUpdatedCertificationCourseDTO = persistedUpdatedCertificationCourse.toDTO(); - expect(persistedUpdatedCertificationCourse.getId()).to.equal(unpersistedUpdatedCertificationCourse.getId()); - expect(persistedUpdatedCertificationCourseDTO.firstName).to.equal( - unpersistedUpdatedCertificationCourseDTO.firstName, - ); - expect(persistedUpdatedCertificationCourseDTO.lastName).to.equal( - unpersistedUpdatedCertificationCourseDTO.lastName, - ); - expect(persistedUpdatedCertificationCourseDTO.birthdate).to.equal( - unpersistedUpdatedCertificationCourseDTO.birthdate, - ); - expect(persistedUpdatedCertificationCourseDTO.birthplace).to.equal( - unpersistedUpdatedCertificationCourseDTO.birthplace, - ); - expect(persistedUpdatedCertificationCourseDTO.birthPostalCode).to.equal( + const updatedCertificationCourse = await knex('certification-courses') + .where('id', unpersistedUpdatedCertificationCourse.getId()) + .first(); + expect(updatedCertificationCourse.id).to.equal(unpersistedUpdatedCertificationCourse.getId()); + expect(updatedCertificationCourse.firstName).to.equal(unpersistedUpdatedCertificationCourseDTO.firstName); + expect(updatedCertificationCourse.lastName).to.equal(unpersistedUpdatedCertificationCourseDTO.lastName); + expect(updatedCertificationCourse.birthdate).to.equal(unpersistedUpdatedCertificationCourseDTO.birthdate); + expect(updatedCertificationCourse.birthplace).to.equal(unpersistedUpdatedCertificationCourseDTO.birthplace); + expect(updatedCertificationCourse.birthPostalCode).to.equal( unpersistedUpdatedCertificationCourseDTO.birthPostalCode, ); - expect(persistedUpdatedCertificationCourseDTO.birthINSEECode).to.equal( + expect(updatedCertificationCourse.birthINSEECode).to.equal( unpersistedUpdatedCertificationCourseDTO.birthINSEECode, ); - expect(persistedUpdatedCertificationCourseDTO.birthCountry).to.equal( - unpersistedUpdatedCertificationCourseDTO.birthCountry, - ); - expect(persistedUpdatedCertificationCourseDTO.sex).to.equal(unpersistedUpdatedCertificationCourseDTO.sex); - expect(persistedUpdatedCertificationCourseDTO.isCancelled).to.be.true; - expect(persistedUpdatedCertificationCourseDTO.completedAt).to.deep.equal(new Date('1999-12-31')); - expect(persistedUpdatedCertificationCourseDTO.isRejectedForFraud).to.be.true; + expect(updatedCertificationCourse.birthCountry).to.equal(unpersistedUpdatedCertificationCourseDTO.birthCountry); + expect(updatedCertificationCourse.sex).to.equal(unpersistedUpdatedCertificationCourseDTO.sex); + expect(updatedCertificationCourse.isCancelled).to.be.true; + expect(updatedCertificationCourse.completedAt).to.deep.equal(new Date('1999-12-31')); + expect(updatedCertificationCourse.isRejectedForFraud).to.be.true; + expect(updatedCertificationCourse.updatedAt).to.be.greaterThan(certificationCourseData.updatedAt); }); it('should prevent other values to be updated', async function () {