A CPV code is now stored once, keeping its longest description
This commit is contained in:
1 parent
b0f93fd437
commit
0a777792d8
5 files changed
+209
-8
No files matched your search
@@ -3,6 +3,7 @@ package store_test
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"path/filepath"
|
||||
"slices"
|
||||
"strings"
|
||||
@@ -273,8 +274,9 @@ func TestNewerReleaseUpdatesOpportunityAndSearchIndex(t *testing.T) {
|
||||
got.Classifications[0].Classification != "IT services (amended)" {
|
||||
t.Fatalf("classifications not replaced: %+v", got.Classifications)
|
||||
}
|
||||
if got.Classifications[0].ID == oldIT {
|
||||
t.Errorf("changed description should create a new classification row")
|
||||
// A CPV code is one row: the longer description replaces the shorter.
|
||||
if got.Classifications[0].ID != oldIT {
|
||||
t.Errorf("a CPV code's new description should keep its row")
|
||||
}
|
||||
|
||||
for title, want := range map[string]int{"cloud": 0, "redesign": 1} {
|
||||
@@ -295,6 +297,61 @@ func TestNewerReleaseUpdatesOpportunityAndSearchIndex(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// A CPV code keeps one row and its longest description, whichever order
|
||||
// the descriptions arrive in (EU Supply cuts them to 64 characters); a code
|
||||
// of another scheme still gets a row per description.
|
||||
func TestCPVCodeKeepsLongestDescription(t *testing.T) {
|
||||
const full = "Petroleum products, fuel, electricity and other sources of energy"
|
||||
cut := full[:64]
|
||||
for name, order := range map[string][]string{
|
||||
"full first": {full, cut},
|
||||
"cut first": {cut, full},
|
||||
} {
|
||||
t.Run(name, func(t *testing.T) {
|
||||
s := openStore(t)
|
||||
var ids []int64
|
||||
for i, description := range order {
|
||||
o := opportunity(fmt.Sprintf("ocds-%d", i), "Fuel", 1, "r1")
|
||||
o.Classifications = []types.ClassificationCode{
|
||||
{
|
||||
IsCPV: true,
|
||||
Code: "09000000",
|
||||
Classification: description,
|
||||
},
|
||||
}
|
||||
mustSave(t, s, o)
|
||||
ids = append(ids, o.Classifications[0].ID)
|
||||
}
|
||||
if ids[0] != ids[1] {
|
||||
t.Errorf("ids = %v; want one row for the code", ids)
|
||||
}
|
||||
for _, uuid := range []string{"ocds-0", "ocds-1"} {
|
||||
got := mustGet(t, s, uuid).Classifications[0].Classification
|
||||
if got != full {
|
||||
t.Errorf("%s: description = %q; want the full one", uuid, got)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
s := openStore(t)
|
||||
var ids []int64
|
||||
for i, description := range []string{"Scheme X", "Scheme X, amended"} {
|
||||
o := opportunity(fmt.Sprintf("other-%d", i), "Other", 1, "r1")
|
||||
o.Classifications = []types.ClassificationCode{
|
||||
{
|
||||
Code: "123",
|
||||
Classification: description,
|
||||
},
|
||||
}
|
||||
mustSave(t, s, o)
|
||||
ids = append(ids, o.Classifications[0].ID)
|
||||
}
|
||||
if ids[0] == ids[1] {
|
||||
t.Errorf("a non-CPV code's descriptions share a row: %v", ids)
|
||||
}
|
||||
}
|
||||
|
||||
func TestClassificationRowsAreShared(t *testing.T) {
|
||||
s := openStore(t)
|
||||
a := opportunity("ocds-a", "A", 1, "r1")
|
||||
|
||||
Reference in new issue
Block a user