mirror of
https://gitlab.dit.htwk-leipzig.de/htwk-software/htwkalender.git
synced 2025-07-16 17:48:49 +02:00
201 lines
5.3 KiB
Go
201 lines
5.3 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/data-manager/model"
|
|
mockTime "htwkalender/data-manager/service/functions/time"
|
|
"reflect"
|
|
"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)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestCombineEventsInFeed(t *testing.T) {
|
|
type args struct {
|
|
events model.Events
|
|
}
|
|
testCases := []struct {
|
|
name string
|
|
args args
|
|
want model.Events
|
|
}{
|
|
{
|
|
name: "TestCombineEventsInFeed",
|
|
args: args{
|
|
events: model.Events{
|
|
{
|
|
Name: "Modellierung",
|
|
Start: mockTime.ParseAsTypesDatetime(time.Date(2023, 12, 1, 0, 0, 0, 0, time.UTC)),
|
|
End: mockTime.ParseAsTypesDatetime(time.Date(2023, 12, 1, 4, 0, 0, 0, time.UTC)),
|
|
Prof: "Prof. Bunt",
|
|
Rooms: "LI001",
|
|
Notes: "Gruppe 2",
|
|
},
|
|
{
|
|
Name: "Modellierung",
|
|
Start: mockTime.ParseAsTypesDatetime(time.Date(2023, 12, 1, 0, 0, 0, 0, time.UTC)),
|
|
End: mockTime.ParseAsTypesDatetime(time.Date(2023, 12, 1, 4, 0, 0, 0, time.UTC)),
|
|
Prof: "Prof. Bunt",
|
|
Rooms: "LI002",
|
|
Notes: "Gruppe 1",
|
|
},
|
|
},
|
|
},
|
|
want: model.Events{
|
|
{
|
|
Name: "Modellierung",
|
|
Start: mockTime.ParseAsTypesDatetime(time.Date(2023, 12, 1, 0, 0, 0, 0, time.UTC)),
|
|
End: mockTime.ParseAsTypesDatetime(time.Date(2023, 12, 1, 4, 0, 0, 0, time.UTC)),
|
|
Prof: "Prof. Bunt",
|
|
Rooms: "LI001, LI002",
|
|
Notes: "LI001 - Gruppe 2 (Prof. Bunt)\nLI002 - Gruppe 1 (Prof. Bunt)",
|
|
},
|
|
},
|
|
},
|
|
{
|
|
name: "CannotCombineEventsInFeed",
|
|
args: args{
|
|
events: model.Events{
|
|
{
|
|
Name: "Modellierung",
|
|
Start: mockTime.ParseAsTypesDatetime(time.Date(2023, 12, 1, 0, 0, 0, 0, time.UTC)),
|
|
End: mockTime.ParseAsTypesDatetime(time.Date(2023, 12, 1, 4, 0, 0, 0, time.UTC)),
|
|
Prof: "Prof. Bunt",
|
|
Rooms: "LI001",
|
|
Notes: "Gruppe 2",
|
|
},
|
|
{
|
|
Name: "Modellierung - 2",
|
|
Start: mockTime.ParseAsTypesDatetime(time.Date(2023, 12, 1, 0, 0, 0, 0, time.UTC)),
|
|
End: mockTime.ParseAsTypesDatetime(time.Date(2023, 12, 1, 4, 0, 0, 0, time.UTC)),
|
|
Prof: "Prof. Bunt",
|
|
Rooms: "LI002",
|
|
Notes: "Gruppe 1",
|
|
},
|
|
},
|
|
},
|
|
want: model.Events{
|
|
{
|
|
Name: "Modellierung",
|
|
Start: mockTime.ParseAsTypesDatetime(time.Date(2023, 12, 1, 0, 0, 0, 0, time.UTC)),
|
|
End: mockTime.ParseAsTypesDatetime(time.Date(2023, 12, 1, 4, 0, 0, 0, time.UTC)),
|
|
Prof: "Prof. Bunt",
|
|
Rooms: "LI001",
|
|
Notes: "Gruppe 2",
|
|
},
|
|
{
|
|
Name: "Modellierung - 2",
|
|
Start: mockTime.ParseAsTypesDatetime(time.Date(2023, 12, 1, 0, 0, 0, 0, time.UTC)),
|
|
End: mockTime.ParseAsTypesDatetime(time.Date(2023, 12, 1, 4, 0, 0, 0, time.UTC)),
|
|
Prof: "Prof. Bunt",
|
|
Rooms: "LI002",
|
|
Notes: "Gruppe 1",
|
|
},
|
|
},
|
|
},
|
|
{
|
|
name: "NoEventsInFeed",
|
|
args: args{
|
|
events: model.Events{},
|
|
},
|
|
want: model.Events{},
|
|
},
|
|
}
|
|
for _, tt := range testCases {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
if got := CombineEventsInFeed(tt.args.events); !reflect.DeepEqual(got, tt.want) {
|
|
t.Errorf("CombineEventsInFeed() = %v, want %v", got, tt.want)
|
|
}
|
|
})
|
|
}
|
|
}
|