Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FEATURE] Afficher la colonne "Écran de fin de test vu" sur la page de finalisation de session si le centre de certification n'utilise pas le portail surveillant (PIX-3748) #3931

Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@ class AllowedCertificationCenterAccess {
isInWhitelist() {
return features.pixCertifScoBlockedAccessWhitelist.includes(this.externalId.toUpperCase());
}

hasEndTestScreenRemovalEnabled() {
return features.endTestScreenRemovalWhiteList.includes(this.id.toString());
}
}

module.exports = AllowedCertificationCenterAccess;
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ module.exports = {
'isAccessBlockedAgri',
'relatedOrganizationTags',
'habilitations',
'hasEndTestScreenRemovalEnabled',
],
},
typeForAttribute: function (attribute) {
Expand All @@ -50,6 +51,7 @@ module.exports = {
isAccessBlockedLycee: access.isAccessBlockedLycee(),
isAccessBlockedAEFE: access.isAccessBlockedAEFE(),
isAccessBlockedAgri: access.isAccessBlockedAgri(),
hasEndTestScreenRemovalEnabled: access.hasEndTestScreenRemovalEnabled(),
};
}
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ describe('Acceptance | Route | CertificationPointOfContact', function () {
// then
expect(response.statusCode).to.equal(200);
expect(response.result.data.id).to.equal(userId.toString());
expect(response.result.included[0].attributes['has-end-test-screen-removal-enabled']).to.be.false;
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ describe('Unit | Controller | certifications-point-of-contact-controller', funct
'is-related-to-managing-students-organization': false,
'related-organization-tags': [],
habilitations: [],
'has-end-test-screen-removal-enabled': false,
},
},
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -688,4 +688,30 @@ describe('Unit | Domain | Read-Models | AllowedCertificationCenterAccess', funct
expect(isScoManagingStudents).to.be.true;
});
});

context('#hasEndTestScreenRemovalEnabled', function () {
it('should return true when whitelisted', function () {
// given
const allowedCertificationCenterAccess = domainBuilder.buildAllowedCertificationCenterAccess({ id: 1 });
settings.features.endTestScreenRemovalWhiteList = ['1'];

// when
const result = allowedCertificationCenterAccess.hasEndTestScreenRemovalEnabled();

// then
expect(result).to.be.true;
});

it('should return false when not whitelisted', function () {
clemlatz marked this conversation as resolved.
Show resolved Hide resolved
// given
const allowedCertificationCenterAccess = domainBuilder.buildAllowedCertificationCenterAccess({ id: 1 });
settings.features.endTestScreenRemovalWhiteList = ['2'];

// when
const result = allowedCertificationCenterAccess.hasEndTestScreenRemovalEnabled();

// then
expect(result).to.be.false;
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,19 @@ const endTestScreenRemovalService = require('../../../../lib/domain/services/end

describe('Unit | Domain | Service | EndTestScreenRemoval', function () {
describe('#isEndTestScreenRemovalEnabledBySessionId', function () {
it('should call repository with sessionId', async function () {
it('should return value from repository', async function () {
// given
const sessionId = Symbol('sessionId');
sinon.spy(endTestScreenRemovalRepository, 'isEndTestScreenRemovalEnabledBySessionId');
sinon.stub(endTestScreenRemovalRepository, 'isEndTestScreenRemovalEnabledBySessionId');
endTestScreenRemovalRepository.isEndTestScreenRemovalEnabledBySessionId.withArgs(sessionId).resolves(false);

// when
await endTestScreenRemovalService.isEndTestScreenRemovalEnabledBySessionId(sessionId);
const isEndTestScreenRemovalEnabled = await endTestScreenRemovalService.isEndTestScreenRemovalEnabledBySessionId(
sessionId
);

// then
expect(endTestScreenRemovalRepository.isEndTestScreenRemovalEnabledBySessionId).to.be.calledWith(sessionId);
expect(isEndTestScreenRemovalEnabled).to.equals(false);
});
});

Expand Down
9 changes: 4 additions & 5 deletions api/tests/unit/domain/usecases/authenticate-user_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ describe('Unit | Application | UseCase | authenticate-user', function () {
updateLastLoggedAt: sinon.stub(),
};
sinon.stub(authenticationService, 'getUserByUsernameAndPassword');
sinon.stub(endTestScreenRemovalService, 'isEndTestScreenRemovalEnabledByCertificationCenterId');
sinon.stub(endTestScreenRemovalService, 'isEndTestScreenRemovalEnabledForSomeCertificationCenter');
});

it('should resolves a valid JWT access token when authentication succeeded', async function () {
Expand Down Expand Up @@ -161,15 +161,14 @@ describe('Unit | Application | UseCase | authenticate-user', function () {
});

context('when scope is pix-certif and user is not linked to any certification centers', function () {
it('should rejects an error when feature toggle is disabled for linked certification center', async function () {
it('should rejects an error when feature toggle is disabled for all certification center', async function () {
// given
const scope = appMessages.PIX_CERTIF.SCOPE;
const user = domainBuilder.buildUser({ email: userEmail, certificationCenterMemberships: [] });
authenticationService.getUserByUsernameAndPassword.resolves(user);
endTestScreenRemovalService.isEndTestScreenRemovalEnabledByCertificationCenterId.returns(true);
endTestScreenRemovalService.isEndTestScreenRemovalEnabledForSomeCertificationCenter.returns(false);

const expectedErrorMessage = appMessages.PIX_CERTIF.NOT_LINKED_CERTIFICATION_MSG;

// when
const error = await catchErr(authenticateUser)({
username: userEmail,
Expand All @@ -194,7 +193,7 @@ describe('Unit | Application | UseCase | authenticate-user', function () {
certificationCenterMemberships: [Symbol('certificationCenterMembership')],
});

endTestScreenRemovalService.isEndTestScreenRemovalEnabledByCertificationCenterId.returns(true);
endTestScreenRemovalService.isEndTestScreenRemovalEnabledForSomeCertificationCenter.returns(true);
authenticationService.getUserByUsernameAndPassword.resolves(user);
tokenService.createAccessTokenFromUser.returns(accessToken);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ describe('Unit | Serializer | JSONAPI | certification-point-of-contact-serialize
relatedOrganizationTags: ['tag1'],
habilitations: [],
});
allowedCertificationCenterAccess2.hasEndTestScreenRemovalEnabled = sinon.stub().returns(true);
const certificationPointOfContact = domainBuilder.buildCertificationPointOfContact({
id: 789,
firstName: 'Buffy',
Expand Down Expand Up @@ -85,6 +86,7 @@ describe('Unit | Serializer | JSONAPI | certification-point-of-contact-serialize
{ id: 1, name: 'Certif comp 1' },
{ id: 2, name: 'Certif comp 2' },
],
'has-end-test-screen-removal-enabled': false,
},
},
{
Expand All @@ -101,6 +103,7 @@ describe('Unit | Serializer | JSONAPI | certification-point-of-contact-serialize
'is-access-blocked-agri': false,
'related-organization-tags': ['tag1'],
habilitations: [],
'has-end-test-screen-removal-enabled': true,
},
},
],
Expand Down Expand Up @@ -186,6 +189,7 @@ describe('Unit | Serializer | JSONAPI | certification-point-of-contact-serialize
'is-access-blocked-agri': false,
'related-organization-tags': [],
habilitations: [],
'has-end-test-screen-removal-enabled': false,
},
},
{
Expand All @@ -202,6 +206,7 @@ describe('Unit | Serializer | JSONAPI | certification-point-of-contact-serialize
'is-access-blocked-agri': false,
'related-organization-tags': ['tag1'],
habilitations: [],
'has-end-test-screen-removal-enabled': false,
},
},
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,22 @@
<th>Prénom</th>
<th>N° de certification</th>
<th>Signalement</th>
<th>
<div class="session-finalization-reports-information-step__row">
<div
class="session-finalization-reports-information-step__checker"
{{on "click" (fn @onAllHasSeenEndTestScreenCheckboxesClicked this.hasCheckedSomething)}}
>
<CertifCheckbox @state={{this.headerCheckboxStatus}} />
{{#if @shouldDisplayHasSeenEndTestScreenCheckbox}}
<th>
<div class="session-finalization-reports-information-step__row">
<div
class="session-finalization-reports-information-step__checker"
{{on "click" (fn @onAllHasSeenEndTestScreenCheckboxesClicked this.hasCheckedSomething)}}
>
<CertifCheckbox
data-test-id="finalization-report-all-candidates-have-seen-end-test-screen"
@state={{this.headerCheckboxStatus}}
/>
</div>
Écran de fin du test vu
</div>
Écran de fin du test vu
</div>
</th>
</th>
{{/if}}
</tr>
</thead>
<tbody>
Expand Down Expand Up @@ -64,13 +69,15 @@
{{/if}}
</div>
</td>
<td>
<CertifCheckbox
data-test-id="finalization-report-has-seen-end-test-screen_{{report.certificationCourseId}}"
@state={{if report.hasSeenEndTestScreen "checked" "unchecked"}}
{{on "click" (fn @onHasSeenEndTestScreenCheckboxClicked report)}}
/>
</td>
{{#if @shouldDisplayHasSeenEndTestScreenCheckbox}}
<td>
<CertifCheckbox
data-test-id="finalization-report-has-seen-end-test-screen_{{report.certificationCourseId}}"
@state={{if report.hasSeenEndTestScreen "checked" "unchecked"}}
{{on "click" (fn @onHasSeenEndTestScreenCheckboxClicked report)}}
/>
</td>
{{/if}}
</tr>
{{/each}}
</tbody>
Expand Down
5 changes: 5 additions & 0 deletions certif/app/controllers/authenticated/sessions/finalize.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import trim from 'lodash/trim';

export default class SessionsFinalizeController extends Controller {
@service featureToggles;
@service currentUser;

@service notifications;

Expand All @@ -28,6 +29,10 @@ export default class SessionsFinalizeController extends Controller {
return this.featureToggles.featureToggles.isManageUncompletedCertifEnabled;
}

get shouldDisplayHasSeenEndTestScreenCheckbox() {
clemlatz marked this conversation as resolved.
Show resolved Hide resolved
return !this.currentUser.currentAllowedCertificationCenterAccess.hasEndTestScreenRemovalEnabled;
}

get uncheckedHasSeenEndTestScreenCount() {
return sumBy(this.session.completedCertificationReports.toArray(), (reports) =>
Number(!reports.hasSeenEndTestScreen)
Expand Down
1 change: 1 addition & 0 deletions certif/app/models/allowed-certification-center-access.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export default class AllowedCertificationCenterAccess extends Model {
@attr() isAccessBlockedAgri;
@attr() relatedOrganizationTags;
@attr() habilitations;
@attr() hasEndTestScreenRemovalEnabled;

get isSco() {
return this.type === 'SCO';
Expand Down
1 change: 1 addition & 0 deletions certif/app/templates/authenticated/sessions/finalize.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
@onHasSeenEndTestScreenCheckboxClicked={{this.toggleCertificationReportHasSeenEndTestScreen}}
@onAllHasSeenEndTestScreenCheckboxesClicked={{this.toggleAllCertificationReportsHasSeenEndTestScreen}}
@onIssueReportDeleteButtonClicked={{this.deleteCertificationIssueReport}}
@shouldDisplayHasSeenEndTestScreenCheckbox={{this.shouldDisplayHasSeenEndTestScreenCheckbox}}
/>
{{/if}}
</SessionFinalizationStepContainer>
Expand Down
13 changes: 12 additions & 1 deletion certif/tests/acceptance/session-finalization_test.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { module, test } from 'qunit';
import { click, currentURL, fillIn, visit } from '@ember/test-helpers';
import { click, currentURL, fillIn } from '@ember/test-helpers';
import { setupApplicationTest } from 'ember-qunit';
import { authenticateSession } from '../helpers/test-init';
import clickByLabel from '../helpers/extended-ember-test-helpers/click-by-label';
import { visit } from '@1024pix/ember-testing-library';

import setupMirage from 'ember-cli-mirage/test-support/setup-mirage';

Expand All @@ -22,6 +23,7 @@ module('Acceptance | Session Finalization', function (hooks) {
isAccessBlockedLycee: false,
isAccessBlockedAEFE: false,
isAccessBlockedAgri: false,
hasEndTestScreenRemovalEnabled: false,
});
certificationPointOfContact = server.create('certification-point-of-contact', {
firstName: 'Buffy',
Expand Down Expand Up @@ -78,6 +80,15 @@ module('Acceptance | Session Finalization', function (hooks) {
assert.equal(currentURL(), `/sessions/${session.id}/finalisation`);
});

test('it should display the end screen column when the center has no access to the supervisor space', async function (assert) {
// when
server.create('feature-toggle', { isEndTestScreenRemovalEnabled: true });
const screen = await visit(`/sessions/${session.id}/finalisation`);

// then
assert.dom(screen.queryByText('Écran de fin du test vu')).exists();
});

module('When certificationPointOfContact click on "Finaliser" button', function () {
module('when there is no certification issue reports', function () {
test('it should show "Ajouter ?" button', async function (assert) {
Expand Down
Loading