feat: editorial article list
This commit is contained in:
1 parent
a0b3c58c52
commit
a671b81f80
103 files changed
+6493
-1805
No files matched your search
@@ -0,0 +1,68 @@
|
||||
package test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"RenewCMS/internal/domain/article"
|
||||
"RenewCMS/internal/infrastructure/useCases"
|
||||
)
|
||||
|
||||
func TestListStoriesPageSuggestionCounts(t *testing.T) {
|
||||
cases := []struct {
|
||||
name string
|
||||
articles []article.Article
|
||||
want int
|
||||
}{
|
||||
{"versions of one story count once", []article.Article{
|
||||
{ID: 1, StoryID: 10, SiteID: 1, IsOnline: true},
|
||||
{ID: 2, StoryID: 10, SiteID: 1, IsOnline: true},
|
||||
}, 1},
|
||||
{"stories without an id count individually", []article.Article{
|
||||
{ID: 1, StoryID: 0, SiteID: 1, IsOnline: true},
|
||||
{ID: 2, StoryID: 0, SiteID: 1, IsOnline: true},
|
||||
{ID: 3, StoryID: 10, SiteID: 1, IsOnline: true},
|
||||
}, 3},
|
||||
{"offline versions are not visible to a reader", []article.Article{
|
||||
{ID: 1, StoryID: 10, SiteID: 1, IsOnline: false},
|
||||
}, 0},
|
||||
}
|
||||
for _, c := range cases {
|
||||
t.Run(c.name, func(t *testing.T) {
|
||||
repo := newMockArticleRepo()
|
||||
for _, a := range c.articles {
|
||||
repo.articles[a.ID] = a
|
||||
}
|
||||
uc := useCases.NewListArticlesUseCase(repo, &fakeBodyRenderer{}, plainSites(), newFakeLocalizationStore(repo))
|
||||
page, err := uc.ListStoriesPage(useCases.ListStoriesCommand{Page: 1, Size: 10})
|
||||
if err != nil {
|
||||
t.Fatalf("unexpected error: %v", err)
|
||||
}
|
||||
if page.Counts.Suggestions != c.want {
|
||||
t.Fatalf("suggestions = %d, want %d", page.Counts.Suggestions, c.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestListArticlesPageSEOFilterAndSuggestionCount(t *testing.T) {
|
||||
repo := newMockArticleRepo()
|
||||
for id := uint32(1); id <= 3; id++ {
|
||||
repo.articles[id] = article.Article{ID: id, StoryID: id, SiteID: 1, IsOnline: true}
|
||||
}
|
||||
uc := useCases.NewListArticlesUseCase(repo, &fakeBodyRenderer{}, plainSites(), plainLocalization())
|
||||
page, err := uc.ListArticlesPage(useCases.ListArticlesCommand{Page: 2, Size: 2, SEO: article.SEOStatusSuggestions})
|
||||
if err != nil {
|
||||
t.Fatalf("unexpected error: %v", err)
|
||||
}
|
||||
if page.Total != 3 || len(page.Items) != 1 || page.Counts.Suggestions != 3 {
|
||||
t.Fatalf("total=%d items=%d suggestions=%d, want 3/1/3", page.Total, len(page.Items), page.Counts.Suggestions)
|
||||
}
|
||||
beyond, _ := uc.ListArticlesPage(useCases.ListArticlesCommand{Page: 3, Size: 2, SEO: article.SEOStatusSuggestions})
|
||||
if len(beyond.Items) != 0 || beyond.Total != 3 {
|
||||
t.Fatalf("beyond: items=%d total=%d, want 0/3", len(beyond.Items), beyond.Total)
|
||||
}
|
||||
none, _ := uc.ListArticlesPage(useCases.ListArticlesCommand{Page: 1, Size: 2, SEO: article.SEOStatusReady})
|
||||
if none.Total != 0 || len(none.Items) != 0 {
|
||||
t.Fatalf("ready: total=%d items=%d, want 0/0", none.Total, len(none.Items))
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user