-
Notifications
You must be signed in to change notification settings - Fork 311
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
is: Add primary_email_address test case
- Loading branch information
1 parent
d93fb1b
commit dc24d41
Showing
1 changed file
with
63 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -251,6 +251,16 @@ func TestUsersCRUD(t *testing.T) { | |
|
||
usr1 := p.NewUser() | ||
usr1.Password = "OldPassword" | ||
usr1.PrimaryEmailAddress = "[email protected]" | ||
validatedAtTime := time.Now().Truncate(time.Millisecond) | ||
usr1.PrimaryEmailAddressValidatedAt = ttnpb.ProtoTime(&validatedAtTime) | ||
// NOTE: Remove this when the deprecated field is removed. | ||
// (https://github.com/TheThingsIndustries/lorawan-stack/issues/3830) | ||
usr1.ContactInfo = append(usr1.ContactInfo, &ttnpb.ContactInfo{ | ||
ContactMethod: ttnpb.ContactMethod_CONTACT_METHOD_EMAIL, | ||
Value: usr1.PrimaryEmailAddress, | ||
ValidatedAt: usr1.PrimaryEmailAddressValidatedAt, | ||
}) | ||
|
||
key, _ := p.NewAPIKey(usr1.GetEntityIdentifiers(), ttnpb.Right_RIGHT_ALL) | ||
creds := rpcCreds(key) | ||
|
@@ -345,11 +355,61 @@ func TestUsersCRUD(t *testing.T) { | |
}) | ||
|
||
t.Run("PrimaryEmailAddress", func(t *testing.T) { // nolint:paralleltest | ||
a, ctx := test.New(t) | ||
t.Run("admin update", func(t *testing.T) { // nolint:paralleltest | ||
a, ctx := test.New(t) | ||
got, err := reg.Update(ctx, &ttnpb.UpdateUserRequest{ | ||
User: &ttnpb.User{ | ||
Ids: usr1.GetIds(), | ||
PrimaryEmailAddress: "[email protected]", | ||
}, | ||
FieldMask: ttnpb.FieldMask("primary_email_address"), | ||
}, adminUsrCreds) | ||
if a.So(err, should.BeNil) { | ||
a.So(got.PrimaryEmailAddress, should.Equal, "[email protected]") | ||
} | ||
|
||
got, err = reg.Get(ctx, &ttnpb.GetUserRequest{ | ||
UserIds: usr1.GetIds(), | ||
FieldMask: ttnpb.FieldMask( | ||
"primary_email_address", "primary_email_address_validated_at", "contact_info", | ||
), | ||
}, adminUsrCreds) | ||
if a.So(err, should.BeNil) && a.So(got, should.NotBeNil) { | ||
a.So(got.PrimaryEmailAddress, should.Equal, "[email protected]") | ||
a.So(got.PrimaryEmailAddressValidatedAt, should.NotBeNil) | ||
a.So(got.ContactInfo, should.HaveLength, 1) | ||
a.So(got.ContactInfo[0].Value, should.Equal, "[email protected]") | ||
a.So(got.ContactInfo[0].ValidatedAt, should.NotBeNil) | ||
} | ||
}) | ||
|
||
// admin operations | ||
t.Run("non admin update", func(t *testing.T) { // nolint:paralleltest | ||
a, ctx := test.New(t) | ||
got, err := reg.Update(ctx, &ttnpb.UpdateUserRequest{ | ||
User: &ttnpb.User{ | ||
Ids: usr1.GetIds(), | ||
PrimaryEmailAddress: "[email protected]", | ||
}, | ||
FieldMask: ttnpb.FieldMask("primary_email_address"), | ||
}, creds) | ||
if a.So(err, should.BeNil) { | ||
a.So(got.PrimaryEmailAddress, should.Equal, "[email protected]") | ||
} | ||
|
||
// non admin operations | ||
got, err = reg.Get(ctx, &ttnpb.GetUserRequest{ | ||
UserIds: usr1.GetIds(), | ||
FieldMask: ttnpb.FieldMask( | ||
"primary_email_address", "primary_email_address_validated_at", "contact_info", | ||
), | ||
}, creds) | ||
if a.So(err, should.BeNil) && a.So(got, should.NotBeNil) { | ||
a.So(got.PrimaryEmailAddress, should.Equal, "[email protected]") | ||
a.So(got.PrimaryEmailAddressValidatedAt, should.BeNil) | ||
a.So(got.ContactInfo, should.HaveLength, 1) | ||
a.So(got.ContactInfo[0].Value, should.Equal, "[email protected]") | ||
a.So(got.ContactInfo[0].ValidatedAt, should.BeNil) | ||
} | ||
}) | ||
}) | ||
}) | ||
|
||
|