Skip to content

Commit

Permalink
hide professionalizing warning on shareable certificate for version d…
Browse files Browse the repository at this point in the history
…ifferent from 2
  • Loading branch information
HEYGUL authored and P-Jeremy committed Nov 7, 2024
1 parent 879320e commit f63dce1
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 10 deletions.
7 changes: 6 additions & 1 deletion mon-pix/app/models/certification.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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');
Expand All @@ -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);

Expand Down Expand Up @@ -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`<UserCertificationsDetailHeader @certification={{this.certification}} />`,
);

// 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);

Expand Down
37 changes: 29 additions & 8 deletions mon-pix/tests/unit/models/certification-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit f63dce1

Please sign in to comment.