2021-12-11 18:43:40 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
)
|
|
|
|
|
|
|
|
func Test_postsScheduler(t *testing.T) {
|
|
|
|
|
|
|
|
app := &goBlog{
|
2022-07-16 19:09:43 +00:00
|
|
|
cfg: createDefaultTestConfig(t),
|
|
|
|
}
|
|
|
|
app.cfg.Blogs = map[string]*configBlog{
|
|
|
|
"en": {
|
|
|
|
Sections: map[string]*configSection{
|
|
|
|
"test": {},
|
2021-12-11 18:43:40 +00:00
|
|
|
},
|
2022-07-16 19:09:43 +00:00
|
|
|
Lang: "en",
|
2021-12-11 18:43:40 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2022-07-16 19:09:43 +00:00
|
|
|
_ = app.initConfig(false)
|
2022-07-17 08:54:03 +00:00
|
|
|
_ = app.initCache()
|
2021-12-11 18:43:40 +00:00
|
|
|
|
|
|
|
err := app.db.savePost(&post{
|
2022-09-23 09:05:07 +00:00
|
|
|
Path: "/test/abc",
|
|
|
|
Content: "ABC",
|
|
|
|
Published: toLocalSafe(time.Now().Add(-1 * time.Hour).String()),
|
|
|
|
Blog: "en",
|
|
|
|
Section: "test",
|
|
|
|
Status: statusScheduled,
|
|
|
|
Visibility: visibilityPublic,
|
2021-12-11 18:43:40 +00:00
|
|
|
}, &postCreationOptions{new: true})
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
2022-09-23 09:05:07 +00:00
|
|
|
count, err := app.db.countPosts(&postsRequestConfig{status: []postStatus{statusScheduled}})
|
2021-12-11 18:43:40 +00:00
|
|
|
require.NoError(t, err)
|
2022-09-23 09:05:07 +00:00
|
|
|
assert.Equal(t, 1, count)
|
2021-12-11 18:43:40 +00:00
|
|
|
|
|
|
|
app.checkScheduledPosts()
|
|
|
|
|
2022-09-23 09:05:07 +00:00
|
|
|
count, err = app.db.countPosts(&postsRequestConfig{status: []postStatus{statusScheduled}})
|
2021-12-11 18:43:40 +00:00
|
|
|
require.NoError(t, err)
|
2022-09-23 09:05:07 +00:00
|
|
|
assert.Equal(t, 0, count)
|
2021-12-11 18:43:40 +00:00
|
|
|
|
|
|
|
}
|