Added api/classifications endpoint, requiring a new query

This commit is contained in:
bwilliams committed 2026-10-16 14:44:12 +01:00
1 parent 378ac59f41
commit 0e27d2b2f3
9 files changed
+186 -6

No files matched your search

+42
View File
@@ -4,6 +4,7 @@ import (
"context"
"errors"
"path/filepath"
"strings"
"testing"
"time"
@@ -902,3 +903,44 @@ func TestSaveResultNewOpportunity(t *testing.T) {
)
}
}
// ListClassifications lists the codes in use, once each and sorted, and not
// a code no opportunity has any more.
func TestListClassifications(t *testing.T) {
s := openStore(t)
ctx := context.Background()
got, err := s.ListClassifications(ctx)
if err != nil || got == nil || len(got) != 0 {
t.Fatalf("empty store: %v, %v; want an empty, non-nil list", got, err)
}
mustSave(t, s, opportunity("ocds-1", "First", 1, "r1"))
mustSave(t, s, opportunity("ocds-2", "Second", 1, "r1"))
codes := func() []string {
t.Helper()
got, err := s.ListClassifications(ctx)
if err != nil {
t.Fatal(err)
}
var listed []string
for _, classification := range got {
listed = append(listed, classification.Code)
}
return listed
}
if got := strings.Join(codes(), ","); got != "03000000,72000000" {
t.Fatalf("codes = %s; want 03000000,72000000", got)
}
// Newer releases replace both opportunities' classifications with one
// code; the other is still stored, but no longer listed.
for _, uuid := range []string{"ocds-1", "ocds-2"} {
newer := opportunity(uuid, "Newer", 2, "r2")
newer.Classifications = newer.Classifications[1:]
mustSave(t, s, newer)
}
if got := strings.Join(codes(), ","); got != "03000000" {
t.Errorf("after the change: codes = %s; want 03000000", got)
}
}