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.
This commit is contained in:
bwilliams committed 2026-10-16 15:24:37 +01:00
1 parent aa06b94870
commit 51d6470649
6 files changed
+287 -3

No files matched your search

+26
View File
@@ -3,6 +3,8 @@ 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 [].
@@ -23,3 +25,27 @@ func TestOpportunitiesUpdatedPayloadJSON(t *testing.T) {
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)
}
}