58 lines
2.5 KiB
Go
58 lines
2.5 KiB
Go
package qaopsorg
|
|
|
|
import (
|
|
"encoding/json"
|
|
"testing"
|
|
)
|
|
|
|
func TestCustomRegionCatalogRejectsAmbiguousOrReservedDefinitions(t *testing.T) {
|
|
for _, regions := range [][]RegionDefinition{
|
|
{{ID: "one", Name: "国内教育"}, {ID: "one", Name: "国外工业Amercia"}},
|
|
{{ID: "one", Name: "国内教育"}, {ID: "two", Name: "国内教育"}},
|
|
{{ID: "unassigned", Name: "区域"}}, {{ID: "one", Name: "cross_region"}},
|
|
{{ID: "__proto__", Name: "区域"}}, {{ID: "one", Name: "constructor"}},
|
|
{{ID: "one", Name: ""}}, {{ID: "one", Name: " 区域"}},
|
|
} {
|
|
if _, err := PreviewRegions(exampleDirectory(), nil, regions); err == nil {
|
|
t.Fatal("invalid region catalog was accepted")
|
|
}
|
|
}
|
|
if _, err := PreviewRegions(exampleDirectory(), []Rule{{DepartmentID: "sales", Region: "missing"}}, []RegionDefinition{{ID: "education", Name: "国内教育"}}); err == nil {
|
|
t.Fatal("unknown mapping ID accepted")
|
|
}
|
|
}
|
|
|
|
func TestCustomRegionCatalogBindsStableIDAndRenamePreservesRules(t *testing.T) {
|
|
directory := exampleDirectory()
|
|
state := State{State: "ready", DirectoryID: "d", Rules: []Rule{}}
|
|
var request SaveRequest
|
|
if err := json.Unmarshal([]byte(`{"directory_id":"d","base_revision":"","regions":[{"id":"education","name":"国内教育"},{"id":"overseas","name":"国外工业Amercia"}],"rules":[{"department_id":"sales","region":"education"},{"department_id":"apac","region":"overseas"}]}`), &request); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
next, err := applyRequest(state, directory, request)
|
|
if err != nil {
|
|
t.Fatalf("custom business regions must not be rejected by the old four-name whitelist: %v", err)
|
|
}
|
|
if next.View.Regions["education"] != 1 || next.View.Regions["overseas"] != 1 || next.View.ConflictingPeople != 1 {
|
|
t.Fatal("inheritance or stable-ID person dedup changed")
|
|
}
|
|
projection, err := BuildAttribution(next, directory)
|
|
if err != nil || projection.Resolve("p2", "").Region != "国外工业Amercia" {
|
|
t.Fatal("attribution did not use the same catalog display name")
|
|
}
|
|
raw, _ := json.Marshal(request)
|
|
var body map[string]any
|
|
_ = json.Unmarshal(raw, &body)
|
|
body["regions"].([]any)[1].(map[string]any)["name"] = "国外工业 EMEA"
|
|
raw, _ = json.Marshal(body)
|
|
_ = json.Unmarshal(raw, &request)
|
|
renamed, err := applyRequest(next, directory, request)
|
|
if err != nil || renamed.Rules[0].Region != next.Rules[0].Region {
|
|
t.Fatal("renaming changed the stable mapping")
|
|
}
|
|
projection, err = BuildAttribution(renamed, directory)
|
|
if err != nil || projection.Resolve("p2", "").Region != "国外工业 EMEA" {
|
|
t.Fatal("renamed catalog not consumed by attribution")
|
|
}
|
|
}
|