diff options
Diffstat (limited to 'internal/reports/unified_test.go')
-rw-r--r-- | internal/reports/unified_test.go | 148 |
1 files changed, 73 insertions, 75 deletions
diff --git a/internal/reports/unified_test.go b/internal/reports/unified_test.go index 64d0b3f..cf18350 100644 --- a/internal/reports/unified_test.go +++ b/internal/reports/unified_test.go @@ -5,10 +5,9 @@ import ( "testing" "time" - "punchcard/internal/queries" + "git.tjp.lol/punchcard/internal/queries" ) - func TestGenerateUnifiedReportData(t *testing.T) { tests := []struct { name string @@ -29,30 +28,30 @@ func TestGenerateUnifiedReportData(t *testing.T) { name: "client entries with UTC timezone", entries: []queries.GetInvoiceDataByClientRow{ { - TimeEntryID: 1, - StartTime: mustParseTime("2025-07-10T14:55:00Z"), - EndTime: sql.NullTime{Time: mustParseTime("2025-07-10T18:05:00Z"), Valid: true}, - Description: sql.NullString{String: "GL closing", Valid: true}, - ClientID: 1, - ClientName: "Test Client", - ProjectID: sql.NullInt64{Int64: 1, Valid: true}, - ProjectName: sql.NullString{String: "Test Project", Valid: true}, - DurationSeconds: 11400, // 3:10 + TimeEntryID: 1, + StartTime: mustParseTime("2025-07-10T14:55:00Z"), + EndTime: sql.NullTime{Time: mustParseTime("2025-07-10T18:05:00Z"), Valid: true}, + Description: sql.NullString{String: "GL closing", Valid: true}, + ClientID: 1, + ClientName: "Test Client", + ProjectID: sql.NullInt64{Int64: 1, Valid: true}, + ProjectName: sql.NullString{String: "Test Project", Valid: true}, + DurationSeconds: 11400, // 3:10 EntryBillableRate: sql.NullInt64{Int64: 150, Valid: true}, ClientBillableRate: sql.NullInt64{Int64: 150, Valid: true}, ProjectBillableRate: sql.NullInt64{Int64: 150, Valid: true}, RateSource: "entry", }, { - TimeEntryID: 2, - StartTime: mustParseTime("2025-07-10T18:42:00Z"), - EndTime: sql.NullTime{Time: mustParseTime("2025-07-10T20:04:00Z"), Valid: true}, - Description: sql.NullString{String: "GL closing", Valid: true}, - ClientID: 1, - ClientName: "Test Client", - ProjectID: sql.NullInt64{Int64: 1, Valid: true}, - ProjectName: sql.NullString{String: "Test Project", Valid: true}, - DurationSeconds: 4920, // 1:22 + TimeEntryID: 2, + StartTime: mustParseTime("2025-07-10T18:42:00Z"), + EndTime: sql.NullTime{Time: mustParseTime("2025-07-10T20:04:00Z"), Valid: true}, + Description: sql.NullString{String: "GL closing", Valid: true}, + ClientID: 1, + ClientName: "Test Client", + ProjectID: sql.NullInt64{Int64: 1, Valid: true}, + ProjectName: sql.NullString{String: "Test Project", Valid: true}, + DurationSeconds: 4920, // 1:22 EntryBillableRate: sql.NullInt64{Int64: 150, Valid: true}, ClientBillableRate: sql.NullInt64{Int64: 150, Valid: true}, ProjectBillableRate: sql.NullInt64{Int64: 150, Valid: true}, @@ -66,13 +65,13 @@ func TestGenerateUnifiedReportData(t *testing.T) { Label: "Software Development", Email: "travis@example.com", }, - invoiceNumber: 123, + invoiceNumber: 123, dateRange: DateRange{ Start: mustParseTime("2025-07-01T00:00:00Z"), End: mustParseTime("2025-07-31T23:59:59Z"), }, timezone: time.UTC, - wantEntries: 1, // Both entries have same rate so grouped together + wantEntries: 1, // Both entries have same rate so grouped together wantHours: 4.5333, // 16320 seconds / 3600 wantTotalAmount: 6.80, // 4.5333 * 1.50 }, @@ -80,14 +79,14 @@ func TestGenerateUnifiedReportData(t *testing.T) { name: "project entries with local timezone", entries: []queries.GetInvoiceDataByProjectRow{ { - TimeEntryID: 3, - StartTime: mustParseTime("2025-07-11T13:55:00Z"), - EndTime: sql.NullTime{Time: mustParseTime("2025-07-11T18:35:00Z"), Valid: true}, - Description: sql.NullString{String: "Development work", Valid: true}, - ClientID: 1, - ClientName: "Test Client", - ProjectID: 1, - ProjectName: "Test Project", + TimeEntryID: 3, + StartTime: mustParseTime("2025-07-11T13:55:00Z"), + EndTime: sql.NullTime{Time: mustParseTime("2025-07-11T18:35:00Z"), Valid: true}, + Description: sql.NullString{String: "Development work", Valid: true}, + ClientID: 1, + ClientName: "Test Client", + ProjectID: 1, + ProjectName: "Test Project", DurationSeconds: 16800, // 4:40 EntryBillableRate: sql.NullInt64{Int64: 125, Valid: true}, ClientBillableRate: sql.NullInt64{Int64: 125, Valid: true}, @@ -117,15 +116,15 @@ func TestGenerateUnifiedReportData(t *testing.T) { name: "entries with different timezone", entries: []queries.GetInvoiceDataByClientRow{ { - TimeEntryID: 4, - StartTime: mustParseTime("2025-07-15T00:09:00Z"), - EndTime: sql.NullTime{Time: mustParseTime("2025-07-15T00:13:00Z"), Valid: true}, - Description: sql.NullString{String: "Quick fix", Valid: true}, - ClientID: 1, - ClientName: "Test Client", - ProjectID: sql.NullInt64{Int64: 1, Valid: true}, - ProjectName: sql.NullString{String: "Test Project", Valid: true}, - DurationSeconds: 240, // 4 minutes + TimeEntryID: 4, + StartTime: mustParseTime("2025-07-15T00:09:00Z"), + EndTime: sql.NullTime{Time: mustParseTime("2025-07-15T00:13:00Z"), Valid: true}, + Description: sql.NullString{String: "Quick fix", Valid: true}, + ClientID: 1, + ClientName: "Test Client", + ProjectID: sql.NullInt64{Int64: 1, Valid: true}, + ProjectName: sql.NullString{String: "Test Project", Valid: true}, + DurationSeconds: 240, // 4 minutes EntryBillableRate: sql.NullInt64{Int64: 200, Valid: true}, ClientBillableRate: sql.NullInt64{Int64: 200, Valid: true}, ProjectBillableRate: sql.NullInt64{Int64: 200, Valid: true}, @@ -278,14 +277,14 @@ func TestUnifiedReportDataConsistency(t *testing.T) { // Test that unified report produces consistent data between invoice and timesheet components entries := []queries.GetInvoiceDataByClientRow{ { - TimeEntryID: 1, - StartTime: mustParseTime("2025-07-10T14:55:00Z"), - EndTime: sql.NullTime{Time: mustParseTime("2025-07-10T18:05:00Z"), Valid: true}, - Description: sql.NullString{String: "Development work", Valid: true}, - ClientID: 1, - ClientName: "Test Client", - ProjectID: sql.NullInt64{Int64: 1, Valid: true}, - ProjectName: sql.NullString{String: "Test Project", Valid: true}, + TimeEntryID: 1, + StartTime: mustParseTime("2025-07-10T14:55:00Z"), + EndTime: sql.NullTime{Time: mustParseTime("2025-07-10T18:05:00Z"), Valid: true}, + Description: sql.NullString{String: "Development work", Valid: true}, + ClientID: 1, + ClientName: "Test Client", + ProjectID: sql.NullInt64{Int64: 1, Valid: true}, + ProjectName: sql.NullString{String: "Test Project", Valid: true}, DurationSeconds: 11400, // 3:10 EntryBillableRate: sql.NullInt64{Int64: 150, Valid: true}, ClientBillableRate: sql.NullInt64{Int64: 150, Valid: true}, @@ -293,14 +292,14 @@ func TestUnifiedReportDataConsistency(t *testing.T) { RateSource: "entry", }, { - TimeEntryID: 2, - StartTime: mustParseTime("2025-07-10T18:42:00Z"), - EndTime: sql.NullTime{Time: mustParseTime("2025-07-10T20:04:00Z"), Valid: true}, - Description: sql.NullString{String: "Code review", Valid: true}, - ClientID: 1, - ClientName: "Test Client", - ProjectID: sql.NullInt64{Int64: 1, Valid: true}, - ProjectName: sql.NullString{String: "Test Project", Valid: true}, + TimeEntryID: 2, + StartTime: mustParseTime("2025-07-10T18:42:00Z"), + EndTime: sql.NullTime{Time: mustParseTime("2025-07-10T20:04:00Z"), Valid: true}, + Description: sql.NullString{String: "Code review", Valid: true}, + ClientID: 1, + ClientName: "Test Client", + ProjectID: sql.NullInt64{Int64: 1, Valid: true}, + ProjectName: sql.NullString{String: "Test Project", Valid: true}, DurationSeconds: 4920, // 1:22 EntryBillableRate: sql.NullInt64{Int64: 150, Valid: true}, ClientBillableRate: sql.NullInt64{Int64: 150, Valid: true}, @@ -330,7 +329,6 @@ func TestUnifiedReportDataConsistency(t *testing.T) { dateRange, time.UTC, ) - if err != nil { t.Fatalf("GenerateUnifiedReportData() error = %v", err) } @@ -385,15 +383,15 @@ func TestUnifiedReportEntryTypeConversion(t *testing.T) { name: "client entries conversion", entries: []queries.GetInvoiceDataByClientRow{ { - TimeEntryID: 1, - StartTime: mustParseTime("2025-07-10T14:55:00Z"), - EndTime: sql.NullTime{Time: mustParseTime("2025-07-10T18:05:00Z"), Valid: true}, - Description: sql.NullString{String: "Work", Valid: true}, - ClientID: 1, - ClientName: "Test Client", - ProjectID: sql.NullInt64{Int64: 1, Valid: true}, - ProjectName: sql.NullString{String: "Test Project", Valid: true}, - DurationSeconds: 11400, + TimeEntryID: 1, + StartTime: mustParseTime("2025-07-10T14:55:00Z"), + EndTime: sql.NullTime{Time: mustParseTime("2025-07-10T18:05:00Z"), Valid: true}, + Description: sql.NullString{String: "Work", Valid: true}, + ClientID: 1, + ClientName: "Test Client", + ProjectID: sql.NullInt64{Int64: 1, Valid: true}, + ProjectName: sql.NullString{String: "Test Project", Valid: true}, + DurationSeconds: 11400, EntryBillableRate: sql.NullInt64{Int64: 150, Valid: true}, ClientBillableRate: sql.NullInt64{Int64: 150, Valid: true}, ProjectBillableRate: sql.NullInt64{Int64: 150, Valid: true}, @@ -406,14 +404,14 @@ func TestUnifiedReportEntryTypeConversion(t *testing.T) { name: "project entries conversion", entries: []queries.GetInvoiceDataByProjectRow{ { - TimeEntryID: 2, - StartTime: mustParseTime("2025-07-11T13:55:00Z"), - EndTime: sql.NullTime{Time: mustParseTime("2025-07-11T18:35:00Z"), Valid: true}, - Description: sql.NullString{String: "Work", Valid: true}, - ClientID: 1, - ClientName: "Test Client", - ProjectID: 1, - ProjectName: "Test Project", + TimeEntryID: 2, + StartTime: mustParseTime("2025-07-11T13:55:00Z"), + EndTime: sql.NullTime{Time: mustParseTime("2025-07-11T18:35:00Z"), Valid: true}, + Description: sql.NullString{String: "Work", Valid: true}, + ClientID: 1, + ClientName: "Test Client", + ProjectID: 1, + ProjectName: "Test Project", DurationSeconds: 16800, EntryBillableRate: sql.NullInt64{Int64: 125, Valid: true}, ClientBillableRate: sql.NullInt64{Int64: 125, Valid: true}, @@ -526,7 +524,6 @@ func TestUnifiedReportEmptyEntries(t *testing.T) { dateRange, time.UTC, ) - if err != nil { t.Errorf("GenerateUnifiedReportData() error = %v", err) return @@ -559,4 +556,5 @@ func TestUnifiedReportEmptyEntries(t *testing.T) { } }) } -}
\ No newline at end of file +} + |