@@ -4,7 +4,7 @@ import { describe } from "mocha";
44import { sinon } from "../../../../test/utils/test-utils" ;
55import { Request , Response } from "express" ;
66import {
7- updatedTermsCondsGet ,
7+ updatedTermsCondsGet , updatedTermsCondsMandatoryGet , updatedTermsCondsOptionalGet ,
88 updatedTermsCondsPost ,
99} from "../updated-terms-conds-controller" ;
1010import { UserSession } from "../../../types" ;
@@ -52,6 +52,40 @@ describe("share-info controller", () => {
5252 } ) ;
5353 } ) ;
5454
55+ describe ( "updatedTermsCondsMandatoryGet" , ( ) => {
56+ it ( "should render updated-terms-conds-mandatory page" , async ( ) => {
57+ const fakeService : UpdateTermsAndCondsServiceInterface = {
58+ updateProfile : sandbox . fake ( ) ,
59+ clientInfo : sandbox . fake . returns ( { scopes : [ "openid" , "profile" ] , serviceType : "mandatory" } ) ,
60+ } ;
61+
62+ res . locals . sessionId = "s-123456-djjad" ;
63+ res . locals . clientSessionId = "c-123456-djjad" ;
64+
65+ await updatedTermsCondsMandatoryGet ( fakeService ) ( req as Request , res as Response ) ;
66+
67+ expect ( fakeService . clientInfo ) . to . be . calledOnce ;
68+ expect ( res . render ) . to . have . calledWith ( "updated-terms-conds/index-mandatory.njk" ) ;
69+ } ) ;
70+ } ) ;
71+
72+ describe ( "updatedTermsCondsOptionalGet" , ( ) => {
73+ it ( "should render updated-terms-conds-optional page" , async ( ) => {
74+ const fakeService : UpdateTermsAndCondsServiceInterface = {
75+ updateProfile : sandbox . fake ( ) ,
76+ clientInfo : sandbox . fake . returns ( { scopes : [ "openid" , "profile" ] , serviceType : "optional" } ) ,
77+ } ;
78+
79+ res . locals . sessionId = "s-123456-djjad" ;
80+ res . locals . clientSessionId = "c-123456-djjad" ;
81+
82+ await updatedTermsCondsOptionalGet ( fakeService ) ( req as Request , res as Response ) ;
83+
84+ expect ( fakeService . clientInfo ) . to . be . calledOnce ;
85+ expect ( res . render ) . to . have . calledWith ( "updated-terms-conds/index-optional.njk" ) ;
86+ } ) ;
87+ } ) ;
88+
5589 describe ( "updatedTermsCondsPost" , ( ) => {
5690 it ( "should redirect to /auth-code when acceptOrReject has value accept" , async ( ) => {
5791 const fakeService : UpdateTermsAndCondsServiceInterface = {
@@ -77,7 +111,7 @@ describe("share-info controller", () => {
77111 it ( "should redirect to redirectUri with error code param when acceptOrReject has value reject" , async ( ) => {
78112 const fakeService : UpdateTermsAndCondsServiceInterface = {
79113 updateProfile : sandbox . fake . returns ( true ) ,
80- clientInfo : sandbox . fake . returns ( { scopes : [ "openid" , "profile" ] } ) ,
114+ clientInfo : sandbox . fake . returns ( { scopes : [ "openid" , "profile" ] , state : "test" } ) ,
81115 } ;
82116
83117 req . session . redirectUri = "http://test.test" ;
@@ -87,12 +121,13 @@ describe("share-info controller", () => {
87121 req . session . user = {
88122 email : "test@test.com" ,
89123 } ;
124+ req . session . state = "test" ;
90125
91126 await updatedTermsCondsPost ( fakeService ) ( req as Request , res as Response ) ;
92127
93128 expect ( fakeService . updateProfile ) . not . to . been . called ;
94129 expect ( res . redirect ) . to . have . calledWith (
95- "http://test.test?error_code=rejectedTermsAndConditions"
130+ "http://test.test?error_code=rejectedTermsAndConditions&state=test "
96131 ) ;
97132 } ) ;
98133 } ) ;
0 commit comments