@@ -26,6 +26,7 @@ import * as identity from "../../../src/common/providers/identity";
26
26
27
27
const EVENT = "EVENT_TYPE" ;
28
28
const now = new Date ( ) ;
29
+ const TEST_NAME = "John Doe" ;
29
30
30
31
describe ( "identity" , ( ) => {
31
32
describe ( "userRecordConstructor" , ( ) => {
@@ -232,14 +233,14 @@ describe("identity", () => {
232
233
describe ( "parseProviderData" , ( ) => {
233
234
const decodedUserInfo = {
234
235
provider_id : "google.com" ,
235
- display_name : "John Doe" ,
236
+ display_name : TEST_NAME ,
236
237
photo_url : "https://lh3.googleusercontent.com/1234567890/photo.jpg" ,
237
238
uid : "1234567890" ,
238
239
239
240
} ;
240
241
const userInfo = {
241
242
providerId : "google.com" ,
242
- displayName : "John Doe" ,
243
+ displayName : TEST_NAME ,
243
244
photoURL : "https://lh3.googleusercontent.com/1234567890/photo.jpg" ,
244
245
uid : "1234567890" ,
245
246
@@ -340,12 +341,12 @@ describe("identity", () => {
340
341
uid : "abcdefghijklmnopqrstuvwxyz" ,
341
342
342
343
email_verified : true ,
343
- display_name : "John Doe" ,
344
+ display_name : TEST_NAME ,
344
345
phone_number : "+11234567890" ,
345
346
provider_data : [
346
347
{
347
348
provider_id : "google.com" ,
348
- display_name : "John Doe" ,
349
+ display_name : TEST_NAME ,
349
350
photo_url : "https://lh3.googleusercontent.com/1234567890/photo.jpg" ,
350
351
351
352
uid : "1234567890" ,
@@ -366,7 +367,7 @@ describe("identity", () => {
366
367
provider_id : "password" ,
367
368
368
369
369
- display_name : "John Doe" ,
370
+ display_name : TEST_NAME ,
370
371
} ,
371
372
] ,
372
373
password_hash : "passwordHash" ,
@@ -407,11 +408,11 @@ describe("identity", () => {
407
408
phoneNumber : "+11234567890" ,
408
409
emailVerified : true ,
409
410
disabled : false ,
410
- displayName : "John Doe" ,
411
+ displayName : TEST_NAME ,
411
412
providerData : [
412
413
{
413
414
providerId : "google.com" ,
414
- displayName : "John Doe" ,
415
+ displayName : TEST_NAME ,
415
416
photoURL : "https://lh3.googleusercontent.com/1234567890/photo.jpg" ,
416
417
417
418
uid : "1234567890" ,
@@ -435,7 +436,7 @@ describe("identity", () => {
435
436
} ,
436
437
{
437
438
providerId : "password" ,
438
- displayName : "John Doe" ,
439
+ displayName : TEST_NAME ,
439
440
photoURL : undefined ,
440
441
441
442
@@ -489,8 +490,9 @@ describe("identity", () => {
489
490
} ) ;
490
491
491
492
describe ( "parseAuthEventContext" , ( ) => {
493
+ const TEST_RECAPTCHA_SCORE = 0.9 ;
492
494
const rawUserInfo = {
493
- name : "John Doe" ,
495
+ name : TEST_NAME ,
494
496
granted_scopes :
495
497
"openid https://www.googleapis.com/auth/userinfo.email https://www.googleapis.com/auth/userinfo.profile" ,
496
498
id : "123456789" ,
@@ -516,6 +518,7 @@ describe("identity", () => {
516
518
user_agent : "USER_AGENT" ,
517
519
locale : "en" ,
518
520
raw_user_info : JSON . stringify ( rawUserInfo ) ,
521
+ recaptcha_score : TEST_RECAPTCHA_SCORE ,
519
522
} ;
520
523
const context = {
521
524
locale : "en" ,
@@ -534,6 +537,7 @@ describe("identity", () => {
534
537
profile : rawUserInfo ,
535
538
username : undefined ,
536
539
isNewUser : false ,
540
+ recaptchaScore : TEST_RECAPTCHA_SCORE ,
537
541
} ,
538
542
credential : null ,
539
543
params : { } ,
@@ -563,6 +567,7 @@ describe("identity", () => {
563
567
oauth_refresh_token : "REFRESH_TOKEN" ,
564
568
oauth_token_secret : "OAUTH_TOKEN_SECRET" ,
565
569
oauth_expires_in : 3600 ,
570
+ recaptcha_score : TEST_RECAPTCHA_SCORE ,
566
571
} ;
567
572
const context = {
568
573
locale : "en" ,
@@ -581,6 +586,7 @@ describe("identity", () => {
581
586
profile : rawUserInfo ,
582
587
username : undefined ,
583
588
isNewUser : false ,
589
+ recaptchaScore : TEST_RECAPTCHA_SCORE ,
584
590
} ,
585
591
credential : {
586
592
claims : undefined ,
@@ -619,14 +625,14 @@ describe("identity", () => {
619
625
uid : "abcdefghijklmnopqrstuvwxyz" ,
620
626
621
627
email_verified : true ,
622
- display_name : "John Doe" ,
628
+ display_name : TEST_NAME ,
623
629
phone_number : "+11234567890" ,
624
630
provider_data : [
625
631
{
626
632
provider_id : "oidc.provider" ,
627
633
628
634
629
- display_name : "John Doe" ,
635
+ display_name : TEST_NAME ,
630
636
} ,
631
637
] ,
632
638
photo_url : "https://lh3.googleusercontent.com/1234567890/photo.jpg" ,
@@ -647,6 +653,7 @@ describe("identity", () => {
647
653
oauth_token_secret : "OAUTH_TOKEN_SECRET" ,
648
654
oauth_expires_in : 3600 ,
649
655
raw_user_info : JSON . stringify ( rawUserInfo ) ,
656
+ recaptcha_score : TEST_RECAPTCHA_SCORE ,
650
657
} ;
651
658
const context = {
652
659
locale : "en" ,
@@ -665,6 +672,7 @@ describe("identity", () => {
665
672
providerId : "oidc.provider" ,
666
673
profile : rawUserInfo ,
667
674
isNewUser : true ,
675
+ recaptchaScore : TEST_RECAPTCHA_SCORE ,
668
676
} ,
669
677
credential : {
670
678
claims : undefined ,
@@ -762,4 +770,38 @@ describe("identity", () => {
762
770
) ;
763
771
} ) ;
764
772
} ) ;
773
+
774
+ describe ( "generateRequestPayload" , ( ) => {
775
+ const DISPLAY_NAME_FILED = "displayName" ;
776
+ const TEST_RESPONSE = {
777
+ displayName : TEST_NAME ,
778
+ recaptchaPassed : false ,
779
+ } as identity . BeforeCreateResponse ;
780
+
781
+ const EXPECT_PAYLOAD = {
782
+ userRecord : { displayName : TEST_NAME , updateMask : DISPLAY_NAME_FILED } ,
783
+ recaptchaPassed : false ,
784
+ } ;
785
+
786
+ const TEST_RESPONSE_RECAPTCHA_UNDEFINED = {
787
+ displayName : TEST_NAME ,
788
+ } as identity . BeforeSignInResponse ;
789
+
790
+ const EXPECT_PAYLOAD_UNDEFINED = {
791
+ userRecord : { displayName : TEST_NAME , updateMask : DISPLAY_NAME_FILED } ,
792
+ } ;
793
+ it ( "should return empty string on undefined response" , ( ) => {
794
+ expect ( identity . generateRequestPayload ( ) ) . to . eq ( "" ) ;
795
+ } ) ;
796
+
797
+ it ( "should exclude recaptchaPass field from updateMask" , ( ) => {
798
+ expect ( identity . generateRequestPayload ( TEST_RESPONSE ) ) . to . deep . equal ( EXPECT_PAYLOAD ) ;
799
+ } ) ;
800
+
801
+ it ( "should not return recaptchaPass if undefined" , ( ) => {
802
+ const payload = identity . generateRequestPayload ( TEST_RESPONSE_RECAPTCHA_UNDEFINED ) ;
803
+ expect ( payload . hasOwnProperty ( "recaptchaPassed" ) ) . to . be . false ;
804
+ expect ( payload ) . to . deep . equal ( EXPECT_PAYLOAD_UNDEFINED ) ;
805
+ } ) ;
806
+ } ) ;
765
807
} ) ;
0 commit comments