@@ -40,6 +40,7 @@ func TestUserList(t *testing.T) {
40
40
users : []models.User {
41
41
{
42
42
ID : "507f1f77bcf86cd799439011" ,
43
+ ExternalID : "01JEVPB55XVSK890Z2MYKMWXXY" ,
43
44
CreatedAt : time .Date (2023 , 1 , 1 , 12 , 0 , 0 , 0 , time .UTC ),
44
45
LastLogin : time .Date (2023 , 1 , 1 , 12 , 0 , 0 , 0 , time .UTC ),
45
46
EmailMarketing : true ,
@@ -289,6 +290,7 @@ func TestStore_UserCreateInvited(t *testing.T) {
289
290
tt ,
290
291
map [string ]interface {}{
291
292
"_id" : objID ,
293
+ "external_id" : nil ,
292
294
"created_at" : primitive .NewDateTimeFromTime (now ),
293
295
"last_login" : primitive .NewDateTimeFromTime (time.Time {}),
294
296
"origin" : nil ,
@@ -337,6 +339,7 @@ func TestUserGetByUsername(t *testing.T) {
337
339
expected : Expected {
338
340
user : & models.User {
339
341
ID : "507f1f77bcf86cd799439011" ,
342
+ ExternalID : "01JEVPB55XVSK890Z2MYKMWXXY" ,
340
343
CreatedAt : time .Date (2023 , 1 , 1 , 12 , 0 , 0 , 0 , time .UTC ),
341
344
LastLogin : time .Date (2023 , 1 , 1 , 12 , 0 , 0 , 0 , time .UTC ),
342
345
EmailMarketing : true ,
@@ -399,6 +402,7 @@ func TestUserGetByEmail(t *testing.T) {
399
402
expected : Expected {
400
403
user : & models.User {
401
404
ID : "507f1f77bcf86cd799439011" ,
405
+ ExternalID : "01JEVPB55XVSK890Z2MYKMWXXY" ,
402
406
CreatedAt : time .Date (2023 , 1 , 1 , 12 , 0 , 0 , 0 , time .UTC ),
403
407
LastLogin : time .Date (2023 , 1 , 1 , 12 , 0 , 0 , 0 , time .UTC ),
404
408
EmailMarketing : true ,
@@ -465,6 +469,7 @@ func TestUserGetByID(t *testing.T) {
465
469
expected : Expected {
466
470
user : & models.User {
467
471
ID : "507f1f77bcf86cd799439011" ,
472
+ ExternalID : "01JEVPB55XVSK890Z2MYKMWXXY" ,
468
473
CreatedAt : time .Date (2023 , 1 , 1 , 12 , 0 , 0 , 0 , time .UTC ),
469
474
LastLogin : time .Date (2023 , 1 , 1 , 12 , 0 , 0 , 0 , time .UTC ),
470
475
EmailMarketing : true ,
@@ -491,6 +496,7 @@ func TestUserGetByID(t *testing.T) {
491
496
expected : Expected {
492
497
user : & models.User {
493
498
ID : "507f1f77bcf86cd799439011" ,
499
+ ExternalID : "01JEVPB55XVSK890Z2MYKMWXXY" ,
494
500
CreatedAt : time .Date (2023 , 1 , 1 , 12 , 0 , 0 , 0 , time .UTC ),
495
501
LastLogin : time .Date (2023 , 1 , 1 , 12 , 0 , 0 , 0 , time .UTC ),
496
502
EmailMarketing : true ,
@@ -526,6 +532,74 @@ func TestUserGetByID(t *testing.T) {
526
532
}
527
533
}
528
534
535
+ func TestUserGetByExternalID (t * testing.T ) {
536
+ type Expected struct {
537
+ user * models.User
538
+ ns int
539
+ err error
540
+ }
541
+
542
+ cases := []struct {
543
+ description string
544
+ externalID string
545
+ ns bool
546
+ fixtures []string
547
+ expected Expected
548
+ }{
549
+ {
550
+ description : "fails when user is not found" ,
551
+ externalID : "invalid" ,
552
+ fixtures : []string {fixtureUsers },
553
+ expected : Expected {
554
+ user : nil ,
555
+ ns : 0 ,
556
+ err : store .ErrNoDocuments ,
557
+ },
558
+ },
559
+ {
560
+ description : "succeeds when user is found with ns equal false" ,
561
+ externalID : "01JEVPB55XVSK890Z2MYKMWXXY" ,
562
+ ns : false ,
563
+ fixtures : []string {fixtureUsers },
564
+ expected : Expected {
565
+ user : & models.User {
566
+ ID : "507f1f77bcf86cd799439011" ,
567
+ ExternalID : "01JEVPB55XVSK890Z2MYKMWXXY" ,
568
+ CreatedAt : time .Date (2023 , 1 , 1 , 12 , 0 , 0 , 0 , time .UTC ),
569
+ LastLogin : time .Date (2023 , 1 , 1 , 12 , 0 , 0 , 0 , time .UTC ),
570
+ EmailMarketing : true ,
571
+ Status : models .UserStatusConfirmed ,
572
+ UserData : models.UserData {
573
+ Name : "john doe" ,
574
+ Username : "john_doe" ,
575
+
576
+ },
577
+ MaxNamespaces : 0 ,
578
+ Password : models.UserPassword {
579
+ Hash : "fcf730b6d95236ecd3c9fc2d92d7b6b2bb061514961aec041d6c7a7192f592e4" ,
580
+ },
581
+ },
582
+ ns : 0 ,
583
+ err : nil ,
584
+ },
585
+ },
586
+ }
587
+
588
+ for _ , tc := range cases {
589
+ t .Run (tc .description , func (t * testing.T ) {
590
+ ctx := context .Background ()
591
+
592
+ assert .NoError (t , srv .Apply (tc .fixtures ... ))
593
+ t .Cleanup (func () {
594
+ assert .NoError (t , srv .Reset ())
595
+ })
596
+
597
+ user , err := s .UserGetByExternalID (ctx , tc .externalID )
598
+ assert .Equal (t , tc .expected , Expected {user : user , err : err })
599
+ })
600
+ }
601
+ }
602
+
529
603
func TestUserConflicts (t * testing.T ) {
530
604
type Expected struct {
531
605
conflicts []string
0 commit comments