fix:#25 added tests and schedule updates

This commit is contained in:
Elmar Kresse
2024-04-22 16:11:13 +02:00
parent c8bcc3be94
commit 02a4360521
19 changed files with 731 additions and 203 deletions

View File

@@ -74,6 +74,7 @@ func GetFreeRooms(app *pocketbase.PocketBase, from time.Time, to time.Time) ([]s
return freeRooms, nil
}
// Remove all rooms from the list that have events in the given time range
func removeRoomsThatHaveEvents(rooms []string, schedule []model.Event) []string {
var freeRooms []string
for _, room := range rooms {
@@ -84,6 +85,7 @@ func removeRoomsThatHaveEvents(rooms []string, schedule []model.Event) []string
return freeRooms
}
// Check if a room is in the schedule
func isRoomInSchedule(room string, schedule []model.Event) bool {
for _, event := range schedule {
if event.Course != "Sport" {

View File

@@ -191,6 +191,50 @@ func Test_isRoomInSchedule(t *testing.T) {
},
want: false,
},
{
name: "schedule event.Course is sport",
args: args{
room: "Klettergerüst",
schedule: []model.Event{
{
UUID: "903784265784639527",
Day: "Montag",
Week: "52",
Start: types.DateTime{},
End: types.DateTime{},
Name: "Hampelmann",
EventType: "S",
Prof: "Prof. Dr. Bewegung",
Rooms: "Klettergerüst",
Notes: "A apple a day keeps the doctor away",
Course: "Sport",
},
},
},
want: true,
},
{
name: "schedule event.Course is sport with different room",
args: args{
room: "HTWK Sportplatz",
schedule: []model.Event{
{
UUID: "903784265784639527",
Day: "Montag",
Week: "52",
Start: types.DateTime{},
End: types.DateTime{},
Name: "Hampelmann",
EventType: "S",
Prof: "Prof. Dr. Bewegung",
Rooms: "Klettergerüst",
Notes: "A apple a day keeps the doctor away",
Course: "Sport",
},
},
},
want: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {