Skip to content

Commit

Permalink
Merge pull request #238 from RecyThing/feat/unit_test-article
Browse files Browse the repository at this point in the history
feat: add unit test dashboard
  • Loading branch information
JuanAzhar authored Dec 16, 2023
2 parents 80ef0e1 + bb0857e commit 8172fda
Show file tree
Hide file tree
Showing 3 changed files with 1,094 additions and 69 deletions.
44 changes: 44 additions & 0 deletions features/dashboard/service/cover.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
mode: set
recything/features/dashboard/service/service.go:13.110,17.2 1 1
recything/features/dashboard/service/service.go:20.295,22.16 2 1
recything/features/dashboard/service/service.go:22.16,24.3 1 1
recything/features/dashboard/service/service.go:26.2,27.16 2 1
recything/features/dashboard/service/service.go:27.16,29.3 1 1
recything/features/dashboard/service/service.go:31.2,32.16 2 1
recything/features/dashboard/service/service.go:32.16,34.3 1 0
recything/features/dashboard/service/service.go:36.2,37.16 2 1
recything/features/dashboard/service/service.go:37.16,39.3 1 1
recything/features/dashboard/service/service.go:41.2,42.16 2 1
recything/features/dashboard/service/service.go:42.16,44.3 1 1
recything/features/dashboard/service/service.go:46.2,47.16 2 1
recything/features/dashboard/service/service.go:47.16,49.3 1 1
recything/features/dashboard/service/service.go:51.2,52.16 2 1
recything/features/dashboard/service/service.go:52.16,54.3 1 1
recything/features/dashboard/service/service.go:56.2,57.16 2 1
recything/features/dashboard/service/service.go:57.16,59.3 1 0
recything/features/dashboard/service/service.go:61.2,62.16 2 1
recything/features/dashboard/service/service.go:62.16,64.3 1 1
recything/features/dashboard/service/service.go:66.2,67.16 2 1
recything/features/dashboard/service/service.go:67.16,69.3 1 0
recything/features/dashboard/service/service.go:71.2,81.119 10 1
recything/features/dashboard/service/service.go:85.294,87.16 2 1
recything/features/dashboard/service/service.go:87.16,89.3 1 1
recything/features/dashboard/service/service.go:91.2,92.16 2 1
recything/features/dashboard/service/service.go:92.16,94.3 1 1
recything/features/dashboard/service/service.go:96.2,97.16 2 1
recything/features/dashboard/service/service.go:97.16,99.3 1 0
recything/features/dashboard/service/service.go:101.2,102.16 2 1
recything/features/dashboard/service/service.go:102.16,104.3 1 1
recything/features/dashboard/service/service.go:106.2,107.16 2 1
recything/features/dashboard/service/service.go:107.16,109.3 1 1
recything/features/dashboard/service/service.go:111.2,112.16 2 1
recything/features/dashboard/service/service.go:112.16,114.3 1 1
recything/features/dashboard/service/service.go:116.2,117.16 2 1
recything/features/dashboard/service/service.go:117.16,119.3 1 1
recything/features/dashboard/service/service.go:121.2,122.16 2 1
recything/features/dashboard/service/service.go:122.16,124.3 1 0
recything/features/dashboard/service/service.go:126.2,127.16 2 1
recything/features/dashboard/service/service.go:127.16,129.3 1 0
recything/features/dashboard/service/service.go:131.2,132.16 2 1
recything/features/dashboard/service/service.go:132.16,134.3 1 0
recything/features/dashboard/service/service.go:137.2,149.120 11 1
69 changes: 0 additions & 69 deletions features/dashboard/service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,72 +149,3 @@ func (ds *dashboardService) DashboardYears() (dashboard.GetCountUser, dashboard.
return userResult, voucherResult, reportResult, trashResult, scalaResult, userRanking, monthlyStats, incomeResult, nil
}

// CountMonthlyTrashAndScalaTypesYear implements entity.DashboardServiceInterface.
// func (ds *dashboardService) CountMonthlyTrashAndScalaTypesYear() ([]dashboard.MonthlyStats, error) {
// trashAndScalaTypes, err := ds.dashboardRepository.CountWeeklyTrashAndScalaTypes()
// if err != nil {
// return nil, err
// }

// // Menghitung jumlah bulan dalam setahun
// startOfYear := time.Now().AddDate(-1, 0, 0) // Mengubah ke -1 untuk mendapatkan awal tahun sekarang
// monthsInYear := 12
// monthlyStats := make([]dashboard.MonthlyStats, monthsInYear)

// for i := 0; i < monthsInYear; i++ {
// // Menghitung awal dan akhir bulan
// monthStartDate := startOfYear.AddDate(0, i, 0)
// monthEndDate := monthStartDate.AddDate(0, 1, -1)

// // Filter data yang berada dalam rentang waktu bulan ini
// filteredData := dashboard.FilterDataByDate(trashAndScalaTypes, monthStartDate, monthEndDate)

// // Hitung jumlah data trash_type dan scala_type
// trashCount, scalaCount := dashboard.CountTrashAndScalaTypes(filteredData)

// // Set nilai MonthlyStats
// monthlyStats[i].Month = i + 1
// monthlyStats[i].Trash = trashCount
// monthlyStats[i].Scala = scalaCount
// }

// return monthlyStats, nil
// }

// // CountWeeklyTrashAndScalaTypes implements entity.DashboardServiceInterface.
// func (ds *dashboardService) CountWeeklyTrashAndScalaTypes() ([]dashboard.WeeklyStats, error) {
// trashAndScalaTypes, err := ds.dashboardRepository.CountWeeklyTrashAndScalaTypes()
// if err != nil {
// return nil, err
// }

// // Menghitung jumlah minggu dalam bulan ini
// startOfMonth := time.Now().AddDate(0, 0, -time.Now().Day()+1)
// year, month, _ := startOfMonth.Date()
// weeksInMonth := helper.GetWeeksInMonth(year, month)
// weeklyStats := make([]dashboard.WeeklyStats, weeksInMonth)

// for i := 0; i < weeksInMonth; i++ {
// // Menghitung awal dan akhir minggu
// weekStartDate := startOfMonth.AddDate(0, 0, 7*i)
// weekEndDate := startOfMonth.AddDate(0, 0, 7*(i+1)-1)

// if i == weeksInMonth-1 {
// lastDayOfMonth := time.Date(year, month+1, 0, 0, 0, 0, 0, time.UTC).Day()
// weekEndDate = startOfMonth.AddDate(0, 0, lastDayOfMonth-1)
// }
// log.Printf("Week %d: StartDate: %s, EndDate: %s\n", i+1, weekStartDate, weekEndDate)
// // Filter data yang berada dalam rentang waktu minggu ini
// filteredData := dashboard.FilterDataByDate(trashAndScalaTypes, weekStartDate, weekEndDate)

// // Hitung jumlah data trash_type dan scala_type
// trashCount, scalaCount := dashboard.CountTrashAndScalaTypes(filteredData)

// // Set nilai WeeklyStats
// weeklyStats[i].Week = i + 1
// weeklyStats[i].Trash = trashCount
// weeklyStats[i].Scala = scalaCount
// }

// return weeklyStats, nil
// }
Loading

0 comments on commit 8172fda

Please sign in to comment.