39 lines
1.2 KiB
Go
39 lines
1.2 KiB
Go
package api
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
|
|
"droboticflow/internal/store"
|
|
"droboticflow/internal/workforcestats"
|
|
)
|
|
|
|
type compactWorkforceProbe struct {
|
|
store.Store
|
|
rawCalls, reportCalls int
|
|
}
|
|
|
|
func (p *compactWorkforceProbe) LoadWorkforceStatsCached(ctx context.Context, org string, q workforcestats.Query) (workforcestats.Snapshot, error) {
|
|
p.rawCalls++
|
|
return p.Store.LoadWorkforceStats(ctx, org, q)
|
|
}
|
|
|
|
func (p *compactWorkforceProbe) LoadWorkforceReportCached(ctx context.Context, org string, q workforcestats.Query) (workforcestats.Report, error) {
|
|
p.reportCalls++
|
|
d, err := p.Store.LoadWorkforceStats(ctx, org, q)
|
|
return workforcestats.Build(d, q), err
|
|
}
|
|
|
|
func TestDashboardWorkforcePrefersCompactReportCache(t *testing.T) {
|
|
f := sharedAcceptanceFixture(t)
|
|
probe := &compactWorkforceProbe{Store: f.store}
|
|
f.handler = NewHandler(probe, nil)
|
|
r := f.request("GET", "/api/dashboard/workforce?from=2026-11-01T00:00:00Z&to=2026-11-14T00:00:00Z", f.reviewer, nil)
|
|
if r.Code != 200 {
|
|
t.Fatalf("%d %s", r.Code, r.Body.String())
|
|
}
|
|
if probe.reportCalls != 1 || probe.rawCalls != 0 {
|
|
t.Fatalf("dashboard retained raw snapshot path: reports=%d raw=%d", probe.reportCalls, probe.rawCalls)
|
|
}
|
|
}
|