MCPcopy Create free account
hub / github.com/gogs/gogs / usersMarkEmailPrimary

Function usersMarkEmailPrimary

internal/database/users_test.go:1283–1307  ·  view source on GitHub ↗
(t *testing.T, ctx context.Context, s *UsersStore)

Source from the content-addressed store, hash-verified

1281}
1282
1283func usersMarkEmailPrimary(t *testing.T, ctx context.Context, s *UsersStore) {
1284 alice, err := s.Create(ctx, "alice", "alice@example.com", CreateUserOptions{})
1285 require.NoError(t, err)
1286 err = s.AddEmail(ctx, alice.ID, "alice2@example.com", false)
1287 require.NoError(t, err)
1288
1289 // Should fail because email not verified
1290 gotError := s.MarkEmailPrimary(ctx, alice.ID, "alice2@example.com")
1291 wantError := ErrEmailNotVerified{args: errutil.Args{"email": "alice2@example.com"}}
1292 assert.Equal(t, wantError, gotError)
1293
1294 // Mark email as verified and should succeed
1295 err = s.MarkEmailActivated(ctx, alice.ID, "alice2@example.com")
1296 require.NoError(t, err)
1297 err = s.MarkEmailPrimary(ctx, alice.ID, "alice2@example.com")
1298 require.NoError(t, err)
1299 gotAlice, err := s.GetByID(ctx, alice.ID)
1300 require.NoError(t, err)
1301 assert.Equal(t, "alice2@example.com", gotAlice.Email)
1302
1303 // Former primary email should be preserved
1304 gotEmail, err := s.GetEmail(ctx, alice.ID, "alice@example.com", false)
1305 require.NoError(t, err)
1306 assert.False(t, gotEmail.IsActivated)
1307}
1308
1309func usersDeleteEmail(t *testing.T, ctx context.Context, s *UsersStore) {
1310 alice, err := s.Create(ctx, "alice", "alice@example.com", CreateUserOptions{})

Callers

nothing calls this directly

Calls 6

AddEmailMethod · 0.80
MarkEmailPrimaryMethod · 0.80
MarkEmailActivatedMethod · 0.80
GetEmailMethod · 0.80
GetByIDMethod · 0.65
CreateMethod · 0.45

Tested by

no test coverage detected