@@ -21,44 +21,47 @@ beforeAll(() => {
2121 notificationUrl = configureNotificationServerUrl ( ) ;
2222} ) ;
2323
24- describe ( "Number Verification authentication " , ( ) => {
24+ describe ( "Number Verification authorization " , ( ) => {
2525 it ( "should retrieve credentials" , async ( ) => {
26- const credentials : any = await client . authentication . credentials ( ) ;
26+ const credentials : any = await client . authorization . credentials ( ) ;
2727 expect ( credentials . clientId ) . toBeTruthy ( ) ;
2828 expect ( credentials . clientSecret ) . toBeTruthy ( ) ;
2929 } ) ;
3030
3131 it ( "should retrieve endpoints" , async ( ) => {
32- const endpoints : any = await client . authentication . endpoints ( ) ;
33- expect ( endpoints . authorizationEndpoint ) . toBeTruthy ( ) ;
34- expect ( endpoints . tokenEndpoint ) . toBeTruthy ( ) ;
32+ const endpoints : any = await client . authorization . endpoints ( ) ;
33+ expect ( endpoints . fastFlowCspAuthEndpoint ) . toBeTruthy ( ) ;
3534 } ) ;
3635
37- it ( "should create authentication link" , async ( ) => {
38- const credentials : any = await client . authentication . credentials ( ) ;
39- const endpoints : any = await client . authentication . endpoints ( ) ;
36+ it ( "should create authorization link" , async ( ) => {
37+ const credentials : any = await client . authorization . credentials ( ) ;
38+ const endpoints : any = await client . authorization . endpoints ( ) ;
4039 const redirectUri = "https://example.com/redirect" ;
4140 const scope = "dpv:FraudPreventionAndDetection number-verification:verify" ;
4241 const loginHint = "+99999991000" ;
43- const callback = await client . authentication . createAuthenticationLink (
42+ const state = "testState" ;
43+ const callback = await client . authorization . createAuthorizationLink (
4444 redirectUri ,
4545 scope ,
46- loginHint
46+ loginHint ,
47+ state
4748 ) ;
4849 expect ( callback )
49- . toEqual ( `${ endpoints . authorizationEndpoint } ?response_type=code&client_id=${ credentials . clientId } &redirect_uri=https%3A%2F%2Fexample.com%2Fredirect&scope=dpv%3AFraudPreventionAndDetection%20number-verification%3Averify&login_hint=%2B99999991000` ) ;
50+ . toEqual ( `${ endpoints . fastFlowCspAuthEndpoint } ?response_type=code&client_id=${ credentials . clientId } &redirect_uri=https%3A%2F%2Fexample.com%2Fredirect&scope=dpv%3AFraudPreventionAndDetection%20number-verification%3Averify&login_hint=%2B99999991000&state=testState ` ) ;
5051 } ) ;
5152} ) ;
5253
53- describe ( "Number Verification NaC auth code and access token " , ( ) => {
54- it ( "should get NaC auth code" , async ( ) => {
54+ describe ( "Number Verification NaC auth code" , ( ) => {
55+ it ( "should get NaC auth code and state " , async ( ) => {
5556 const redirectUri = `${ notificationUrl } /nv` ;
5657 const scope = "dpv:FraudPreventionAndDetection number-verification:verify" ;
5758 const loginHint = "+99999991000" ;
58- const callback = await client . authentication . createAuthenticationLink (
59+ const state = "testState" ;
60+ const callback = await client . authorization . createAuthorizationLink (
5961 redirectUri ,
6062 scope ,
61- loginHint
63+ loginHint ,
64+ state
6265 ) ;
6366 await fetch ( callback , {
6467 method : "GET" ,
@@ -71,123 +74,92 @@ describe("Number Verification NaC auth code and access token", () => {
7174 agent : agent
7275 } ) ;
7376 const data = await response . json ( ) as any ;
74- const code = data . code
75- expect ( code ) . toBeTruthy ( ) ;
76- } ) ;
77-
78- it ( "should get single use access token" , async ( ) => {
79- const redirectUri = `${ notificationUrl } /nv` ;
80- const scope = "dpv:FraudPreventionAndDetection number-verification:verify" ;
81- const loginHint = "+99999991000" ;
82- const callback = await client . authentication . createAuthenticationLink (
83- redirectUri ,
84- scope ,
85- loginHint
86- ) ;
87- await fetch ( callback , {
88- method : "GET" ,
89- agent : agent
90- } ) ;
91-
92- const response = await fetch ( `${ notificationUrl } /nv-get-code` ,
93- {
94- method : "GET" ,
95- agent : agent
96- } ) ;
97- const data = await response . json ( ) as any ;
98- const code = data . code
99- const accessToken : any = await device . getSingleUseAccessToken ( code ) ;
100- expect ( accessToken . accessToken ) . toBeTruthy ( ) ;
101- expect ( accessToken . tokenType ) . toBeTruthy ( ) ;
102- expect ( accessToken . expiresIn ) . toBeTruthy ( ) ;
77+ expect ( data . code ) . toBeTruthy ( ) ;
78+ expect ( data . state ) . toBeTruthy ( ) ;
10379 } ) ;
10480} ) ;
10581
106- describe ( "Number verification" , ( ) => {
82+ describe ( "Number verification" , ( ) => {
10783 it ( "should verify number - True" , async ( ) => {
10884 const redirectUri = `${ notificationUrl } /nv` ;
10985 const scope = "dpv:FraudPreventionAndDetection number-verification:verify" ;
11086 const loginHint = "+99999991000" ;
111- const callback = await client . authentication . createAuthenticationLink (
87+ const state = "testState" ;
88+ const callback = await client . authorization . createAuthorizationLink (
11289 redirectUri ,
11390 scope ,
114- loginHint
91+ loginHint ,
92+ state
11593 ) ;
11694 await fetch ( callback , {
11795 method : "GET" ,
11896 agent : agent
11997 } ) ;
12098
12199 const response = await fetch ( `${ notificationUrl } /nv-get-code` ,
122- {
123- method : "GET" ,
124- agent : agent
125- } ) ;
100+ {
101+ method : "GET" ,
102+ agent : agent
103+ } ) ;
126104 const data = await response . json ( ) as any ;
127- const code = data . code
128- const result : boolean = await device . verifyNumber ( code ) ;
105+ const result : boolean = await device . verifyNumber ( data . code , data . state ) ;
129106 expect ( result ) . toBeTruthy ( ) ;
130107 } ) ;
131108
132- it . skip ( "should verify number - False" , async ( ) => {
109+ it ( "should verify number - False" , async ( ) => {
110+ device = client . devices . get ( {
111+ phoneNumber : "+99999991001"
112+ } ) ;
133113 const redirectUri = `${ notificationUrl } /nv` ;
134114 const scope = "dpv:FraudPreventionAndDetection number-verification:verify" ;
135115 const loginHint = "+99999991001" ;
136- const callback = await client . authentication . createAuthenticationLink (
116+ const state = "testState" ;
117+ const callback = await client . authorization . createAuthorizationLink (
137118 redirectUri ,
138119 scope ,
139- loginHint
120+ loginHint ,
121+ state
140122 ) ;
141123 await fetch ( callback , {
142124 method : "GET" ,
143125 agent : agent
144126 } ) ;
145127
146128 const response = await fetch ( `${ notificationUrl } /nv-get-code` ,
147- {
148- method : "GET" ,
149- agent : agent
150- } ) ;
129+ {
130+ method : "GET" ,
131+ agent : agent
132+ } ) ;
151133 const data = await response . json ( ) as any ;
152- const code = data . code
153- const result : boolean = await device . verifyNumber ( code ) ;
134+ const result : boolean = await device . verifyNumber ( data . code , data . state ) ;
154135 expect ( result ) . toBeFalsy ( ) ;
155136 } ) ;
156137
157- it ( "should return 400 APIError" , async ( ) => {
158- try {
159- await device . getSingleUseAccessToken ( "1234567" ) ;
160- expect ( true ) . toBe ( false ) ;
161- } catch ( error ) {
162- expect ( error ) . toBeDefined ( ) ;
163- const err = error as Error ;
164- expect ( err . message ) . toEqual ( "400 - Bad Request" ) ;
165- }
166- } ) ;
167138} ) ;
168139describe ( "Get Phone Number" , ( ) => {
169140 it ( "should get device phone number" , async ( ) => {
170141 const redirectUri = `${ notificationUrl } /nv` ;
171142 const scope = "dpv:FraudPreventionAndDetection number-verification:device-phone-number:read" ;
172143 const loginHint = "+99999991000" ;
173- const callback = await client . authentication . createAuthenticationLink (
144+ const state = "testState"
145+ const callback = await client . authorization . createAuthorizationLink (
174146 redirectUri ,
175147 scope ,
176- loginHint
148+ loginHint ,
149+ state
177150 ) ;
178151 await fetch ( callback , {
179152 method : "GET" ,
180153 agent : agent
181154 } ) ;
182155
183156 const response = await fetch ( `${ notificationUrl } /nv-get-code` ,
184- {
185- method : "GET" ,
186- agent : agent
187- } ) ;
157+ {
158+ method : "GET" ,
159+ agent : agent
160+ } ) ;
188161 const data = await response . json ( ) as any ;
189- const code = data . code
190- const result : string = await device . getPhoneNumber ( code ) ;
162+ const result : string = await device . getPhoneNumber ( data . code , data . state ) ;
191163 expect ( result ) . toBeDefined ( ) ;
192164 } ) ;
193165} ) ;
0 commit comments