Skip to content

Commit

Permalink
♻️ api: set updatedAt when certification course is update
Browse files Browse the repository at this point in the history
Co-authored-by: GUL <[email protected]>
  • Loading branch information
AndreiaPena and HEYGUL committed Dec 9, 2024
1 parent 5b37b27 commit 6e93f66
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 33 deletions.
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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 () {
Expand Down

0 comments on commit 6e93f66

Please sign in to comment.