fix(02-03): treat null foreign keys as valid masked ids
PHP album payloads leave discogs_id null. The id mask required an integer and failed PHP self-replay on otherwise identical bodies. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -81,6 +81,9 @@ func maskDate(path string, val any, diffs *[]Diff) any {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func maskIDValue(path string, val any, diffs *[]Diff) any {
|
func maskIDValue(path string, val any, diffs *[]Diff) any {
|
||||||
|
if val == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
n, ok := val.(json.Number)
|
n, ok := val.(json.Number)
|
||||||
if !ok {
|
if !ok {
|
||||||
*diffs = append(*diffs, Diff{Path: path, Expected: "integer id", Actual: formatValue(val)})
|
*diffs = append(*diffs, Diff{Path: path, Expected: "integer id", Actual: formatValue(val)})
|
||||||
|
|||||||
@@ -16,6 +16,10 @@ func TestNormalizeDateIDAndDisable(t *testing.T) {
|
|||||||
if diffs := compareBodies(Response{Headers: jsonCT(), Body: Body(want)}, Response{Headers: jsonCT(), Body: Body(gotOK)}, step); len(diffs) != 0 {
|
if diffs := compareBodies(Response{Headers: jsonCT(), Body: Body(want)}, Response{Headers: jsonCT(), Body: Body(gotOK)}, step); len(diffs) != 0 {
|
||||||
t.Fatalf("masked date/id should pass: %+v", diffs)
|
t.Fatalf("masked date/id should pass: %+v", diffs)
|
||||||
}
|
}
|
||||||
|
nullID := []byte(`{"id":1,"discogs_id":null,"created_at":"2026-01-01T00:00:00+00:00","slug":"keep-me"}`)
|
||||||
|
if diffs := compareBodies(Response{Headers: jsonCT(), Body: Body(nullID)}, Response{Headers: jsonCT(), Body: Body(nullID)}, step); len(diffs) != 0 {
|
||||||
|
t.Fatalf("null *_id must pass: %+v", diffs)
|
||||||
|
}
|
||||||
zdiffs := compareBodies(Response{Headers: jsonCT(), Body: Body(want)}, Response{Headers: jsonCT(), Body: Body(gotZ)}, step)
|
zdiffs := compareBodies(Response{Headers: jsonCT(), Body: Body(want)}, Response{Headers: jsonCT(), Body: Body(gotZ)}, step)
|
||||||
if len(zdiffs) == 0 {
|
if len(zdiffs) == 0 {
|
||||||
t.Fatal("Z date must fail")
|
t.Fatal("Z date must fail")
|
||||||
|
|||||||
Reference in New Issue
Block a user