Files
RenewCMS/test/article_impact_cover_test.go
T

78 lines
2.8 KiB
Go

package test
import (
"RenewCMS/internal/domain/article"
"testing"
)
func TestArticleImpactOfImageIdentity(t *testing.T) {
one, sameOne, two := uint32(1), uint32(1), uint32(2)
cases := []struct {
name string
before, after *uint32
edited bool
}{
{"both absent", nil, nil, false},
{"added", nil, &one, true},
{"removed", &one, nil, true},
{"same id", &one, &sameOne, false},
{"other id", &one, &two, true},
}
for _, c := range cases {
t.Run(c.name, func(t *testing.T) {
for _, social := range []bool{false, true} {
before, after := article.Article{}, article.Article{}
if social {
before.SocialImageID, after.SocialImageID = c.before, c.after
} else {
before.CoverImageID, after.CoverImageID = c.before, c.after
}
impact := article.ImpactOf(before, after, false)
if impact.Edited != c.edited || impact.Content {
t.Errorf("social=%v: got %+v, want edited=%v content=false", social, impact, c.edited)
}
}
})
}
}
func TestArticleImpactOfPerField(t *testing.T) {
cases := []struct {
name string
change func(a *article.Article)
authors bool
edited bool
content bool
}{
{"nothing", func(a *article.Article) {}, false, false, false},
{"title", func(a *article.Article) { a.Title = "other" }, false, true, true},
{"body", func(a *article.Article) { a.Body = "other" }, false, true, true},
{"excerpt", func(a *article.Article) { a.Excerpt = "other" }, false, true, true},
{"slug", func(a *article.Article) { a.Slug = "other" }, false, true, true},
{"cover alt", func(a *article.Article) { a.CoverImageAlt = "other" }, false, true, true},
{"seo title", func(a *article.Article) { a.SEOTitle = "other" }, false, true, true},
{"seo description", func(a *article.Article) { a.SEODescription = "other" }, false, true, true},
{"social title", func(a *article.Article) { a.SocialTitle = "other" }, false, true, true},
{"social description", func(a *article.Article) { a.SocialDescription = "other" }, false, true, true},
{"authors", func(a *article.Article) {}, true, true, false},
{"site", func(a *article.Article) { a.SiteID = 9 }, false, true, false},
{"canonical url", func(a *article.Article) { a.CanonicalURL = "https://example.org/a" }, false, true, false},
{"noindex", func(a *article.Article) { a.Noindex = true }, false, true, false},
{"seo dismissed", func(a *article.Article) { a.SEODismissed = []string{"title"} }, false, true, false},
{"is online", func(a *article.Article) { a.IsOnline = true }, false, false, false},
}
for _, c := range cases {
t.Run(c.name, func(t *testing.T) {
before := article.Article{}
after := before
c.change(&after)
impact := article.ImpactOf(before, after, c.authors)
if impact.Edited != c.edited || impact.Content != c.content {
t.Errorf("got %+v, want edited=%v content=%v", impact, c.edited, c.content)
}
})
}
}