|
| 1 | +import { FixNotFullyFinalizedSession } from '../../../../scripts/certification/fix-not-fully-finalized-session.js'; |
| 2 | +import { databaseBuilder, expect, knex, sinon } from '../../../test-helper.js'; |
| 3 | + |
| 4 | +describe('Integration | Scripts | Certification | fix not fully finalized session', function () { |
| 5 | + let assessment, certificationCourse, session, fixNotFullyFinalizedSessionScript, logger; |
| 6 | + |
| 7 | + beforeEach(async function () { |
| 8 | + session = databaseBuilder.factory.buildSession({ |
| 9 | + version: 2, |
| 10 | + finalizedAt: new Date('2024-01-02T00:00:00Z'), |
| 11 | + }); |
| 12 | + const user = databaseBuilder.factory.buildUser(); |
| 13 | + databaseBuilder.factory.buildCertificationCandidate({ |
| 14 | + sessionId: session.id, |
| 15 | + userId: user.id, |
| 16 | + }); |
| 17 | + certificationCourse = databaseBuilder.factory.buildCertificationCourse({ |
| 18 | + createdAt: new Date('2024-02-01T00:00:00Z'), |
| 19 | + sessionId: session.id, |
| 20 | + userId: user.id, |
| 21 | + completedAt: new Date('2024-02-01T08:00:00Z'), |
| 22 | + isPublished: false, |
| 23 | + isCancelled: false, |
| 24 | + abortReason: null, |
| 25 | + version: 2, |
| 26 | + isRejectedForFraud: false, |
| 27 | + endedAt: null, |
| 28 | + }); |
| 29 | + assessment = databaseBuilder.factory.buildAssessment({ |
| 30 | + certificationCourseId: certificationCourse.id, |
| 31 | + userId: user.id, |
| 32 | + type: 'CERTIFICATION', |
| 33 | + state: 'completed', |
| 34 | + method: 'CERTIFICATION_DETERMINED', |
| 35 | + }); |
| 36 | + databaseBuilder.factory.buildAssessmentResult({ |
| 37 | + assessmentId: assessment.id, |
| 38 | + userId: user.id, |
| 39 | + type: 'CERTIFICATION', |
| 40 | + status: 'validated', |
| 41 | + }); |
| 42 | + |
| 43 | + await databaseBuilder.commit(); |
| 44 | + |
| 45 | + logger = { info: sinon.stub() }; |
| 46 | + fixNotFullyFinalizedSessionScript = new FixNotFullyFinalizedSession(); |
| 47 | + }); |
| 48 | + |
| 49 | + it('creates a finalized session', async function () { |
| 50 | + // when |
| 51 | + await fixNotFullyFinalizedSessionScript.handle({ |
| 52 | + options: { sessionId: session.id }, |
| 53 | + logger, |
| 54 | + }); |
| 55 | + |
| 56 | + // then |
| 57 | + const { count: finalizedSessionCount } = await knex('finalized-sessions') |
| 58 | + .where({ sessionId: session.id }) |
| 59 | + .count() |
| 60 | + .first(); |
| 61 | + |
| 62 | + expect(finalizedSessionCount).to.equal(1); |
| 63 | + }); |
| 64 | +}); |
0 commit comments