Files
summercms/tide/normalize_test.go
Jakub Zych aa165fe3d0 feat(02-02): capture, scrub, and strictly diff stateful flows
Resolve named placeholders from a private variable store, mask
dates and ids after shape checks, and keep comparing independent steps.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-09-17 12:32:49 +02:00

45 lines
1.9 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)
}
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"}
}