Skip to content

Commit

Permalink
✨ api, admin: Add specific error message when scoring has not been done
Browse files Browse the repository at this point in the history
  • Loading branch information
aceol committed Jun 27, 2024
1 parent c689ec5 commit 79d48f8
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,11 @@ export default class CertificationInformationsController extends Controller {
this.notifications.success('Le commentaire du jury a bien été enregistré.');
return true;
} catch (e) {
this.notifications.error("Le commentaire du jury n'a pas pu être enregistré.");
if (e.errors && e.errors.at(0).status == '404') {
this.notifications.error('Le commentaire du jury ne peux pas être renseigné avant scoring');
} else {
this.notifications.error("Le commentaire du jury n'a pas pu être enregistré.");
}
return false;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1186,6 +1186,29 @@ module('Acceptance | Route | routes/authenticated/certifications/certification |
assert.dom(screen.queryByText('button', { name: 'Modifier le commentaire jury' })).doesNotExist();
assert.dom(screen.getByText("Le commentaire du jury n'a pas pu être enregistré.")).exists();
});

module('when the form is submitted with a 404 error', function () {
test('it displays a specific error notification', async function (assert) {
// given
await authenticateAdminMemberWithRole({ isSuperAdmin: true })(server);

server.patch(
'/admin/certification-courses/:id/assessment-results',
() => ({ errors: [{ status: '404', title: 'Missing' }] }),
404,
);

// when
const screen = await visit(`/certifications/${certification.id}`);
await clickByName('Modifier le commentaire jury');
await fillByLabel('Notes internes Jury Pix :', 'Whatever jury said');

await clickByName('Enregistrer');

// then
assert.dom(screen.getByText('Le commentaire du jury ne peux pas être renseigné avant scoring')).exists();
});
});
});
});
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { knex } from '../../../../../db/knex-database-connection.js';
import { NotFoundError } from '../../../../shared/domain/errors.js';
import { AssessmentResultJuryComment } from '../../domain/models/AssessmentResultJuryComment.js';

const getLatestAssessmentResultJuryComment = async function ({ certificationCourseId }) {
Expand All @@ -12,6 +13,10 @@ const getLatestAssessmentResultJuryComment = async function ({ certificationCour
.where({ certificationCourseId })
.first();

if (!result) {
throw new NotFoundError(`Assessment result not found for certification course ${certificationCourseId}`);
}

return new AssessmentResultJuryComment(result);
};

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { AssessmentResultJuryComment } from '../../../../../../src/certification/session-management/domain/models/AssessmentResultJuryComment.js';
import * as assessmentResultJuryCommentRepository from '../../../../../../src/certification/session-management/infrastructure/repositories/assessment-result-jury-comment-repository.js';
import { NotFoundError } from '../../../../../../src/shared/domain/errors.js';
import { databaseBuilder, expect, knex } from '../../../../../test-helper.js';

describe('Integration | Repository | Certification | Session-management | AssessmentResultJuryCommentRepository', function () {
Expand All @@ -23,6 +24,23 @@ describe('Integration | Repository | Certification | Session-management | Assess
// then
expect(result).to.deepEqualInstance(new AssessmentResultJuryComment(latestAssessmentResultData));
});

describe('#when there is no assessment-results for the given certification-course id', function () {
it('should throw a not found exception', async function () {
// given
databaseBuilder.factory.buildCertificationCourse({ id: 55 });
databaseBuilder.factory.buildAssessment({ id: 51, certificationCourseId: 55 });
await databaseBuilder.commit();

// when
const promise = assessmentResultJuryCommentRepository.getLatestAssessmentResultJuryComment({
certificationCourseId: 55,
});

// then
expect(promise).to.have.been.rejectedWith(NotFoundError);
});
});
});

describe('#save', function () {
Expand Down

0 comments on commit 79d48f8

Please sign in to comment.