product_calendar_break_time_period_test.go 1.2 KB
package domain

import (
	"fmt"
	"github.com/stretchr/testify/assert"
	"testing"
	"time"
)

func TestCheckOverDay(t *testing.T) {
	var input = []struct {
		name    string
		begin   string
		end     string
		overDay bool
	}{
		{
			"normal",
			"11:00",
			"12:00",
			false,
		},
		{
			"over day",
			"23:45",
			"00:45",
			true,
		},
	}
	for _, v := range input {
		p := NewProductCalendarBreakTimePeriod(v.begin, v.end, 0)
		t.Run(v.name, func(t *testing.T) {
			ok, err := p.CheckOverDay()
			assert.Equal(t, v.overDay, ok)
			assert.Nil(t, err)
		})
	}
}

func TestGetCheckTime(t *testing.T) {
	var input = []struct {
		name    string
		begin   string
		end     string
		overDay bool
		in      time.Time
	}{
		{
			"normal",
			"11:00",
			"12:00",
			false,
			time.Date(2022, 5, 5, 9, 0, 0, 0, time.Local),
		},
		{
			"over day",
			"23:45",
			"00:45",
			true,
			time.Date(2022, 5, 5, 23, 0, 0, 0, time.Local),
		},
	}
	for _, v := range input {
		p := NewProductCalendarBreakTimePeriod(v.begin, v.end, 0)
		t.Run(v.name, func(t *testing.T) {
			begin := p.GetCheckBeginTime(time.Now())
			end := p.GetCheckEndTime(time.Now())
			overDay := begin.Day() != end.Day()
			assert.Equal(t, v.overDay, overDay, fmt.Sprintf("begin:%v end:%v", begin, end))
		})
	}
}