mirror of
https://gitlab.dit.htwk-leipzig.de/htwk-software/htwkalender.git
synced 2025-07-23 13:08:48 +02:00
84 lines
1.7 KiB
Go
84 lines
1.7 KiB
Go
package feed
|
|
|
|
import (
|
|
"github.com/pocketbase/pocketbase/daos"
|
|
"github.com/pocketbase/pocketbase/tests"
|
|
"htwkalender/model"
|
|
mockTime "htwkalender/service/functions/time"
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
const testDataDir = "./mockData"
|
|
|
|
func TestClearFeeds(t *testing.T) {
|
|
|
|
setupTestApp := func(t *testing.T) *daos.Dao {
|
|
testApp, err := tests.NewTestApp(testDataDir)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
dao := daos.New(testApp.Dao().DB())
|
|
return dao
|
|
}
|
|
|
|
type args struct {
|
|
db *daos.Dao
|
|
months int
|
|
mockClock mockTime.MockClock
|
|
}
|
|
testCases := []struct {
|
|
name string
|
|
args args
|
|
want int
|
|
}{
|
|
{
|
|
name: "TestClearFeeds",
|
|
args: args{
|
|
db: setupTestApp(t),
|
|
months: 6,
|
|
mockClock: mockTime.MockClock{
|
|
NowTime: time.Date(2023, 12, 1, 0, 0, 0, 0, time.UTC),
|
|
},
|
|
},
|
|
want: 1,
|
|
},
|
|
{
|
|
name: "TestClearAllFeeds",
|
|
args: args{
|
|
db: setupTestApp(t),
|
|
months: 1,
|
|
mockClock: mockTime.MockClock{
|
|
NowTime: time.Date(2024, 1, 1, 0, 0, 0, 0, time.UTC),
|
|
},
|
|
},
|
|
want: 0,
|
|
},
|
|
{
|
|
name: "TestClearFeedsClearBeforeRetrievedTime",
|
|
args: args{
|
|
db: setupTestApp(t),
|
|
months: 1,
|
|
mockClock: mockTime.MockClock{
|
|
NowTime: time.Date(2010, 1, 1, 0, 0, 0, 0, time.UTC),
|
|
},
|
|
},
|
|
want: 3,
|
|
},
|
|
}
|
|
for _, tt := range testCases {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
ClearFeeds(tt.args.db, tt.args.months, tt.args.mockClock)
|
|
// count all feeds in db
|
|
var feeds []*model.Feed
|
|
err := tt.args.db.DB().Select("id").From("feeds").All(&feeds)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if got := len(feeds); got != tt.want {
|
|
t.Errorf("ClearFeeds() = %v, want %v", got, tt.want)
|
|
}
|
|
})
|
|
}
|
|
}
|