@@ -39,7 +39,7 @@ import * as client from './client';
39
39
import * as storage from './storage' ;
40
40
import * as logger from './logger' ;
41
41
import * as util from './util' ;
42
- import { ReCAPTCHAV3Provider } from './providers' ;
42
+ import { ReCaptchaV3Provider } from './providers' ;
43
43
44
44
describe ( 'api' , ( ) => {
45
45
beforeEach ( ( ) => {
@@ -56,7 +56,7 @@ describe('api', () => {
56
56
expect ( getState ( app ) . activated ) . to . equal ( false ) ;
57
57
activate (
58
58
app ,
59
- new ReCAPTCHAV3Provider ( FAKE_SITE_KEY ) ,
59
+ new ReCaptchaV3Provider ( FAKE_SITE_KEY ) ,
60
60
getFakePlatformLoggingProvider ( )
61
61
) ;
62
62
expect ( getState ( app ) . activated ) . to . equal ( true ) ;
@@ -66,7 +66,7 @@ describe('api', () => {
66
66
app = getFakeApp ( { automaticDataCollectionEnabled : false } ) ;
67
67
activate (
68
68
app ,
69
- new ReCAPTCHAV3Provider ( FAKE_SITE_KEY ) ,
69
+ new ReCaptchaV3Provider ( FAKE_SITE_KEY ) ,
70
70
getFakePlatformLoggingProvider ( )
71
71
) ;
72
72
expect ( getState ( app ) . isTokenAutoRefreshEnabled ) . to . equal ( false ) ;
@@ -76,7 +76,7 @@ describe('api', () => {
76
76
app = getFakeApp ( { automaticDataCollectionEnabled : false } ) ;
77
77
activate (
78
78
app ,
79
- new ReCAPTCHAV3Provider ( FAKE_SITE_KEY ) ,
79
+ new ReCaptchaV3Provider ( FAKE_SITE_KEY ) ,
80
80
getFakePlatformLoggingProvider ( ) ,
81
81
true
82
82
) ;
@@ -86,25 +86,36 @@ describe('api', () => {
86
86
it ( 'can only be called once' , ( ) => {
87
87
activate (
88
88
app ,
89
- new ReCAPTCHAV3Provider ( FAKE_SITE_KEY ) ,
89
+ new ReCaptchaV3Provider ( FAKE_SITE_KEY ) ,
90
90
getFakePlatformLoggingProvider ( )
91
91
) ;
92
92
expect ( ( ) =>
93
93
activate (
94
94
app ,
95
- new ReCAPTCHAV3Provider ( FAKE_SITE_KEY ) ,
95
+ new ReCaptchaV3Provider ( FAKE_SITE_KEY ) ,
96
96
getFakePlatformLoggingProvider ( )
97
97
)
98
98
) . to . throw ( / A p p C h e c k c a n o n l y b e a c t i v a t e d o n c e / ) ;
99
99
} ) ;
100
100
101
- it ( 'initialize reCAPTCHA when a sitekey is provided' , ( ) => {
101
+ it ( 'initialize reCAPTCHA when a sitekey string is provided' , ( ) => {
102
+ const initReCAPTCHAStub = stub ( reCAPTCHA , 'initialize' ) . returns (
103
+ Promise . resolve ( { } as any )
104
+ ) ;
105
+ activate ( app , FAKE_SITE_KEY , getFakePlatformLoggingProvider ( ) ) ;
106
+ expect ( initReCAPTCHAStub ) . to . have . been . calledWithExactly (
107
+ app ,
108
+ FAKE_SITE_KEY
109
+ ) ;
110
+ } ) ;
111
+
112
+ it ( 'initialize reCAPTCHA when a ReCaptchaV3Provider instance is provided' , ( ) => {
102
113
const initReCAPTCHAStub = stub ( reCAPTCHA , 'initialize' ) . returns (
103
114
Promise . resolve ( { } as any )
104
115
) ;
105
116
activate (
106
117
app ,
107
- new ReCAPTCHAV3Provider ( FAKE_SITE_KEY ) ,
118
+ new ReCaptchaV3Provider ( FAKE_SITE_KEY ) ,
108
119
getFakePlatformLoggingProvider ( )
109
120
) ;
110
121
expect ( initReCAPTCHAStub ) . to . have . been . calledWithExactly (
@@ -113,13 +124,22 @@ describe('api', () => {
113
124
) ;
114
125
} ) ;
115
126
116
- it ( 'does NOT initialize reCAPTCHA when a custom token provider is provided' , ( ) => {
117
- const fakeCustomTokenProvider = getFakeCustomTokenProvider ( ) ;
118
- const initReCAPTCHAStub = stub ( reCAPTCHA , 'initialize' ) ;
119
- activate ( app , fakeCustomTokenProvider , getFakePlatformLoggingProvider ( ) ) ;
120
- expect ( getState ( app ) . provider ) . to . equal ( fakeCustomTokenProvider ) ;
121
- expect ( initReCAPTCHAStub ) . to . have . not . been . called ;
122
- } ) ;
127
+ it (
128
+ 'creates CustomProvider instance if user provides an object containing' +
129
+ ' a getToken() method' ,
130
+ async ( ) => {
131
+ const fakeCustomTokenProvider = getFakeCustomTokenProvider ( ) ;
132
+ const initReCAPTCHAStub = stub ( reCAPTCHA , 'initialize' ) ;
133
+ activate (
134
+ app ,
135
+ fakeCustomTokenProvider ,
136
+ getFakePlatformLoggingProvider ( )
137
+ ) ;
138
+ const result = await getState ( app ) . provider ?. getToken ( ) ;
139
+ expect ( result ?. token ) . to . equal ( 'fake-custom-app-check-token' ) ;
140
+ expect ( initReCAPTCHAStub ) . to . have . not . been . called ;
141
+ }
142
+ ) ;
123
143
} ) ;
124
144
describe ( 'setTokenAutoRefreshEnabled()' , ( ) => {
125
145
it ( 'sets isTokenAutoRefreshEnabled correctly' , ( ) => {
@@ -177,7 +197,7 @@ describe('api', () => {
177
197
const app = getFakeApp ( ) ;
178
198
activate (
179
199
app ,
180
- new ReCAPTCHAV3Provider ( FAKE_SITE_KEY ) ,
200
+ new ReCaptchaV3Provider ( FAKE_SITE_KEY ) ,
181
201
fakePlatformLoggingProvider ,
182
202
false
183
203
) ;
@@ -226,7 +246,7 @@ describe('api', () => {
226
246
const app = getFakeApp ( ) ;
227
247
activate (
228
248
app ,
229
- new ReCAPTCHAV3Provider ( FAKE_SITE_KEY ) ,
249
+ new ReCaptchaV3Provider ( FAKE_SITE_KEY ) ,
230
250
fakePlatformLoggingProvider ,
231
251
false
232
252
) ;
@@ -276,7 +296,7 @@ describe('api', () => {
276
296
const app = getFakeApp ( ) ;
277
297
activate (
278
298
app ,
279
- new ReCAPTCHAV3Provider ( FAKE_SITE_KEY ) ,
299
+ new ReCaptchaV3Provider ( FAKE_SITE_KEY ) ,
280
300
fakePlatformLoggingProvider ,
281
301
false
282
302
) ;
0 commit comments