@@ -497,6 +497,7 @@ describe('addQuestion', () => {
497
497
let saveStub : SinonStub ;
498
498
let findOneStub : SinonStub ;
499
499
let getNextSequenceValueStub : SinonStub ;
500
+ let collationStub : SinonStub ;
500
501
501
502
beforeEach ( ( ) => {
502
503
req = {
@@ -509,6 +510,8 @@ describe('addQuestion', () => {
509
510
saveStub = sinon . stub ( Question . prototype , 'save' ) ;
510
511
findOneStub = sinon . stub ( Question , 'findOne' ) ;
511
512
getNextSequenceValueStub = sinon . stub ( seq , 'getNextSequenceValue' ) ;
513
+ collationStub = sinon . stub ( ) . returnsThis ( ) ;
514
+ findOneStub . returns ( { collation : collationStub } ) ;
512
515
} ) ;
513
516
514
517
afterEach ( ( ) => {
@@ -523,7 +526,7 @@ describe('addQuestion', () => {
523
526
difficulty : 'easy' ,
524
527
} ;
525
528
526
- findOneStub . resolves ( null ) ;
529
+ collationStub . resolves ( null ) ;
527
530
getNextSequenceValueStub . resolves ( 1 ) ;
528
531
saveStub . resolves ( {
529
532
id : 1 ,
@@ -627,7 +630,7 @@ describe('addQuestion', () => {
627
630
difficulty : 'easy' ,
628
631
} ;
629
632
630
- findOneStub . resolves ( {
633
+ collationStub . resolves ( {
631
634
id : 1 ,
632
635
title : 'Existing Question' ,
633
636
description : 'Existing Description' ,
@@ -655,10 +658,10 @@ describe('addQuestion', () => {
655
658
difficulty : 'easy' ,
656
659
} ;
657
660
658
- findOneStub . resolves ( {
661
+ collationStub . resolves ( {
659
662
id : 1 ,
660
663
title : 'Existing Question' ,
661
- description : 'Existing Description ' ,
664
+ description : 'Exiing Dstescription ' ,
662
665
topics : [ 'topic1' ] ,
663
666
difficulty : 'easy' ,
664
667
} ) ;
@@ -668,7 +671,7 @@ describe('addQuestion', () => {
668
671
expect ( findOneStub ) . to . have . been . calledWith ( {
669
672
$or : [ { title : 'Non-Existing Question' } , { description : 'Existing Description' } ] ,
670
673
} ) ;
671
- expect ( res . status ) . to . have . been . calledWith ( 500 ) ;
674
+ expect ( res . status ) . to . have . been . calledWith ( 400 ) ;
672
675
expect ( res . json ) . to . have . been . calledWith ( {
673
676
status : 'Error' ,
674
677
message : 'A question with the same title or description already exists.' ,
@@ -695,29 +698,6 @@ describe('addQuestion', () => {
695
698
} ) ;
696
699
} ) ;
697
700
698
- it ( 'should add a new question successfully' , async ( ) => {
699
- await addQuestion ( req as Request , res as Response ) ;
700
-
701
- expect ( findOneStub ) . to . have . been . calledWith ( {
702
- $or : [ { title : 'New Question' } , { description : 'New Description' } ] ,
703
- } ) ;
704
- expect ( getNextSequenceValueStub ) . to . have . been . calledWith ( 'questionId' ) ;
705
- // eslint-disable-next-line @typescript-eslint/no-unused-expressions
706
- expect ( saveStub ) . to . have . been . calledOnce ;
707
- expect ( res . status ) . to . have . been . calledWith ( 201 ) ;
708
- expect ( res . json ) . to . have . been . calledWith ( {
709
- status : 'Success' ,
710
- message : 'Question created successfully' ,
711
- data : {
712
- id : 1 ,
713
- title : 'New Question' ,
714
- description : 'New Description' ,
715
- topics : [ 'topic1' ] ,
716
- difficulty : 'easy' ,
717
- } ,
718
- } ) ;
719
- } ) ;
720
-
721
701
it ( 'should return bad request if title is missing' , async ( ) => {
722
702
req . body = {
723
703
description : 'New Description' ,
@@ -790,7 +770,7 @@ describe('addQuestion', () => {
790
770
difficulty : 'easy' ,
791
771
} ;
792
772
793
- findOneStub . resolves ( {
773
+ collationStub . resolves ( {
794
774
id : 1 ,
795
775
title : 'Existing Question' ,
796
776
description : 'Existing Description' ,
0 commit comments