Add unit tests for middleware, models, services, handlers, and repository helpers
All checks were successful
CI / ci (push) Successful in 35s
All checks were successful
CI / ci (push) Successful in 35s
This commit is contained in:
46
internal/model/user_test.go
Normal file
46
internal/model/user_test.go
Normal file
@@ -0,0 +1,46 @@
|
||||
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)
|
||||
}
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user