Files
phishingclub/backend/service/programExport_test.go
2026-12-01 21:25:01 +01:00

40 lines
1.4 KiB
Go

package service
import (
"strings"
"testing"
)
func TestProgramAggregateCSVWithholds(t *testing.T) {
results := &ProgramResults{
Anonymous: true,
Summary: &ProgramSummary{Recipients: 20, HasPhishing: true, Sent: intPtr(18), ClickedLink: nil, SubmittedData: intPtr(0), Reported: intPtr(7)},
Months: []*ProgramResultRow{{Key: "2025-05", Name: "May 2025", Suppressed: true}},
Templates: []*ProgramResultRow{
{Key: "t", Name: "=HYPERLINK(\"x\")", Sent: intPtr(9), Clicked: intPtr(1), Submitted: intPtr(0), Reported: intPtr(2)},
},
}
rows := programAggregateCSV(results)
// header, 5 result rows without training and without repeat offenders,
// which an anonymous program never counts, a month and a template
if len(rows) != 8 {
t.Fatalf("expected 8 rows, got %d", len(rows))
}
labels := []string{}
for _, r := range rows[1:6] {
labels = append(labels, r[2])
}
if strings.Join(labels, ",") != "Recipients,Sent,Clicked link,Data submitted,Reported" {
t.Fatalf("result rows: %v", labels)
}
if rows[3][3] != "" || rows[3][9] != "yes" || rows[5][3] != "7" {
t.Fatalf("a withheld result has no value: %v %v", rows[3], rows[5])
}
if rows[6][4] != "" || rows[6][9] != "yes" {
t.Fatalf("suppressed month must have no counts: %v", rows[6])
}
if rows[7][2] != "'=HYPERLINK(\"x\")" || rows[7][4] != "9" {
t.Fatalf("template row wrong: %v", rows[7])
}
}