aboutsummaryrefslogtreecommitdiff
path: root/internal/db/email_addresses_test.go
diff options
context:
space:
mode:
authorJoe Chen <jc@unknwon.io>2022-11-27 15:19:44 +0800
committerGitHub <noreply@github.com>2022-11-27 15:19:44 +0800
commit13099a7e4fe7565bb858646d42d1fba817cb06cc (patch)
treeac932d0f5df9f14b0f9408c32f699ae7167edc25 /internal/db/email_addresses_test.go
parenta7dbc970dfaac9f04addf05da97bb0aa29083e37 (diff)
refactor(db): add `Users.Update` (#7263)
Diffstat (limited to 'internal/db/email_addresses_test.go')
-rw-r--r--internal/db/email_addresses_test.go17
1 files changed, 14 insertions, 3 deletions
diff --git a/internal/db/email_addresses_test.go b/internal/db/email_addresses_test.go
index b54ffbad..f55db549 100644
--- a/internal/db/email_addresses_test.go
+++ b/internal/db/email_addresses_test.go
@@ -49,7 +49,7 @@ func emailAddressesGetByEmail(t *testing.T, db *emailAddresses) {
ctx := context.Background()
const testEmail = "alice@example.com"
- _, err := db.GetByEmail(ctx, testEmail)
+ _, err := db.GetByEmail(ctx, testEmail, false)
wantErr := ErrEmailNotExist{
args: errutil.Args{
"email": testEmail,
@@ -58,9 +58,20 @@ func emailAddressesGetByEmail(t *testing.T, db *emailAddresses) {
assert.Equal(t, wantErr, err)
// TODO: Use EmailAddresses.Create to replace SQL hack when the method is available.
- err = db.Exec(`INSERT INTO email_address (uid, email) VALUES (1, ?)`, testEmail).Error
+ err = db.Exec(`INSERT INTO email_address (uid, email, is_activated) VALUES (1, ?, FALSE)`, testEmail).Error
require.NoError(t, err)
- got, err := db.GetByEmail(ctx, testEmail)
+ got, err := db.GetByEmail(ctx, testEmail, false)
+ require.NoError(t, err)
+ assert.Equal(t, testEmail, got.Email)
+
+ // Should not return if we only want activated emails
+ _, err = db.GetByEmail(ctx, testEmail, true)
+ assert.Equal(t, wantErr, err)
+
+ // TODO: Use EmailAddresses.MarkActivated to replace SQL hack when the method is available.
+ err = db.Exec(`UPDATE email_address SET is_activated = TRUE WHERE email = ?`, testEmail).Error
+ require.NoError(t, err)
+ got, err = db.GetByEmail(ctx, testEmail, true)
require.NoError(t, err)
assert.Equal(t, testEmail, got.Email)
}