Skip to content

Commit

Permalink
is: Add primary_email_address test case
Browse files Browse the repository at this point in the history
  • Loading branch information
nicholaspcr committed Sep 29, 2023
1 parent d93fb1b commit dc24d41
Showing 1 changed file with 63 additions and 3 deletions.
66 changes: 63 additions & 3 deletions pkg/identityserver/user_registry_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
}
})
})
})

Expand Down

0 comments on commit dc24d41

Please sign in to comment.