30 lines
1.3 KiB
Go
30 lines
1.3 KiB
Go
package growth
|
|
|
|
import (
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
func TestAggregateDailyUsesTehranDayAndSessionGrain(t *testing.T) {
|
|
sessions := []Session{
|
|
{CreatedAt: time.Date(2026, 1, 1, 20, 29, 0, 0, time.UTC), Status: "Paid", AmountRial: 100},
|
|
{CreatedAt: time.Date(2026, 1, 1, 20, 31, 0, 0, time.UTC), Status: "Verified", AmountRial: 200},
|
|
{CreatedAt: time.Date(2026, 1, 1, 21, 0, 0, 0, time.UTC), Status: "Failed", AmountRial: 900},
|
|
}
|
|
points := AggregateDaily(sessions, nil)
|
|
if len(points) != 2 || dayKey(points[0].Date) != "2026-01-01" || points[0].PaidAmountRial != 100 {
|
|
t.Fatalf("unexpected first day: %+v", points)
|
|
}
|
|
if dayKey(points[1].Date) != "2026-01-02" || points[1].SessionCount != 2 || points[1].PaidSessionCount != 1 || points[1].PaidAmountRial != 200 {
|
|
t.Fatalf("unexpected second day: %+v", points[1])
|
|
}
|
|
}
|
|
|
|
func TestAggregateDailyAnnotatesCatalogEvents(t *testing.T) {
|
|
events := []Event{{ID: "b", StartDate: date("2026-05-02"), EndDate: date("2026-05-02")}, {ID: "a", StartDate: date("2026-05-02"), EndDate: date("2026-05-02")}}
|
|
points := AggregateDaily([]Session{{CreatedAt: time.Date(2026, 5, 2, 8, 0, 0, 0, tehranLocation()), Status: "Paid", AmountRial: 10}}, events)
|
|
if len(points) != 1 || len(points[0].EventIDs) != 2 || points[0].EventIDs[0] != "a" || points[0].EventIDs[1] != "b" {
|
|
t.Fatalf("unexpected event annotation: %+v", points)
|
|
}
|
|
}
|