@@ -355,6 +355,161 @@ describe('Quest | Unit | Domain | Models | Quest ', function () {
355
355
} ) ;
356
356
} ) ;
357
357
358
+ describe ( '#findCampaignParticipationIdsContributingToQuest' , function ( ) {
359
+ const organization = { type : 'SCO' } ;
360
+ const organizationLearner = { id : 123 } ;
361
+
362
+ context ( 'at least one eligibilityRequirements is type of "campaignParticipations"' , function ( ) {
363
+ it ( 'return false if none of campaignParticipation eligibilityRequirement is valid given campaignParticipationId' , function ( ) {
364
+ // given
365
+ const eligibilityRequirements = [
366
+ {
367
+ requirement_type : REQUIREMENT_TYPES . OBJECT . ORGANIZATION ,
368
+ data : {
369
+ type : {
370
+ data : 'SCO' ,
371
+ comparison : CRITERION_COMPARISONS . EQUAL ,
372
+ } ,
373
+ } ,
374
+ comparison : REQUIREMENT_COMPARISONS . ALL ,
375
+ } ,
376
+ {
377
+ requirement_type : REQUIREMENT_TYPES . OBJECT . CAMPAIGN_PARTICIPATIONS ,
378
+ data : {
379
+ targetProfileId : {
380
+ data : 1 ,
381
+ comparison : CRITERION_COMPARISONS . EQUAL ,
382
+ } ,
383
+ } ,
384
+ comparison : REQUIREMENT_COMPARISONS . ALL ,
385
+ } ,
386
+ {
387
+ requirement_type : REQUIREMENT_TYPES . OBJECT . CAMPAIGN_PARTICIPATIONS ,
388
+ data : {
389
+ targetProfileId : {
390
+ data : 2 ,
391
+ comparison : CRITERION_COMPARISONS . EQUAL ,
392
+ } ,
393
+ } ,
394
+ comparison : REQUIREMENT_COMPARISONS . ALL ,
395
+ } ,
396
+ ] ;
397
+ const quest = new Quest ( { eligibilityRequirements, successRequirements : [ ] } ) ;
398
+ const campaignParticipations = [
399
+ { id : 10 , targetProfileId : 1 } ,
400
+ { id : 11 , targetProfileId : 3 } ,
401
+ ] ;
402
+ const eligibility = new Eligibility ( { organization, organizationLearner, campaignParticipations } ) ;
403
+ const data = new DataForQuest ( { eligibility } ) ;
404
+ const campaignParticipationIdToCheck = 11 ;
405
+
406
+ // when
407
+ const isContributing = quest . isCampaignParticipationContributingToQuest ( {
408
+ data,
409
+ campaignParticipationId : campaignParticipationIdToCheck ,
410
+ } ) ;
411
+
412
+ // then
413
+ expect ( isContributing ) . to . be . false ;
414
+ } ) ;
415
+
416
+ it ( 'return true if one of campaignParticipation eligibilityRequirement is valid given campaignParticipationId' , function ( ) {
417
+ // given
418
+ const eligibilityRequirements = [
419
+ {
420
+ requirement_type : REQUIREMENT_TYPES . OBJECT . ORGANIZATION ,
421
+ data : {
422
+ type : {
423
+ data : 'SCO' ,
424
+ comparison : CRITERION_COMPARISONS . EQUAL ,
425
+ } ,
426
+ } ,
427
+ comparison : REQUIREMENT_COMPARISONS . ALL ,
428
+ } ,
429
+ {
430
+ requirement_type : REQUIREMENT_TYPES . OBJECT . CAMPAIGN_PARTICIPATIONS ,
431
+ data : {
432
+ targetProfileId : {
433
+ data : 1 ,
434
+ comparison : CRITERION_COMPARISONS . EQUAL ,
435
+ } ,
436
+ } ,
437
+ comparison : REQUIREMENT_COMPARISONS . ALL ,
438
+ } ,
439
+ {
440
+ requirement_type : REQUIREMENT_TYPES . OBJECT . CAMPAIGN_PARTICIPATIONS ,
441
+ data : {
442
+ targetProfileId : {
443
+ data : 2 ,
444
+ comparison : CRITERION_COMPARISONS . EQUAL ,
445
+ } ,
446
+ } ,
447
+ comparison : REQUIREMENT_COMPARISONS . ALL ,
448
+ } ,
449
+ ] ;
450
+ const quest = new Quest ( { eligibilityRequirements, successRequirements : [ ] } ) ;
451
+ const campaignParticipations = [
452
+ { id : 10 , targetProfileId : 1 } ,
453
+ { id : 11 , targetProfileId : 3 } ,
454
+ ] ;
455
+ const eligibility = new Eligibility ( { organization, organizationLearner, campaignParticipations } ) ;
456
+ const data = new DataForQuest ( { eligibility } ) ;
457
+ const campaignParticipationIdToCheck = 10 ;
458
+
459
+ // when
460
+ const isContributing = quest . isCampaignParticipationContributingToQuest ( {
461
+ data,
462
+ campaignParticipationId : campaignParticipationIdToCheck ,
463
+ } ) ;
464
+
465
+ // then
466
+ expect ( isContributing ) . to . be . true ;
467
+ } ) ;
468
+ } ) ;
469
+
470
+ context ( 'eligibilityRequirement without campaignParticipation type' , function ( ) {
471
+ it ( 'return false' , function ( ) {
472
+ // given
473
+ const eligibilityRequirements = [
474
+ {
475
+ requirement_type : REQUIREMENT_TYPES . OBJECT . ORGANIZATION ,
476
+ data : {
477
+ type : {
478
+ data : 'SCO' ,
479
+ comparison : CRITERION_COMPARISONS . EQUAL ,
480
+ } ,
481
+ } ,
482
+ comparison : REQUIREMENT_COMPARISONS . ALL ,
483
+ } ,
484
+ {
485
+ requirement_type : REQUIREMENT_TYPES . OBJECT . ORGANIZATION_LEARNER ,
486
+ data : {
487
+ type : {
488
+ id : 123 ,
489
+ comparison : CRITERION_COMPARISONS . EQUAL ,
490
+ } ,
491
+ } ,
492
+ comparison : REQUIREMENT_COMPARISONS . ALL ,
493
+ } ,
494
+ ] ;
495
+ const quest = new Quest ( { eligibilityRequirements, successRequirements : [ ] } ) ;
496
+ const campaignParticipations = [ { id : 10 } , { id : 11 } ] ;
497
+ const eligibility = new Eligibility ( { organization, organizationLearner, campaignParticipations } ) ;
498
+ const data = new DataForQuest ( { eligibility } ) ;
499
+ const campaignParticipationIdToCheck = 10 ;
500
+
501
+ // when
502
+ const isContributing = quest . isCampaignParticipationContributingToQuest ( {
503
+ data,
504
+ campaignParticipationId : campaignParticipationIdToCheck ,
505
+ } ) ;
506
+
507
+ // then
508
+ expect ( isContributing ) . to . be . false ;
509
+ } ) ;
510
+ } ) ;
511
+ } ) ;
512
+
358
513
describe ( '#toDTO' , function ( ) {
359
514
it ( 'should return a DTO version of the Quest' , function ( ) {
360
515
// given
0 commit comments