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>
49 lines
2.2 KiB
Go
49 lines
2.2 KiB
Go
package tide
|
|
|
|
import (
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
func TestNormalizeDateIDAndDisable(t *testing.T) {
|
|
step := Step{ID: "n"}
|
|
want := []byte(`{"id":1,"created_at":"2026-01-01T00:00:00+00:00","slug":"keep-me"}`)
|
|
gotOK := []byte(`{"id":9,"created_at":"2026-02-02T00:00:00+00:00","slug":"keep-me"}`)
|
|
gotZ := []byte(`{"id":9,"created_at":"2026-02-02T00:00:00Z","slug":"keep-me"}`)
|
|
gotStrID := []byte(`{"id":"9","created_at":"2026-02-02T00:00:00+00:00","slug":"keep-me"}`)
|
|
gotSlug := []byte(`{"id":9,"created_at":"2026-02-02T00:00:00+00:00","slug":"other"}`)
|
|
|
|
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)
|
|
}
|
|
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)
|
|
if len(zdiffs) == 0 {
|
|
t.Fatal("Z date must fail")
|
|
}
|
|
if !strings.Contains(zdiffs[0].Path, "created_at") {
|
|
t.Fatalf("Z path %s", zdiffs[0].Path)
|
|
}
|
|
idDiffs := compareBodies(Response{Headers: jsonCT(), Body: Body(want)}, Response{Headers: jsonCT(), Body: Body(gotStrID)}, step)
|
|
if len(idDiffs) == 0 || !strings.Contains(idDiffs[0].Path, "id") {
|
|
t.Fatalf("string id: %+v", idDiffs)
|
|
}
|
|
slugDiffs := compareBodies(Response{Headers: jsonCT(), Body: Body(want)}, Response{Headers: jsonCT(), Body: Body(gotSlug)}, step)
|
|
if len(slugDiffs) == 0 || !strings.Contains(slugDiffs[0].Path, "slug") {
|
|
t.Fatalf("slug must stay exact: %+v", slugDiffs)
|
|
}
|
|
|
|
disabled := Step{ID: "n", Normalize: []NormalizeRule{{Path: "created_at", Disable: true}}}
|
|
dDiffs := compareBodies(Response{Headers: jsonCT(), Body: Body(want)}, Response{Headers: jsonCT(), Body: Body(gotOK)}, disabled)
|
|
if len(dDiffs) == 0 {
|
|
t.Fatal("disabled date mask must compare raw timestamps")
|
|
}
|
|
}
|
|
|
|
func jsonCT() map[string]string {
|
|
return map[string]string{"Content-Type": "application/json"}
|
|
}
|