package classes import ( "testing" "git.golem15.com/golem15/summercms/modules/pact" ) // TestRealChanges pins which saves move lastmod (D-30, RESEARCH Pitfall // 4): nothing for an empty or ignored-only change list; every locale for a // change on the record's own row; only the named locales for translated // changes. func TestRealChanges(t *testing.T) { ignore := map[string]bool{"updated_at": true, "views": true} for name, c := range map[string]struct { changes []pact.RecordChange any bool all bool locales []string }{ "no-op save": {nil, false, false, nil}, "ignored only": {[]pact.RecordChange{{Attribute: "updated_at"}, {Attribute: "views"}}, false, false, nil}, "own row": {[]pact.RecordChange{{Attribute: "updated_at"}, {Attribute: "title"}}, true, true, nil}, "translated": {[]pact.RecordChange{{Attribute: "title", Locale: "pl"}, {Attribute: "slug", Locale: "de"}}, true, false, []string{"de", "pl"}}, "both": {[]pact.RecordChange{{Attribute: "title", Locale: "pl"}, {Attribute: "content"}}, true, true, nil}, } { got := RealChanges(c.changes, ignore) if got.Any != c.any || got.All != c.all || len(got.Locales) != len(c.locales) { t.Errorf("%s: %+v", name, got) continue } for _, l := range c.locales { if !got.Locales[l] { t.Errorf("%s: locale %s missing in %+v", name, l, got) } } } }