45 lines
1.2 KiB
Go
45 lines
1.2 KiB
Go
package dashboard
|
|
|
|
import (
|
|
"testing"
|
|
)
|
|
|
|
type expectedRangeDate struct {
|
|
startDate string
|
|
endDate string
|
|
}
|
|
|
|
func TestDashboardDateRange(t *testing.T) {
|
|
dataSet := []struct {
|
|
testCase string
|
|
data PeriodeDashboardRequest
|
|
expected expectedRangeDate
|
|
}{
|
|
{
|
|
testCase: "Normal case",
|
|
data: PeriodeDashboardRequest{Year: 2025, Month: 1},
|
|
expected: expectedRangeDate{startDate: "2025-1-1", endDate: "2025-2-1"},
|
|
},
|
|
{
|
|
testCase: "Cross year case",
|
|
data: PeriodeDashboardRequest{Year: 2025, Month: 12},
|
|
expected: expectedRangeDate{startDate: "2025-12-1", endDate: "2026-1-1"},
|
|
},
|
|
{
|
|
testCase: "Month > 12",
|
|
data: PeriodeDashboardRequest{Year: 2025, Month: 20},
|
|
expected: expectedRangeDate{startDate: "2025-12-1", endDate: "2026-1-1"},
|
|
},
|
|
}
|
|
|
|
t.Run("test parsing dashboard range date", func(t *testing.T) {
|
|
for _, testcase := range dataSet {
|
|
resultStartDate, resultEndDate := GenerateStartEndDate(testcase.data)
|
|
|
|
if resultStartDate != testcase.expected.startDate || resultEndDate != testcase.expected.endDate {
|
|
t.Fatalf("expected start date %v got %v \n expected end date %v got %v", testcase.expected.startDate, resultStartDate, testcase.expected.endDate, resultEndDate)
|
|
}
|
|
}
|
|
})
|
|
}
|