Skip to content

Commit

Permalink
[FEATURE] Sauvegarder les raisons d'abandons à la finalisation (PIX-1…
Browse files Browse the repository at this point in the history
  • Loading branch information
pix-service-auto-merge authored Dec 31, 2024
2 parents 6258708 + 7b508bf commit 9a0ad2b
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 36 deletions.
21 changes: 5 additions & 16 deletions certif/app/controllers/authenticated/sessions/finalize.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,27 +37,16 @@ export default class SessionsFinalizeController extends Controller {
}

@action
async abort(certificationReport, option) {
const abortReason = option;

try {
await certificationReport.abort(abortReason);

certificationReport.abortReason = abortReason;
} catch (error) {
const select = document.getElementById(`finalization-report-abort-reason__select${certificationReport.id}`);

if (certificationReport.abortReason) {
select.value = certificationReport.abortReason;
} else {
select.options[0].selected = true;
}
}
async abort(certificationReport, abortReason) {
certificationReport.abortReason = abortReason;
}

@action
async finalizeSession() {
try {
for (const certificationReport of this.session.uncompletedCertificationReports) {
await certificationReport.abort();
}
await this.session.save({ adapterOptions: { finalization: true } });
this.pixToast.sendSuccessNotification({
message: this.intl.t('pages.session-finalization.notification.success'),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ module('Integration | Component | finalization-confirmation-modal', function (ho
});

module('when the finalization is confirmed', () => {
test('it should finalize de session', async function (assert) {
test('it should finalize the session', async function (assert) {
// given
const finalizeSessionStub = sinon.stub();
this.set('closeModal', sinon.stub());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@ import { setupTest } from 'ember-qunit';
import { module, test } from 'qunit';
import sinon from 'sinon';

import setupIntl from '../../../../helpers/setup-intl';

const FINALIZE_PATH = 'authenticated/sessions/finalize';

module('Unit | Controller | ' + FINALIZE_PATH, function (hooks) {
setupTest(hooks);
setupIntl(hooks, 'fr');

module('#computed uncheckedHasSeenEndTestScreenCount', function () {
test('it should count no unchecked box if no report', function (assert) {
Expand Down Expand Up @@ -309,25 +312,6 @@ module('Unit | Controller | ' + FINALIZE_PATH, function (hooks) {
});
});

module('#abort', function () {
test('should abort a certification report', function (assert) {
// given
const store = this.owner.lookup('service:store');
const certificationReport = store.createRecord('certification-report');
const controller = this.owner.lookup('controller:' + FINALIZE_PATH);
certificationReport.abort = sinon.stub();
certificationReport.abort.resolves('ok');
const optionSelected = 'coucou';

// when
controller.abort(certificationReport, optionSelected);

// then
sinon.assert.calledWithExactly(certificationReport.abort, 'coucou');
assert.ok(true);
});
});

module('#action toggleIncidentDuringCertificationSession', function () {
test('it should set hasIncident to true', function (assert) {
// given
Expand Down Expand Up @@ -364,6 +348,65 @@ module('Unit | Controller | ' + FINALIZE_PATH, function (hooks) {
assert.true(session.hasJoiningIssue);
});
});

module('#finalizeSession', function () {
module('when there are no certification reports', function () {
test('it finalizes the session', async function (assert) {
// given
const store = this.owner.lookup('service:store');
const session = store.createRecord('session-management', {
certificationReports: [],
});
const controller = this.owner.lookup('controller:' + FINALIZE_PATH);
controller.session = session;
controller.router = {
transitionTo: sinon.stub(),
};
controller.pixToast = {
sendSuccessNotification: sinon.stub(),
};
session.save = sinon.stub();
session.save.resolves();

// when
await controller.finalizeSession();

// then
sinon.assert.calledWithExactly(session.save, { adapterOptions: { finalization: true } });
assert.ok(controller.pixToast.sendSuccessNotification.called);
sinon.assert.calledWithExactly(controller.router.transitionTo, 'authenticated.sessions.details', session.id);
});
});

module('when there are certification reports', function () {
test('it finalizes the session', async function (assert) {
// given
const store = this.owner.lookup('service:store');
const certificationReport = store.createRecord('certification-report');
certificationReport.abort = sinon.stub();
const session = store.createRecord('session-management', {
certificationReports: [certificationReport],
});
const controller = this.owner.lookup('controller:' + FINALIZE_PATH);
controller.session = session;
controller.router = {
transitionTo: sinon.stub(),
};
controller.pixToast = {
sendSuccessNotification: sinon.stub(),
};
session.save = sinon.stub();
session.save.resolves();

// when
await controller.finalizeSession();

// then
sinon.assert.calledOnce(certificationReport.abort);
assert.ok(true);
});
});
});
});

async function _createSessionWithCertificationReports({ store, sessionData = {}, certificationReportsData = [] }) {
Expand Down

0 comments on commit 9a0ad2b

Please sign in to comment.