refac: missing mutation tests, spa specs, checks shown to pass, touch targets, catalogue entry, production code
This commit is contained in:
1 parent
7c15206170
commit
3e02e14da4
48 files changed
+2173
-83
No files matched your search
@@ -0,0 +1,72 @@
|
||||
package test
|
||||
|
||||
import (
|
||||
"RenewCMS/internal/domain/article"
|
||||
"RenewCMS/internal/infrastructure/useCases"
|
||||
"errors"
|
||||
"testing"
|
||||
)
|
||||
|
||||
type batchedSEOIndex struct {
|
||||
batches [][]article.Article
|
||||
stored [][]article.SEORecord
|
||||
storeErr error
|
||||
afterIDs []uint32
|
||||
staleRead int
|
||||
}
|
||||
|
||||
var _ article.SEOIndex = &batchedSEOIndex{}
|
||||
|
||||
func (b *batchedSEOIndex) StaleSEO(afterID uint32, limit int) ([]article.Article, error) {
|
||||
b.afterIDs = append(b.afterIDs, afterID)
|
||||
if b.staleRead >= len(b.batches) {
|
||||
return nil, nil
|
||||
}
|
||||
batch := b.batches[b.staleRead]
|
||||
b.staleRead++
|
||||
return batch, nil
|
||||
}
|
||||
|
||||
func (b *batchedSEOIndex) StoreSEO(records []article.SEORecord) error {
|
||||
b.stored = append(b.stored, records)
|
||||
return b.storeErr
|
||||
}
|
||||
|
||||
func (b *batchedSEOIndex) MarkSiteSEOStale(uint32) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func staleVersion(id uint32) article.Article {
|
||||
return article.Article{ID: id, SiteID: 1, Lang: "en", Title: "Renovation costs", SEOVersion: 3}
|
||||
}
|
||||
|
||||
func TestRefreshArticleSEOBatches(t *testing.T) {
|
||||
t.Run("Every stale batch is stored, each read after the last stored id", func(t *testing.T) {
|
||||
index := &batchedSEOIndex{batches: [][]article.Article{{staleVersion(4), staleVersion(7)}, {staleVersion(9)}}}
|
||||
|
||||
err := useCases.NewRefreshArticleSEOUseCase(index, plainSites(), plainLocalization()).RefreshStale()
|
||||
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if len(index.stored) != 2 || len(index.stored[0]) != 2 || index.stored[1][0].ArticleID != 9 || index.stored[1][0].Version != 3 {
|
||||
t.Fatalf("stored %+v", index.stored)
|
||||
}
|
||||
if len(index.afterIDs) != 3 || index.afterIDs[0] != 0 || index.afterIDs[1] != 7 || index.afterIDs[2] != 9 {
|
||||
t.Fatalf("read after %v", index.afterIDs)
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("A failed store stops the refresh with its error", func(t *testing.T) {
|
||||
index := &batchedSEOIndex{batches: [][]article.Article{{staleVersion(4)}, {staleVersion(9)}}, storeErr: errRepositoryFailure}
|
||||
|
||||
err := useCases.NewRefreshArticleSEOUseCase(index, plainSites(), plainLocalization()).RefreshStale()
|
||||
|
||||
if !errors.Is(err, errRepositoryFailure) {
|
||||
t.Fatalf("err = %v", err)
|
||||
}
|
||||
if len(index.stored) != 1 || index.staleRead != 1 {
|
||||
t.Fatalf("the refresh went on after the failure: %d stores, %d reads", len(index.stored), index.staleRead)
|
||||
}
|
||||
})
|
||||
}
|
||||
Reference in new issue
Block a user