Files
goimgApi/accounts/models/models_test.go
Beyhan Oğur e6f3268c28 first commit
2026-04-26 21:48:15 +03:00

66 lines
1.9 KiB
Go
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package models
import (
"reflect"
"testing"
)
// ─── User.IsEmailVerified ────────────────────────────────────────────────────
func TestIsEmailVerified_NilPointer(t *testing.T) {
u := &User{}
if u.IsEmailVerified() {
t.Fatal("expected false when EmailVerified is nil")
}
}
func TestIsEmailVerified_False(t *testing.T) {
v := false
u := &User{EmailVerified: &v}
if u.IsEmailVerified() {
t.Fatal("expected false when EmailVerified is &false")
}
}
func TestIsEmailVerified_True(t *testing.T) {
v := true
u := &User{EmailVerified: &v}
if !u.IsEmailVerified() {
t.Fatal("expected true when EmailVerified is &true")
}
}
// ─── User struct tag doğrulamaları ──────────────────────────────────────────
func TestUser_PasswordHiddenFromJSON(t *testing.T) {
f, ok := reflect.TypeOf(User{}).FieldByName("Password")
if !ok {
t.Fatal("User has no Password field")
}
if tag := f.Tag.Get("json"); tag != "-" {
t.Fatalf("expected Password json tag to be \"-\", got %q", tag)
}
}
func TestUser_EmailUniqueIndexTagSet(t *testing.T) {
f, ok := reflect.TypeOf(User{}).FieldByName("Email")
if !ok {
t.Fatal("User has no Email field")
}
if gormTag := f.Tag.Get("gorm"); gormTag == "" {
t.Fatal("Email field has no gorm tag")
}
}
// ─── RefreshToken alanları ───────────────────────────────────────────────────
func TestRefreshToken_HasRequiredFields(t *testing.T) {
typ := reflect.TypeOf(RefreshToken{})
required := []string{"UserID", "TokenID", "TokenHash", "TokenFingerprint", "ExpiresAt", "Revoked"}
for _, name := range required {
if _, ok := typ.FieldByName(name); !ok {
t.Errorf("RefreshToken missing required field: %s", name)
}
}
}