File tree Expand file tree Collapse file tree 1 file changed +39
-0
lines changed Expand file tree Collapse file tree 1 file changed +39
-0
lines changed Original file line number Diff line number Diff line change
1
+ const Sinon = require ( "sinon" ) ;
2
+ const { createChallenge } = require ( "../../../middlewares/validators/challenges" ) ;
3
+ const { expect } = require ( "chai" ) ;
4
+
5
+ describe ( "Middleware | Validators | Challenges" , function ( ) {
6
+ describe ( "create challenge validator" , function ( ) {
7
+ it ( "lets the request pass to next" , async function ( ) {
8
+ const req = {
9
+ body : {
10
+ level : "Noob" ,
11
+ title : "The noob challenge" ,
12
+ start_date : 1254324345 ,
13
+ end_date : 354654345 ,
14
+ } ,
15
+ } ;
16
+ const res = { } ;
17
+ const nextSpy = Sinon . spy ( ) ;
18
+ await createChallenge ( req , res , nextSpy ) ;
19
+ expect ( nextSpy . calledOnce ) . to . be . equal ( true ) ;
20
+ } ) ;
21
+ it ( "Stops the propogation of the next" , async function ( ) {
22
+ const req = {
23
+ body : {
24
+ level : "Noob" ,
25
+ } ,
26
+ } ;
27
+ const res = {
28
+ boom : {
29
+ badRequest : ( ) => { } ,
30
+ } ,
31
+ } ;
32
+ const nextSpy = Sinon . spy ( ) ;
33
+ await createChallenge ( req , res , nextSpy ) . catch ( ( err ) => {
34
+ expect ( err ) . to . be . an . instanceOf ( Error ) ;
35
+ } ) ;
36
+ expect ( nextSpy . calledOnce ) . to . be . equal ( false ) ;
37
+ } ) ;
38
+ } ) ;
39
+ } ) ;
You can’t perform that action at this time.
0 commit comments