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, }, Batch: "abc", } encoded, err := json.Marshal(payload) if err != nil { t.Fatal(err) } want := `{"new":["ocds-1"],"updated":[],"large":false,` + `"summary":{"new":1,"updated":0},"batch":"abc"}` 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) } }