From f63dce1ded9c53e3fbe8e8b2ec18371024204db8 Mon Sep 17 00:00:00 2001 From: Guillaume Lagorce Date: Wed, 6 Nov 2024 16:05:29 +0100 Subject: [PATCH] hide professionalizing warning on shareable certificate for version different from 2 --- mon-pix/app/models/certification.js | 7 +++- .../user-certifications-detail-header-test.js | 40 ++++++++++++++++++- .../tests/unit/models/certification-test.js | 37 +++++++++++++---- 3 files changed, 74 insertions(+), 10 deletions(-) diff --git a/mon-pix/app/models/certification.js b/mon-pix/app/models/certification.js index 188c2b0e6a6..a9a73be210c 100644 --- a/mon-pix/app/models/certification.js +++ b/mon-pix/app/models/certification.js @@ -26,6 +26,7 @@ export default class Certification extends Model { @attr('string') verificationCode; @attr() certifiedBadgeImages; @attr('number') maxReachableLevelOnCertificationDate; + @attr('number') version; // includes @belongsTo('resultCompetenceTree', { async: true, inverse: null }) resultCompetenceTree; @@ -42,7 +43,11 @@ export default class Certification extends Model { } get shouldDisplayProfessionalizingWarning() { - return this.currentDomain.isFranceDomain && new Date(this.deliveredAt).getTime() >= professionalizingDate.getTime(); + return ( + this.version === 2 && + this.currentDomain.isFranceDomain && + new Date(this.deliveredAt).getTime() >= professionalizingDate.getTime() + ); } get maxReachablePixCountOnCertificationDate() { diff --git a/mon-pix/tests/integration/components/user-certifications-detail-header-test.js b/mon-pix/tests/integration/components/user-certifications-detail-header-test.js index b368dd532a6..0719c05444b 100644 --- a/mon-pix/tests/integration/components/user-certifications-detail-header-test.js +++ b/mon-pix/tests/integration/components/user-certifications-detail-header-test.js @@ -30,6 +30,7 @@ module('Integration | Component | user certifications detail header', function ( pixScore: 654, status: 'validated', commentForCandidate: 'Comment for candidate', + version: 2, }); this.set('certification', certification); @@ -100,7 +101,7 @@ module('Integration | Component | user certifications detail header', function ( this.owner.register('service:currentDomain', CurrentDomainServiceStub); }); - module('when certification is delivered after 2022-01-01', function () { + module('when certification is v2 and delivered after 2022-01-01', function () { test('should display the professionalizing warning', async function (assert) { // given const store = this.owner.lookup('service:store'); @@ -117,6 +118,7 @@ module('Integration | Component | user certifications detail header', function ( pixScore: 654, status: 'validated', commentForCandidate: 'Comment for candidate', + version: 2, }); this.set('certification', certification); @@ -151,6 +153,42 @@ module('Integration | Component | user certifications detail header', function ( pixScore: 654, status: 'validated', commentForCandidate: 'Comment for candidate', + version: 2, + }); + this.set('certification', certification); + + // when + const screen = await renderScreen( + hbs``, + ); + + // then + assert.notOk( + screen.queryByText( + 'Le certificat Pix est reconnu comme professionnalisant par France compétences à compter d’un score minimal de 120 pix', + ), + ); + }); + }); + + module('when certification is v3', function () { + test('should not display the professionalizing warning', async function (assert) { + // given + const store = this.owner.lookup('service:store'); + const certification = store.createRecord('certification', { + id: 1, + birthdate: '2000-01-22', + birthplace: 'Paris', + firstName: 'Jean', + lastName: 'Bon', + date: new Date('2018-02-15T15:15:52Z'), + deliveredAt: '2022-05-28', + certificationCenter: 'Université de Lyon', + isPublished: true, + pixScore: 654, + status: 'validated', + commentForCandidate: 'Comment for candidate', + version: 3, }); this.set('certification', certification); diff --git a/mon-pix/tests/unit/models/certification-test.js b/mon-pix/tests/unit/models/certification-test.js index c5830565626..a321f32a9e9 100644 --- a/mon-pix/tests/unit/models/certification-test.js +++ b/mon-pix/tests/unit/models/certification-test.js @@ -34,24 +34,45 @@ module('Unit | Model | certification', function (hooks) { this.owner.register('service:currentDomain', CurrentDomainServiceStub); }); - test('should be true when deliveredAt >= 2022-01-01 ', function (assert) { - // given - const model = store.createRecord('certification', { deliveredAt: '2022-01-01' }); + module('when version is 2', function () { + const version = 2; - // when / then - assert.true(model.shouldDisplayProfessionalizingWarning); + test('should be true when deliveredAt >= 2022-01-01 ', function (assert) { + // given + const model = store.createRecord('certification', { version, deliveredAt: '2022-01-01' }); + + // when / then + assert.true(model.shouldDisplayProfessionalizingWarning); + }); + + test('should be false when when deliveredAt < 2022-01-01', function (assert) { + // given + const model = store.createRecord('certification', { version, deliveredAt: '2021-01-01' }); + + // when / then + assert.false(model.shouldDisplayProfessionalizingWarning); + }); }); + }); - test('should be false when when deliveredAt < 2022-01-01', function (assert) { + module('when domain is not french', function () { + test('should be false', function (assert) { // given - const model = store.createRecord('certification', { deliveredAt: '2021-01-01' }); + class CurrentDomainServiceStub extends Service { + get isFranceDomain() { + return false; + } + } + + this.owner.register('service:currentDomain', CurrentDomainServiceStub); + const model = store.createRecord('certification', { deliveredAt: '2022-01-01' }); // when / then assert.false(model.shouldDisplayProfessionalizingWarning); }); }); - module('when domain is not french', function () { + module('when version is not 2', function () { test('should be false', function (assert) { // given class CurrentDomainServiceStub extends Service {