refac: migration crash, real-database tests, site deleted during create, ruels out of the repo, lists
This commit is contained in:
1 parent
680b9a1308
commit
9d284e65a9
62 files changed
+1858
-987
No files matched your search
@@ -176,6 +176,10 @@ func createTitled(db *gorm.DB, title string) (domainArticle.Article, error) {
|
||||
return createThroughUseCase(db).CreateArticle(context.Background(), useCases.CreateArticleCommand{Title: title, Caller: ownerCaller(1)})
|
||||
}
|
||||
|
||||
func confirmDefaultLanguage(db *gorm.DB, siteID uint32) error {
|
||||
return useCases.NewConfirmDefaultLanguageUseCase(persistence.NewTransactor(db)).Confirm(context.Background(), siteID)
|
||||
}
|
||||
|
||||
func newStorageArticle(siteID uint32, lang string, slug string, storyID uint32) domainArticle.Article {
|
||||
return domainArticle.Article{Title: "Article " + slug, Body: "Body", SiteID: siteID, Lang: lang, Slug: slug, StoryID: storyID, SEODismissed: []string{}}
|
||||
}
|
||||
@@ -406,7 +410,7 @@ func runArticleLocalizationStorage(t *testing.T, open func(*testing.T) *gorm.DB)
|
||||
t.Run("Creating an article after the default is confirmed", func(t *testing.T) {
|
||||
db, site := legacyDatabase(t, open, localeOf("fr-CA"))
|
||||
migrateStorage(t, db)
|
||||
if err := persistence.NewSiteLanguageRepository(db).ConfirmDefault(site.ID); err != nil {
|
||||
if err := confirmDefaultLanguage(db, site.ID); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
@@ -426,7 +430,6 @@ func runArticleLocalizationStorage(t *testing.T, open func(*testing.T) *gorm.DB)
|
||||
t.Run("Create racing a confirmation never strands an article", func(t *testing.T) {
|
||||
db, site := legacyDatabase(t, open, localeOf("fr-CA"))
|
||||
migrateStorage(t, db)
|
||||
languages := persistence.NewSiteLanguageRepository(db)
|
||||
var group sync.WaitGroup
|
||||
var retries atomic.Int64
|
||||
start := make(chan struct{})
|
||||
@@ -457,7 +460,7 @@ func runArticleLocalizationStorage(t *testing.T, open func(*testing.T) *gorm.DB)
|
||||
go func() {
|
||||
defer group.Done()
|
||||
<-start
|
||||
failures <- retry(func() error { return languages.ConfirmDefault(site.ID) })
|
||||
failures <- retry(func() error { return confirmDefaultLanguage(db, site.ID) })
|
||||
}()
|
||||
close(start)
|
||||
group.Wait()
|
||||
@@ -540,13 +543,12 @@ func runArticleLocalizationStorage(t *testing.T, open func(*testing.T) *gorm.DB)
|
||||
t.Run("Assigning a language is idempotent", func(t *testing.T) {
|
||||
db, site := legacyDatabase(t, open, localeOf("fr-CA"))
|
||||
migrateStorage(t, db)
|
||||
languages := persistence.NewSiteLanguageRepository(db)
|
||||
if err := languages.ConfirmDefault(site.ID); err != nil {
|
||||
if err := confirmDefaultLanguage(db, site.ID); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
before := storageSnapshot(t, db)
|
||||
|
||||
err := languages.ConfirmDefault(site.ID)
|
||||
err := confirmDefaultLanguage(db, site.ID)
|
||||
|
||||
if err != nil || storageSnapshot(t, db) != before {
|
||||
t.Errorf("the second assignment must change nothing: %v", err)
|
||||
@@ -562,7 +564,7 @@ func runArticleLocalizationStorage(t *testing.T, open func(*testing.T) *gorm.DB)
|
||||
db := open(t)
|
||||
site := storageDefaultSite(t, db)
|
||||
|
||||
err := persistence.NewSiteLanguageRepository(db).ConfirmDefault(site.ID)
|
||||
err := confirmDefaultLanguage(db, site.ID)
|
||||
|
||||
if !errors.Is(err, language.ErrNoDefaultLanguage) {
|
||||
t.Errorf("expected ErrNoDefaultLanguage, got %v", err)
|
||||
|
||||
Reference in new issue
Block a user