1
1
import { findTutorials } from '../../../../../src/devcomp/domain/usecases/find-tutorials.js' ;
2
- import { Scorecard } from '../../../../../src/evaluation/domain/models/Scorecard.js' ;
3
- import { UserNotAuthorizedToAccessEntityError } from '../../../../../src/shared/domain/errors.js' ;
4
2
import { KnowledgeElement } from '../../../../../src/shared/domain/models/KnowledgeElement.js' ;
5
3
import { domainBuilder , expect , sinon } from '../../../../test-helper.js' ;
6
4
7
5
describe ( 'Unit | UseCase | find-tutorials' , function ( ) {
8
- let authenticatedUserId ;
6
+ let userId ;
9
7
let competenceId ;
10
- let scorecardId ;
11
- let parseIdStub ;
12
8
let knowledgeElementRepository ;
13
9
let skillRepository ;
14
10
let tubeRepository ;
@@ -17,10 +13,8 @@ describe('Unit | UseCase | find-tutorials', function () {
17
13
let locale ;
18
14
19
15
beforeEach ( function ( ) {
20
- scorecardId = '1_recabC123' ;
21
16
competenceId = 'recABc123' ;
22
- authenticatedUserId = 1 ;
23
- parseIdStub = sinon . stub ( Scorecard , 'parseId' ) ;
17
+ userId = 1 ;
24
18
knowledgeElementRepository = { findUniqByUserIdAndCompetenceId : sinon . stub ( ) } ;
25
19
skillRepository = { findActiveByCompetenceId : sinon . stub ( ) } ;
26
20
tubeRepository = { findByNames : sinon . stub ( ) } ;
@@ -29,19 +23,15 @@ describe('Unit | UseCase | find-tutorials', function () {
29
23
} ) ;
30
24
31
25
context ( 'When user is authenticated' , function ( ) {
32
- beforeEach ( function ( ) {
33
- parseIdStub . withArgs ( scorecardId ) . returns ( { competenceId, userId : authenticatedUserId } ) ;
34
- } ) ;
35
-
36
26
context ( 'And user asks for tutorials belonging to his scorecard' , function ( ) {
37
27
it ( 'should resolve' , function ( ) {
38
28
// given
39
29
knowledgeElementRepository . findUniqByUserIdAndCompetenceId . resolves ( { } ) ;
40
30
41
31
// when
42
32
const result = findTutorials ( {
43
- authenticatedUserId ,
44
- scorecardId ,
33
+ userId ,
34
+ competenceId ,
45
35
knowledgeElementRepository,
46
36
skillRepository,
47
37
tubeRepository,
@@ -101,14 +91,14 @@ describe('Unit | UseCase | find-tutorials', function () {
101
91
const inferredTutorialIdList = [ inferredTutorial . id ] ;
102
92
103
93
tutorialRepository . findByRecordIdsForCurrentUser
104
- . withArgs ( { ids : tutorialIdList1 , userId : authenticatedUserId , locale } )
94
+ . withArgs ( { ids : tutorialIdList1 , userId : userId , locale } )
105
95
. returns ( [ tutorial1 , tutorial2 ] ) ;
106
96
tutorialRepository . findByRecordIdsForCurrentUser
107
- . withArgs ( { ids : tutorialIdList2 , userId : authenticatedUserId , locale } )
97
+ . withArgs ( { ids : tutorialIdList2 , userId : userId , locale } )
108
98
. returns ( [ tutorial3 ] ) ;
109
99
110
100
tutorialRepository . findByRecordIdsForCurrentUser
111
- . withArgs ( { ids : inferredTutorialIdList , userId : authenticatedUserId } )
101
+ . withArgs ( { ids : inferredTutorialIdList , userId : userId } )
112
102
. returns ( [ inferredTutorial ] ) ;
113
103
114
104
const skill_1 = domainBuilder . buildSkill ( {
@@ -227,8 +217,8 @@ describe('Unit | UseCase | find-tutorials', function () {
227
217
it ( 'should return the tutorials related to the scorecard' , async function ( ) {
228
218
// when
229
219
const result = await findTutorials ( {
230
- authenticatedUserId ,
231
- scorecardId ,
220
+ userId ,
221
+ competenceId ,
232
222
knowledgeElementRepository,
233
223
skillRepository,
234
224
tubeRepository,
@@ -267,8 +257,8 @@ describe('Unit | UseCase | find-tutorials', function () {
267
257
268
258
// when
269
259
const result = await findTutorials ( {
270
- authenticatedUserId ,
271
- scorecardId ,
260
+ userId ,
261
+ competenceId ,
272
262
knowledgeElementRepository,
273
263
skillRepository,
274
264
tubeRepository,
@@ -282,26 +272,5 @@ describe('Unit | UseCase | find-tutorials', function () {
282
272
} ) ;
283
273
} ) ;
284
274
} ) ;
285
-
286
- context ( 'And user asks for a scorecard that do not belongs to him' , function ( ) {
287
- it ( 'should reject a "UserNotAuthorizedToAccessEntityError" domain error' , function ( ) {
288
- // given
289
- const unauthorizedUserId = 42 ;
290
-
291
- // when
292
- const promise = findTutorials ( {
293
- authenticatedUserId : unauthorizedUserId ,
294
- scorecardId,
295
- knowledgeElementRepository,
296
- skillRepository,
297
- tubeRepository,
298
- tutorialRepository,
299
- userSavedTutorialRepository,
300
- } ) ;
301
-
302
- // then
303
- return expect ( promise ) . to . be . rejectedWith ( UserNotAuthorizedToAccessEntityError ) ;
304
- } ) ;
305
- } ) ;
306
275
} ) ;
307
276
} ) ;
0 commit comments