Add new test for section settings

pull/25/head
Jan-Lukas Else 3 weeks ago
parent 5b4c20b917
commit e0da309f56
  1. 55
      settingsDb_test.go

@ -0,0 +1,55 @@
package main
import (
"testing"
"github.com/samber/lo"
"github.com/stretchr/testify/require"
)
func Test_settingsDb_sections(t *testing.T) {
app := &goBlog{
cfg: createDefaultTestConfig(t),
}
_ = app.initConfig(false)
require.Len(t, lo.Values(app.cfg.Blogs), 1)
sections, err := app.getSections(app.cfg.DefaultBlog)
require.NoError(t, err)
require.Len(t, lo.Values(sections), 1)
// Update
section := lo.Values(sections)[0]
section.Title = "New Title"
err = app.saveSection(app.cfg.DefaultBlog, section)
require.NoError(t, err)
// Check update
sections, err = app.getSections(app.cfg.DefaultBlog)
require.NoError(t, err)
require.Len(t, lo.Values(sections), 1)
section = lo.Values(sections)[0]
require.Equal(t, "New Title", section.Title)
// New section
section = &configSection{
Name: "new",
Title: "New section",
}
err = app.saveSection(app.cfg.DefaultBlog, section)
require.NoError(t, err)
// Check new section count
sections, err = app.getSections(app.cfg.DefaultBlog)
require.NoError(t, err)
require.Len(t, lo.Values(sections), 2)
// Delete section
err = app.deleteSection(app.cfg.DefaultBlog, "new")
require.NoError(t, err)
sections, err = app.getSections(app.cfg.DefaultBlog)
require.NoError(t, err)
require.Len(t, lo.Values(sections), 1)
}
Loading…
Cancel
Save