Files
job-search/internal/events/events_test.go
T
bwilliams 51d6470649 Added a ClassificationsUpdated event
SaveOpportunities now reports the classification codes a save brings into
use (AddedClassifications, in full) and takes out of use
(RemovedClassificationIDs), by comparing the codes in use before and after
the save inside its transaction. The fetcher publishes them as a
ClassificationsUpdated event, {"added":[codes],"removed":[ids]}, never null,
before the save's OpportunitiesUpdated, so clients can keep their list of
classifications without asking the API again.
2026-10-16 15:24:37 +01:00

52 lines
1.2 KiB
Go

package events
import (
"encoding/json"
"testing"
"git.avsdev.uk/Go/job-search/internal/types"
)
// The payload marshals with the keys clients read, and empty lists as [].
func TestOpportunitiesUpdatedPayloadJSON(t *testing.T) {
payload := OpportunitiesUpdatedPayload{
New: []string{"ocds-1"},
Updated: []string{},
Summary: OpportunitiesSummary{
New: 1,
},
}
encoded, err := json.Marshal(payload)
if err != nil {
t.Fatal(err)
}
want := `{"new":["ocds-1"],"updated":[],"summary":{"new":1,"updated":0}}`
if string(encoded) != want {
t.Errorf("JSON = %s; want %s", encoded, want)
}
}
// The classifications payload marshals with the keys clients read.
func TestClassificationsUpdatedPayloadJSON(t *testing.T) {
payload := ClassificationsUpdatedPayload{
Added: []types.ClassificationCode{
{
ID: 7,
IsCPV: true,
Code: "72000000",
Classification: "IT services",
},
},
Removed: []int64{3},
}
encoded, err := json.Marshal(payload)
if err != nil {
t.Fatal(err)
}
want := `{"added":[{"id":7,"is_cpv":true,"code":"72000000",` +
`"classification":"IT services"}],"removed":[3]}`
if string(encoded) != want {
t.Errorf("JSON = %s; want %s", encoded, want)
}
}