Files
2026-08-19 02:15:57 +07:00

38 lines
1023 B
Go

package app
import (
"testing"
"time"
"evening_detective_server/internal/repos"
)
func TestMapUser(t *testing.T) {
t.Run("nil — обезличенный автор, возвращает nil", func(t *testing.T) {
if got := mapUser(nil); got != nil {
t.Errorf("mapUser(nil) = %v, want nil", got)
}
})
t.Run("обычный пользователь маппится полностью", func(t *testing.T) {
u := &repos.User{
ID: 42,
Username: "detective",
Email: "d@example.com",
Roles: []string{"user"},
IsActive: true,
CreatedAt: time.Date(2026, 8, 18, 12, 0, 0, 0, time.UTC),
}
got := mapUser(u)
if got == nil {
t.Fatal("mapUser вернул nil для не-nil пользователя")
}
if got.Id != 42 || got.Username != "detective" || got.Email != "d@example.com" {
t.Errorf("неожиданный маппинг: %+v", got)
}
if len(got.Roles) != 1 || got.Roles[0] != "user" {
t.Errorf("roles = %v, want [user]", got.Roles)
}
})
}