Files
htwkalender-pwa/backend/service/feed/feedFunctions_test.go
2024-04-02 11:34:47 +02:00

100 lines
2.5 KiB
Go

//Calendar implementation for the HTWK Leipzig timetable. Evaluation and display of the individual dates in iCal format.
//Copyright (C) 2024 HTWKalender support@htwkalender.de
//This program is free software: you can redistribute it and/or modify
//it under the terms of the GNU Affero General Public License as published by
//the Free Software Foundation, either version 3 of the License, or
//(at your option) any later version.
//This program is distributed in the hope that it will be useful,
//but WITHOUT ANY WARRANTY; without even the implied warranty of
//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
//GNU Affero General Public License for more details.
//You should have received a copy of the GNU Affero General Public License
//along with this program. If not, see <https://www.gnu.org/licenses/>.
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)
}
})
}
}