| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354 |
- // IdentityRepo 仓储集成测试(t_identity 登录身份,(type,identifier) 唯一键)。
- //
- // 依赖 test_helpers_test.go 的 setup/insertFixture;未设置 UNIFIED_TEST_DSN 时跳过。
- package repository
- import (
- "context"
- stderrors "errors"
- "testing"
- apperrors "yuansiwei/unified-backend/internal/infra/errors"
- identitymodel "yuansiwei/unified-backend/internal/identity/model"
- )
- // TestIdentityRepo_GetByTypeIdentifier (type,identifier) 唯一键命中 / 未命中。
- func TestIdentityRepo_GetByTypeIdentifier(t *testing.T) {
- gdb := setup(t)
- ctx := context.Background()
- fx := insertFixture(t, gdb, ctx)
- repo := NewIdentityRepo(gdb)
- t.Run("命中_phone", func(t *testing.T) {
- it, err := repo.GetByTypeIdentifier(ctx, identitymodel.IdentityTypePhone, fx.phone)
- if err != nil {
- t.Fatalf("GetByTypeIdentifier phone: %v", err)
- }
- if it.CanonicalUserID != fx.canonical {
- t.Errorf("返回 canonical_user_id = %q,期望 %q", it.CanonicalUserID, fx.canonical)
- }
- if !it.Verified {
- t.Errorf("phone 身份应 verified=true")
- }
- })
- t.Run("命中_email", func(t *testing.T) {
- it, err := repo.GetByTypeIdentifier(ctx, identitymodel.IdentityTypeEmail, fx.email)
- if err != nil {
- t.Fatalf("GetByTypeIdentifier email: %v", err)
- }
- if it.CanonicalUserID != fx.canonical {
- t.Errorf("返回 canonical_user_id = %q,期望 %q", it.CanonicalUserID, fx.canonical)
- }
- if it.Verified {
- t.Errorf("email 身份应 verified=false")
- }
- })
- t.Run("未命中_返回ErrNotFound", func(t *testing.T) {
- _, err := repo.GetByTypeIdentifier(ctx, identitymodel.IdentityTypeWechat, "unknown_openid")
- if !stderrors.Is(err, apperrors.ErrNotFound) {
- t.Fatalf("期望 ErrNotFound,实际 %v", err)
- }
- })
- }
|