feat:#5 added free rooms api endpoint

This commit is contained in:
Elmar Kresse
2024-01-24 02:07:30 +01:00
parent 2430913a51
commit 4c16605bd6
8 changed files with 295 additions and 7 deletions

View File

@@ -1,11 +1,10 @@
package room
import (
"github.com/pocketbase/pocketbase/tools/types"
"htwkalender/model"
"reflect"
"testing"
"github.com/pocketbase/pocketbase/tools/types"
)
func Test_anonymizeRooms(t *testing.T) {
@@ -123,3 +122,170 @@ func Test_anonymizeRooms(t *testing.T) {
})
}
}
func Test_isRoomInSchedule(t *testing.T) {
type args struct {
room string
schedule []model.Event
}
tests := []struct {
name string
args args
want bool
}{
{
name: "room is in schedule",
args: args{
room: "Room",
schedule: []model.Event{
{
UUID: "testUUID",
Day: "Montag",
Week: "52",
Start: types.DateTime{},
End: types.DateTime{},
Name: "Secret",
EventType: "V",
Prof: "Prof. Dr. Secret",
Rooms: "Room",
Notes: "Secret",
},
},
},
want: true,
},
{
name: "room is not in schedule",
args: args{
room: "Z324",
schedule: []model.Event{
{
UUID: "testUUID",
Day: "Montag",
Week: "52",
Start: types.DateTime{},
End: types.DateTime{},
Name: "Secret",
EventType: "V",
Prof: "Prof. Dr. Bond",
Rooms: "LI007",
Notes: "Keine Zeit für die Uni",
},
},
},
want: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := isRoomInSchedule(tt.args.room, tt.args.schedule); got != tt.want {
t.Errorf("isRoomInSchedule() = %v, want %v", got, tt.want)
}
})
}
}
func Test_getFreeRooms(t *testing.T) {
type args struct {
rooms []string
schedule []model.Event
}
tests := []struct {
name string
args args
want []string
}{
{
name: "remove room1 from list",
args: args{
rooms: []string{
"Room1",
"Room2",
"Room3",
},
schedule: []model.Event{
{
UUID: "testUUID",
Day: "Montag",
Week: "52",
Start: types.DateTime{},
End: types.DateTime{},
Name: "Secret",
EventType: "V",
Prof: "Prof. Dr. Secret",
Rooms: "Room1",
Notes: "Secret",
},
},
},
want: []string{
"Room2",
"Room3",
},
},
{
name: "remove room2 from list",
args: args{
rooms: []string{
"Room1",
"Room2",
"Room3",
},
schedule: []model.Event{
{
UUID: "testUUID",
Day: "Montag",
Week: "52",
Start: types.DateTime{},
End: types.DateTime{},
Name: "Secret",
EventType: "V",
Prof: "Prof. Dr. Secret",
Rooms: "Room3",
Notes: "Secret",
},
},
},
want: []string{
"Room1",
"Room2",
},
},
{
name: "remove no room from list",
args: args{
rooms: []string{
"Room1",
"Room2",
"Room3",
},
schedule: []model.Event{
{
UUID: "testUUID",
Day: "Montag",
Week: "52",
Start: types.DateTime{},
End: types.DateTime{},
Name: "Secret",
EventType: "V",
Prof: "Prof. Dr. Secret",
Rooms: "Room4",
Notes: "Secret",
},
},
},
want: []string{
"Room1",
"Room2",
"Room3",
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := removeRoomsThatHaveEvents(tt.args.rooms, tt.args.schedule); !reflect.DeepEqual(got, tt.want) {
t.Errorf("removeRoomsThatHaveEvents() = %v, want %v", got, tt.want)
}
})
}
}