| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455 |
- // IdentityRepo 仓储集成测试(t_identity 登录身份,(type,identifier,appid) 唯一键·v1.2)。
- //
- // 依赖 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_GetByTypeIdentifierAppID (type,identifier,appid) 唯一键命中 / 未命中(v1.2)。
- // 非微信类型 appid 恒 "",微信类型 appid 必填。
- func TestIdentityRepo_GetByTypeIdentifierAppID(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.GetByTypeIdentifierAppID(ctx, identitymodel.IdentityTypePhone, fx.phone, "")
- if err != nil {
- t.Fatalf("GetByTypeIdentifierAppID 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.GetByTypeIdentifierAppID(ctx, identitymodel.IdentityTypeEmail, fx.email, "")
- if err != nil {
- t.Fatalf("GetByTypeIdentifierAppID 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.GetByTypeIdentifierAppID(ctx, identitymodel.IdentityTypeWechat, "unknown_openid", "appid-x")
- if !stderrors.Is(err, apperrors.ErrNotFound) {
- t.Fatalf("期望 ErrNotFound,实际 %v", err)
- }
- })
- }
|