Always store primary email address into email_address table and also the state (#15956)

* Always store primary email address into email_address table and also the state

* Add lower_email to not convert email to lower as what's added

* Fix fixture

* Fix tests

* Use BeforeInsert to save lower email

* Fix v180 migration

* fix tests

* Fix test

* Remove wrong submited codes

* Fix test

* Fix test

* Fix test

* Add test for v181 migration

* remove change user's email to lower

* Revert change on user's email column

* Fix lower email

* Fix test

* Fix test
This commit is contained in:
Lunny Xiao 2021-06-08 11:52:51 +08:00 committed by GitHub
parent 21cde5c439
commit b9d611e917
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 594 additions and 237 deletions

View file

@ -33,7 +33,7 @@ func TestAPIListEmails(t *testing.T) {
Primary: true,
},
{
Email: "user21@example.com",
Email: "user2-2@example.com",
Verified: false,
Primary: false,
},
@ -55,7 +55,7 @@ func TestAPIAddEmail(t *testing.T) {
session.MakeRequest(t, req, http.StatusUnprocessableEntity)
opts = api.CreateEmailOption{
Emails: []string{"user22@example.com"},
Emails: []string{"user2-3@example.com"},
}
req = NewRequestWithJSON(t, "POST", "/api/v1/user/emails?token="+token, &opts)
resp := session.MakeRequest(t, req, http.StatusCreated)
@ -64,7 +64,7 @@ func TestAPIAddEmail(t *testing.T) {
DecodeJSON(t, resp, &emails)
assert.EqualValues(t, []*api.Email{
{
Email: "user22@example.com",
Email: "user2-3@example.com",
Verified: true,
Primary: false,
},
@ -79,13 +79,13 @@ func TestAPIDeleteEmail(t *testing.T) {
token := getTokenForLoggedInUser(t, session)
opts := api.DeleteEmailOption{
Emails: []string{"user22@example.com"},
Emails: []string{"user2-3@example.com"},
}
req := NewRequestWithJSON(t, "DELETE", "/api/v1/user/emails?token="+token, &opts)
session.MakeRequest(t, req, http.StatusNotFound)
opts = api.DeleteEmailOption{
Emails: []string{"user21@example.com"},
Emails: []string{"user2-2@example.com"},
}
req = NewRequestWithJSON(t, "DELETE", "/api/v1/user/emails?token="+token, &opts)
session.MakeRequest(t, req, http.StatusNoContent)