test: expand handler tests to 53.4% coverage
Some checks failed
CI / lint-test (push) Failing after 1s
Some checks failed
CI / lint-test (push) Failing after 1s
This commit is contained in:
91
internal/model/email_test.go
Normal file
91
internal/model/email_test.go
Normal file
@@ -0,0 +1,91 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func TestEmailToken_Fields(t *testing.T) {
|
||||
now := time.Now()
|
||||
token := &EmailToken{
|
||||
ID: 1,
|
||||
UserID: 42,
|
||||
Token: "abc123",
|
||||
Type: "verification",
|
||||
ExpiresAt: now.Add(24 * time.Hour),
|
||||
CreatedAt: now,
|
||||
}
|
||||
|
||||
if token.ID != 1 {
|
||||
t.Errorf("expected ID 1, got %d", token.ID)
|
||||
}
|
||||
if token.UserID != 42 {
|
||||
t.Errorf("expected UserID 42, got %d", token.UserID)
|
||||
}
|
||||
if token.Token != "abc123" {
|
||||
t.Errorf("expected token abc123, got %s", token.Token)
|
||||
}
|
||||
if token.Type != "verification" {
|
||||
t.Errorf("expected type verification, got %s", token.Type)
|
||||
}
|
||||
if token.UsedAt != nil {
|
||||
t.Error("expected UsedAt nil initially")
|
||||
}
|
||||
}
|
||||
|
||||
func TestEmailToken_UsedAt(t *testing.T) {
|
||||
now := time.Now()
|
||||
token := &EmailToken{
|
||||
UsedAt: &now,
|
||||
}
|
||||
if token.UsedAt == nil {
|
||||
t.Error("expected non-nil UsedAt")
|
||||
}
|
||||
if !token.UsedAt.Equal(now) {
|
||||
t.Errorf("expected %v, got %v", now, token.UsedAt)
|
||||
}
|
||||
}
|
||||
|
||||
func TestEmailToken_Types(t *testing.T) {
|
||||
types := []string{"verification", "reset"}
|
||||
for _, tp := range types {
|
||||
token := &EmailToken{Type: tp}
|
||||
if token.Type != tp {
|
||||
t.Errorf("expected type %s, got %s", tp, token.Type)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestForgotPasswordRequest(t *testing.T) {
|
||||
req := ForgotPasswordRequest{Email: "test@example.com"}
|
||||
if req.Email != "test@example.com" {
|
||||
t.Errorf("unexpected email: %s", req.Email)
|
||||
}
|
||||
}
|
||||
|
||||
func TestResetPasswordRequest(t *testing.T) {
|
||||
req := ResetPasswordRequest{
|
||||
Token: "reset-token",
|
||||
NewPassword: "newpassword123",
|
||||
}
|
||||
if req.Token != "reset-token" {
|
||||
t.Errorf("unexpected token: %s", req.Token)
|
||||
}
|
||||
if req.NewPassword != "newpassword123" {
|
||||
t.Errorf("unexpected password: %s", req.NewPassword)
|
||||
}
|
||||
}
|
||||
|
||||
func TestVerifyEmailRequest(t *testing.T) {
|
||||
req := VerifyEmailRequest{Token: "verify-token"}
|
||||
if req.Token != "verify-token" {
|
||||
t.Errorf("unexpected token: %s", req.Token)
|
||||
}
|
||||
}
|
||||
|
||||
func TestResendVerificationRequest(t *testing.T) {
|
||||
req := ResendVerificationRequest{Email: "user@example.com"}
|
||||
if req.Email != "user@example.com" {
|
||||
t.Errorf("unexpected email: %s", req.Email)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user