Files
pulse-api/internal/model/user_test.go
Cosmo 8d9fe818f4
All checks were successful
CI / ci (push) Successful in 35s
Add unit tests for middleware, models, services, handlers, and repository helpers
2026-03-01 02:32:59 +00:00

47 lines
1.2 KiB
Go

package model
import (
"database/sql"
"testing"
)
func TestUser_ProcessForJSON(t *testing.T) {
t.Run("with telegram chat id", func(t *testing.T) {
u := &User{
TelegramChatID: sql.NullInt64{Int64: 123456, Valid: true},
MorningReminderTime: sql.NullString{String: "09:00:00", Valid: true},
EveningReminderTime: sql.NullString{String: "21:30:00", Valid: true},
}
u.ProcessForJSON()
if u.TelegramChatIDValue == nil || *u.TelegramChatIDValue != 123456 {
t.Error("telegram_chat_id not set correctly")
}
if u.MorningTime != "09:00" {
t.Errorf("expected 09:00, got %s", u.MorningTime)
}
if u.EveningTime != "21:30" {
t.Errorf("expected 21:30, got %s", u.EveningTime)
}
})
t.Run("without telegram chat id", func(t *testing.T) {
u := &User{
TelegramChatID: sql.NullInt64{Valid: false},
MorningReminderTime: sql.NullString{Valid: false},
EveningReminderTime: sql.NullString{Valid: false},
}
u.ProcessForJSON()
if u.TelegramChatIDValue != nil {
t.Error("telegram_chat_id should be nil")
}
if u.MorningTime != "09:00" {
t.Errorf("expected default 09:00, got %s", u.MorningTime)
}
if u.EveningTime != "21:00" {
t.Errorf("expected default 21:00, got %s", u.EveningTime)
}
})
}