owl-blogs/infra/config_repository_test.go

72 lines
1.6 KiB
Go
Raw Permalink Normal View History

2023-07-16 19:08:25 +00:00
package infra_test
import (
"owl-blogs/app/repository"
"owl-blogs/domain/model"
2023-07-16 19:08:25 +00:00
"owl-blogs/infra"
"owl-blogs/test"
"testing"
"github.com/stretchr/testify/require"
)
func setupSiteConfigRepo() repository.ConfigRepository {
2023-07-16 19:08:25 +00:00
db := test.NewMockDb()
repo := infra.NewConfigRepo(db)
2023-07-16 19:08:25 +00:00
return repo
}
func TestSiteConfigRepo(t *testing.T) {
repo := setupSiteConfigRepo()
config := model.SiteConfig{}
err := repo.Get("test", &config)
2023-07-16 19:08:25 +00:00
require.NoError(t, err)
require.Equal(t, "", config.Title)
require.Equal(t, "", config.SubTitle)
config.Title = "title"
config.SubTitle = "SubTitle"
err = repo.Update("test", config)
2023-07-16 19:08:25 +00:00
require.NoError(t, err)
config2 := model.SiteConfig{}
err = repo.Get("test", &config2)
2023-07-16 19:08:25 +00:00
require.NoError(t, err)
require.Equal(t, "title", config2.Title)
require.Equal(t, "SubTitle", config2.SubTitle)
}
func TestSiteConfigUpdates(t *testing.T) {
repo := setupSiteConfigRepo()
config := model.SiteConfig{}
err := repo.Get("test", &config)
2023-07-16 19:08:25 +00:00
require.NoError(t, err)
require.Equal(t, "", config.Title)
require.Equal(t, "", config.SubTitle)
config.Title = "title"
config.SubTitle = "SubTitle"
err = repo.Update("test", config)
2023-07-16 19:08:25 +00:00
require.NoError(t, err)
config2 := model.SiteConfig{}
err = repo.Get("test", &config2)
2023-07-16 19:08:25 +00:00
require.NoError(t, err)
require.Equal(t, "title", config2.Title)
require.Equal(t, "SubTitle", config2.SubTitle)
config2.Title = "title2"
config2.SubTitle = "SubTitle2"
err = repo.Update("test", config2)
2023-07-16 19:08:25 +00:00
require.NoError(t, err)
config3 := model.SiteConfig{}
err = repo.Get("test", &config3)
2023-07-16 19:08:25 +00:00
require.NoError(t, err)
require.Equal(t, "title2", config3.Title)
require.Equal(t, "SubTitle2", config3.SubTitle)
}