jokes-bapak2/api/app/v1/utils/date_test.go

41 lines
862 B
Go
Raw Normal View History

2021-07-09 12:13:19 +00:00
package utils_test
import (
"testing"
"time"
2021-07-14 18:17:01 +00:00
"jokes-bapak2-api/app/v1/utils"
2021-07-09 12:13:19 +00:00
)
func TestIsToday(t *testing.T) {
t.Run("should be able to tell if it's today", func(t *testing.T) {
today, err := utils.IsToday(time.Now().UTC().Format(time.RFC3339))
if err != nil {
t.Error(err.Error())
}
if today == false {
t.Error("today should be true:", today)
}
})
t.Run("should be able to tell if it's not today", func(t *testing.T) {
today, err := utils.IsToday("2021-01-01T11:48:24Z")
if err != nil {
t.Error(err.Error())
}
if today == true {
t.Error("today should be false:", today)
}
})
2021-07-14 18:24:47 +00:00
t.Run("should return false with no error if no date is supplied", func(t *testing.T) {
today, err := utils.IsToday("")
if err != nil {
t.Error(err.Error())
}
if today != false {
t.Error("it should be false:", today)
}
})
2021-07-09 12:13:19 +00:00
}