1
+ import { ChallengeAlreadyAnsweredError } from '../../../../../../src/certification/evaluation/domain/errors.js' ;
1
2
import { validateLiveAlert } from '../../../../../../src/certification/session-management/domain/usecases/validate-live-alert.js' ;
2
3
import { CertificationChallengeLiveAlertStatus } from '../../../../../../src/certification/shared/domain/models/CertificationChallengeLiveAlert.js' ;
3
4
import {
@@ -12,6 +13,7 @@ describe('Unit | UseCase | validate-live-alert', function () {
12
13
let assessmentRepository ;
13
14
let issueReportCategoryRepository ;
14
15
let certificationIssueReportRepository ;
16
+ let answerRepository ;
15
17
16
18
beforeEach ( function ( ) {
17
19
certificationChallengeLiveAlertRepository = {
@@ -30,6 +32,10 @@ describe('Unit | UseCase | validate-live-alert', function () {
30
32
certificationIssueReportRepository = {
31
33
save : sinon . stub ( ) ,
32
34
} ;
35
+
36
+ answerRepository = {
37
+ findByAssessment : sinon . stub ( ) ,
38
+ } ;
33
39
} ) ;
34
40
35
41
describe ( 'when the liveAlert does not exist' , function ( ) {
@@ -57,6 +63,52 @@ describe('Unit | UseCase | validate-live-alert', function () {
57
63
} ) ;
58
64
59
65
describe ( 'when the liveAlert exists' , function ( ) {
66
+ describe ( 'when an answer for the alerted challenge exists' , function ( ) {
67
+ it ( 'should throw an error' , async function ( ) {
68
+ // given
69
+ const sessionId = 123 ;
70
+ const userId = 456 ;
71
+ const assessmentId = 789 ;
72
+ const questionNumber = 2 ;
73
+ const challengeId = 'rec123' ;
74
+
75
+ const onGoingLiveAlert = domainBuilder . buildCertificationChallengeLiveAlert ( {
76
+ questionNumber,
77
+ challengeId,
78
+ assessmentId,
79
+ status : CertificationChallengeLiveAlertStatus . ONGOING ,
80
+ } ) ;
81
+
82
+ certificationChallengeLiveAlertRepository . getOngoingBySessionIdAndUserId
83
+ . withArgs ( {
84
+ sessionId,
85
+ userId,
86
+ } )
87
+ . resolves ( onGoingLiveAlert ) ;
88
+
89
+ answerRepository . findByAssessment
90
+ . withArgs ( onGoingLiveAlert . assessmentId )
91
+ . resolves ( [ domainBuilder . buildAnswer ( { challengeId } ) ] ) ;
92
+
93
+ const error = await catchErr ( validateLiveAlert ) ( {
94
+ certificationChallengeLiveAlertRepository,
95
+ issueReportCategoryRepository,
96
+ certificationIssueReportRepository,
97
+ answerRepository,
98
+ sessionId,
99
+ userId,
100
+ } ) ;
101
+
102
+ // then
103
+ expect ( onGoingLiveAlert . status ) . equals ( CertificationChallengeLiveAlertStatus . DISMISSED ) ;
104
+ expect ( certificationChallengeLiveAlertRepository . save ) . to . have . been . calledWith ( {
105
+ certificationChallengeLiveAlert : onGoingLiveAlert ,
106
+ } ) ;
107
+
108
+ expect ( error ) . to . be . instanceOf ( ChallengeAlreadyAnsweredError ) ;
109
+ } ) ;
110
+ } ) ;
111
+
60
112
it ( 'should update the LiveAlert and create a new resolved CertificationIssueReport' , async function ( ) {
61
113
// given
62
114
const sessionId = 123 ;
@@ -97,6 +149,8 @@ describe('Unit | UseCase | validate-live-alert', function () {
97
149
} )
98
150
. resolves ( issueReportCategory ) ;
99
151
152
+ answerRepository . findByAssessment . withArgs ( liveAlert . assessmentId ) . resolves ( [ ] ) ;
153
+
100
154
const validatedLiveAlert = domainBuilder . buildCertificationChallengeLiveAlert ( {
101
155
assessmentId : liveAlert . assessmentId ,
102
156
challengeId : liveAlert . challengeId ,
@@ -110,6 +164,7 @@ describe('Unit | UseCase | validate-live-alert', function () {
110
164
issueReportCategoryRepository,
111
165
assessmentRepository,
112
166
certificationIssueReportRepository,
167
+ answerRepository,
113
168
subcategory,
114
169
sessionId,
115
170
userId,
0 commit comments