1+ import sinon from "sinon" ;
2+ import { skipAuthenticateForOnboardingExtensionRequest } from "../../../middlewares/skipAuthenticateForOnboardingExtension" ;
3+ import { REQUEST_TYPE } from "../../../constants/requests" ;
4+ import { assert } from "chai" ;
5+
6+ describe ( "skipAuthenticateForOnboardingExtensionRequest Middleware" , ( ) => {
7+ let req , res , next , authenticate : sinon . SinonSpy , verifyDiscordBot : sinon . SinonSpy ;
8+
9+ beforeEach ( ( ) => {
10+ authenticate = sinon . spy ( ) ;
11+ verifyDiscordBot = sinon . spy ( ) ;
12+ req = {
13+ body :{ } ,
14+ query :{ } ,
15+ } ,
16+ res = { }
17+ } ) ;
18+
19+ it ( "should call authenticate when type is not onboarding" , ( ) => {
20+ req . body . type = REQUEST_TYPE . TASK
21+ const middleware = skipAuthenticateForOnboardingExtensionRequest ( authenticate , verifyDiscordBot ) ;
22+ middleware ( req , res , next ) ;
23+
24+ assert . isTrue ( authenticate . calledOnce , "authenticate should be called once" ) ;
25+ assert . isTrue ( verifyDiscordBot . notCalled , "verifyDiscordBot should not be called" ) ;
26+ } ) ;
27+
28+ it ( "should not call verifyDicordBot and authenticate when dev is not true and type is onboarding" , async ( ) => {
29+ req . query . dev = "false" ;
30+ req . body . type = REQUEST_TYPE . ONBOARDING ;
31+
32+ const middleware = skipAuthenticateForOnboardingExtensionRequest ( authenticate , verifyDiscordBot ) ;
33+ middleware ( req , res , next ) ;
34+
35+ assert . isTrue ( verifyDiscordBot . notCalled , "verifyDiscordBot should not be called" ) ;
36+ assert . isTrue ( authenticate . notCalled , "authenticate should not be called" ) ;
37+ } ) ;
38+
39+ it ( "should call verifyDiscordBot when dev is true and type is onboarding" , ( ) => {
40+ req . query . dev = "true" ;
41+ req . body . type = REQUEST_TYPE . ONBOARDING ;
42+
43+ const middleware = skipAuthenticateForOnboardingExtensionRequest ( authenticate , verifyDiscordBot ) ;
44+ middleware ( req , res , next ) ;
45+
46+ assert . isTrue ( verifyDiscordBot . calledOnce , "verifyDiscordBot should be called once" ) ;
47+ assert . isTrue ( authenticate . notCalled , "authenticate should not be called" ) ;
48+ } ) ;
49+ } ) ;
0 commit comments