Commit 1dac2c2a authored by Enrico Bollen's avatar Enrico Bollen 💬
Browse files

Merge branch 'fix/testing' into let-us-finish-dis

parents f7074cfb c41e86a4
......@@ -157,6 +157,34 @@ func TestBuilding_FindFreeRooms(t *testing.T) {
t.Error("expected 2 rooms, got more or less ", rooms)
}
// check building opening hours - time before building
ap, _ = Appointment{}.New("02-06-2020 04:00", "2h")
rooms, err = building1.FindAvailableRooms(ap)
if err == nil {
t.Error("expected error, got: ", err)
}
// check building opening hours - time after building
ap, _ = Appointment{}.New("02-06-2020 23:00", "2h")
rooms, err = building1.FindAvailableRooms(ap)
if err == nil {
t.Error("expected error, got: ", err)
}
// check building opening hours - time longer building
ap, _ = Appointment{}.New("02-06-2020 18:00", "5h")
rooms, err = building1.FindAvailableRooms(ap)
if err == nil {
t.Error("expected error, got: ", err)
}
// check building opening hours - day
ap, _ = Appointment{}.New("07-06-2020 10:00", "2h")
rooms, err = building1.FindAvailableRooms(ap)
if err == nil {
t.Error("expected error, got: ", err)
}
}
func newBuilding() Building {
......
......@@ -27,8 +27,8 @@ func TestAppointmentService_DeleteAppointment(t *testing.T) {
t.Error(err)
}
err = AppointmentService.DeleteAppointment(0, 200, "01-06-2020 10:00")
building, err := BuildingService.GetBuilding(0)
err = AppointmentService.DeleteAppointment("0", 200, "01-06-2020 10:00")
building, err := BuildingService.GetBuilding("0")
if err != nil {
log.Fatal(err)
} else {
......@@ -42,7 +42,7 @@ func TestAppointmentService_DeleteAppointment(t *testing.T) {
}
// Test non existent building
err = AppointmentService.DeleteAppointment(1, 200, "01-06-2020 10:00")
err = AppointmentService.DeleteAppointment("1", 200, "01-06-2020 10:00")
if err == nil {
t.Error("error expected, got: ", err)
}
......@@ -59,7 +59,8 @@ func TestAppointmentService_GetAppointments(t *testing.T) {
if err != nil {
t.Error(err)
}
_, err = BuildingService.CreateRoom(0, 250, 20)
room := model.Room{Capacity: 20, Number: 200}
_, err = BuildingService.CreateRoom("0", &room)
ap3, _ := model.Appointment{}.New("01-06-2020 10:00", "2h")
ap4, _ := model.Appointment{}.New("01-06-2020 12:30", "2h")
_, err = AppointmentService.AddAppointment(ap3)
......@@ -71,7 +72,7 @@ func TestAppointmentService_GetAppointments(t *testing.T) {
t.Error("Not all appointments found, expected 2 rooms, 4 appointments, got: ", appointments)
}
if len(appointments[0][200]) != 2 {
if len(appointments[0]) != 2 {
t.Error("Too many appointments for room 200, expected 2, got: ", appointments[200])
}
}
......@@ -86,12 +87,12 @@ func TestAppointmentService_GetAppointment(t *testing.T) {
t.Error(err)
}
appointment, err := AppointmentService.GetAppointment(0, 200, "01-06-2020 10:00")
appointment, err := AppointmentService.GetAppointment("0", "01-06-2020 10:00")
if err != nil {
t.Error(err)
}
if appointment[0][200].Duration != requestedAppointment.Duration {
if appointment[0].Duration != requestedAppointment.Duration {
t.Error("Got different Appointment, requested: ", requestedAppointment, "\n got: ", appointment[200])
}
}
......
......@@ -7,7 +7,8 @@ import (
func TestBuildingService_CreateRoom(t *testing.T) {
BuildDefBuilding()
room, err := BuildingService.CreateRoom(0, 250, 50)
sampleRoom := model.Room{Capacity: 20, Number: 200}
room, err := BuildingService.CreateRoom("0", &sampleRoom)
if err != nil {
t.Error(err)
}
......@@ -20,7 +21,7 @@ func TestBuildingService_CreateRoom(t *testing.T) {
}
// produce error
_, err = BuildingService.CreateRoom(1, 200, 20)
_, err = BuildingService.CreateRoom("1", &sampleRoom)
if err == nil {
t.Error("expected error, got: ", err)
}
......@@ -31,7 +32,7 @@ func TestBuildingService_GetRoom(t *testing.T) {
BuildDefBuilding()
// try to get an actual room
room, err := BuildingService.GetRoom(0)
room, err := BuildingService.GetRoom("0")
if err != nil {
t.Error(err)
}
......@@ -42,35 +43,33 @@ func TestBuildingService_GetRoom(t *testing.T) {
room = nil
// pass wrong room id
room, err = BuildingService.GetRoom(1)
room, err = BuildingService.GetRoom("1")
if err == nil {
t.Error("error expected, got: ", err)
}
}
func TestBuildingService_GetRooms(t *testing.T) {
func TestBuildingService_GetAllRooms(t *testing.T) {
BuildDefBuilding()
roomsMap := BuildingService.GetRooms()
roomsMap := BuildingService.GetAllRooms()
if len(roomsMap) <= 0 {
t.Error("did not get any room, expected one")
}
if val, ok := roomsMap[0]; ok {
if len(val) != 1 {
t.Error("expected one room, got", len(val))
}
if roomsMap[0][0].Number != 200 {
t.Error("got wrong room, expected No. 200, got: ", roomsMap[0][0].Number)
}
if len(roomsMap) != 1 {
t.Error("expected one room, got", len(roomsMap))
}
if roomsMap[0].Number != 200 {
t.Error("got wrong room, expected No. 200, got: ", roomsMap[0].Number)
}
}
func TestBuildingService_DeleteRoom(t *testing.T) {
BuildDefBuilding()
err := BuildingService.DeleteRoom(0, 200)
err := BuildingService.DeleteRoom("0")
if err != nil {
t.Error(err)
}
building, err := BuildingService.GetBuilding(0)
building, err := BuildingService.GetBuilding("0")
if err == nil {
if len(building.Rooms) > 0 {
t.Error("too many rooms left, expected 0, got: ", len(building.Rooms))
......@@ -78,7 +77,7 @@ func TestBuildingService_DeleteRoom(t *testing.T) {
}
// produce error
err = BuildingService.DeleteRoom(1, 200)
err = BuildingService.DeleteRoom("1")
if err == nil {
t.Error("expected error, got: ", err)
}
......@@ -87,8 +86,8 @@ func TestBuildingService_DeleteRoom(t *testing.T) {
func TestBuildingService_UpdateRoomCapacity(t *testing.T) {
BuildDefBuilding()
room, err := BuildingService.UpdateRoomCapacity(0, 200, 20)
room2, err := BuildingService.GetRoom(0)
room, err := BuildingService.UpdateRoomCapacity("0", 20)
room2, err := BuildingService.GetRoom("0")
if err != nil {
t.Error(err)
}
......@@ -98,7 +97,7 @@ func TestBuildingService_UpdateRoomCapacity(t *testing.T) {
}
// produce error
room, err = BuildingService.UpdateRoomCapacity(1, 200, 20)
room, err = BuildingService.UpdateRoomCapacity("1", 20)
if err == nil {
t.Error("expected error, got: ", err)
}
......
package utils
import (
"strconv"
"strings"
"time"
)
......@@ -21,7 +22,9 @@ func FormatHour(input string) time.Time {
func FormatDateToHour(date time.Time) (formattedTime time.Time) {
const timeLayout string = "15:04"
dateString := date.String()
hourString := strconv.Itoa(date.Hour())
minuteString := strconv.Itoa(date.Minute())
dateString := hourString + ":" + minuteString
formattedTime, _ = time.Parse(timeLayout, dateString)
return formattedTime
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment