Add internal/services/membership package: AttendanceLoader, TransactionLoader, ExceptionLoader interfaces + NewStubSources stub (returns ErrIOPending until M4 lands real Sheets loaders). FeesReport and ReconcileReport orchestrate domain/fees + domain/reconcile and write fixed-width text reports matching Python calculate_fees.py and match_payments.py print_report output. 13 unit tests cover all formatter branches and orchestration wiring via fake loaders. cmd/fuj/main.go: fees and reconcile subcommands now dispatch; sync/infer retain the [M4] placeholder. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
48 lines
1.1 KiB
Go
48 lines
1.1 KiB
Go
package membership
|
|
|
|
import (
|
|
"bytes"
|
|
"context"
|
|
"fuj-management/go/internal/domain/reconcile"
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
type fakeAttendanceLoader struct {
|
|
members []reconcile.Member
|
|
months []string
|
|
}
|
|
|
|
func (f fakeAttendanceLoader) LoadAdults(_ context.Context) ([]reconcile.Member, []string, error) {
|
|
return f.members, f.months, nil
|
|
}
|
|
|
|
func TestFeesReport(t *testing.T) {
|
|
t.Parallel()
|
|
loader := fakeAttendanceLoader{
|
|
members: []reconcile.Member{
|
|
{Name: "Alice", Tier: "A", Fees: map[string]reconcile.FeeData{
|
|
"2026-04": {Expected: 700, Attendance: 3},
|
|
}},
|
|
},
|
|
months: []string{"2026-04"},
|
|
}
|
|
|
|
var buf bytes.Buffer
|
|
if err := FeesReport(context.Background(), loader, &buf); err != nil {
|
|
t.Fatalf("unexpected error: %v", err)
|
|
}
|
|
if !strings.Contains(buf.String(), "700 CZK (3)") {
|
|
t.Errorf("expected '700 CZK (3)' in output, got:\n%s", buf.String())
|
|
}
|
|
}
|
|
|
|
func TestFeesReportStubErrors(t *testing.T) {
|
|
t.Parallel()
|
|
var buf bytes.Buffer
|
|
err := FeesReport(context.Background(), NewStubSources(), &buf)
|
|
if err == nil {
|
|
t.Fatal("expected error from stub, got nil")
|
|
}
|
|
}
|