add dashboard test
This commit is contained in:
@@ -2,6 +2,7 @@ package dashboard
|
||||
|
||||
import (
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
type expectedRangeDate struct {
|
||||
@@ -42,3 +43,99 @@ func TestDashboardDateRange(t *testing.T) {
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func TestPerbandingStatusAntrianResponse(t *testing.T) {
|
||||
dataset := ListPerbandinganStatusAntrean{
|
||||
{IdStatus: 1, Jumlah: 100},
|
||||
{IdStatus: 2, Jumlah: 50},
|
||||
{IdStatus: 3, Jumlah: 3},
|
||||
{IdStatus: 4, Jumlah: 5},
|
||||
}
|
||||
|
||||
expected := []PerbandinganStatusAntreanResponse{
|
||||
{IdStatus: 1, Status: "Belum", Jumlah: 100},
|
||||
{IdStatus: 2, Status: "Selesai", Jumlah: 50},
|
||||
{IdStatus: 3, Status: "Tunda", Jumlah: 3},
|
||||
{IdStatus: 4, Status: "Batal", Jumlah: 5},
|
||||
}
|
||||
|
||||
t.Run("test parsing query status antrian to response", func(t *testing.T) {
|
||||
parsedToResponse := dataset.MapToResponse()
|
||||
|
||||
for idx := range parsedToResponse {
|
||||
if parsedToResponse[idx].IdStatus != expected[idx].IdStatus ||
|
||||
parsedToResponse[idx].Status != expected[idx].Status ||
|
||||
parsedToResponse[idx].Jumlah != expected[idx].Jumlah {
|
||||
t.Fatalf("expected id %v got %v, expected status %v got %v, expected jumlah %v got %v",
|
||||
expected[idx].IdStatus, parsedToResponse[idx].IdStatus,
|
||||
expected[idx].Status, parsedToResponse[idx].Status,
|
||||
expected[idx].Jumlah, parsedToResponse[idx].Jumlah,
|
||||
)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func TestAntrianPerHariResponse(t *testing.T) {
|
||||
year := 2025
|
||||
month := 8
|
||||
expectedLength := 31
|
||||
|
||||
dataset := ListAntrianPerHari{
|
||||
{TanggalDaftar: time.Date(year, time.Month(month), 2, 0, 0, 0, 0, time.Local), Belum: 2, Selesai: 5, Tunda: 0, Batal: 1},
|
||||
{TanggalDaftar: time.Date(year, time.Month(month), 5, 0, 0, 0, 0, time.Local), Belum: 3, Selesai: 6, Tunda: 1, Batal: 0},
|
||||
{TanggalDaftar: time.Date(year, time.Month(month), 10, 0, 0, 0, 0, time.Local), Belum: 10, Selesai: 9, Tunda: 0, Batal: 0},
|
||||
{TanggalDaftar: time.Date(year, time.Month(month), 11, 0, 0, 0, 0, time.Local), Belum: 12, Selesai: 6, Tunda: 0, Batal: 2},
|
||||
{TanggalDaftar: time.Date(year, time.Month(month), 21, 0, 0, 0, 0, time.Local), Belum: 2, Selesai: 1, Tunda: 10, Batal: 0},
|
||||
}
|
||||
|
||||
response := dataset.ParseToResponse(year, time.Month(month))
|
||||
|
||||
mapTestIdx := map[int]int{
|
||||
0: 1,
|
||||
1: 4,
|
||||
2: 9,
|
||||
3: 10,
|
||||
4: 20,
|
||||
}
|
||||
|
||||
t.Run("test parsing query antrian harian to response", func(t *testing.T) {
|
||||
if len(response) != expectedLength {
|
||||
t.Fatalf("unexpected date length. expected %v got %v", expectedLength, len(response))
|
||||
}
|
||||
|
||||
for idDataset := range mapTestIdx {
|
||||
if response[mapTestIdx[idDataset]].Belum != dataset[idDataset].Belum ||
|
||||
response[mapTestIdx[idDataset]].Selesai != dataset[idDataset].Selesai ||
|
||||
response[mapTestIdx[idDataset]].Tunda != dataset[idDataset].Tunda ||
|
||||
response[mapTestIdx[idDataset]].Batal != dataset[idDataset].Batal {
|
||||
t.Fatalf("parsing error. dataset %v response %v. date dataset: %v, date response : %v",
|
||||
dataset[idDataset].Belum, response[mapTestIdx[idDataset]].Belum,
|
||||
dataset[idDataset].TanggalDaftar, response[mapTestIdx[idDataset]].TanggalDaftar)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func daysInMonth(year int, month time.Month) int {
|
||||
t := time.Date(year, month+1, 0, 0, 0, 0, 0, time.UTC)
|
||||
return t.Day()
|
||||
}
|
||||
|
||||
func TestAntrianResponseFeedNoDataDate(t *testing.T) {
|
||||
year := 2025
|
||||
var nullDataset ListAntrianPerHari
|
||||
|
||||
t.Run("test feed null data should feed exactly days in specific month", func(t *testing.T) {
|
||||
for idxMonth := range 11 {
|
||||
month := time.Month(idxMonth + 1)
|
||||
response := nullDataset.ParseToResponse(year, month)
|
||||
daysAmount := daysInMonth(year, month)
|
||||
|
||||
if len(response) != daysAmount {
|
||||
t.Fatalf("feed data error. year %v month %v, feed %v days, expected %v days", year, month, len(response), daysAmount)
|
||||
}
|
||||
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user