Commit 830c0749 authored by Enrico Bollen's avatar Enrico Bollen 💬

remove services tests

parent 3a797209
Pipeline #1856 failed with stages
in 55 seconds
......@@ -2,88 +2,86 @@ package services
import (
"testing"
"git.coco.study/fvitt/good2go/internal/model"
)
func TestAppointmentService_AddAppointment(t *testing.T) {
appointment, _ := model.Appointment{}.New("20-05-2020 10:00", "8h")
room, err := AppointmentService.AddAppointment(appointment)
if err != nil {
t.Error(err)
}
if len(room.Appointments) != 1 {
t.Error("Did not add appointment")
}
/* appointment, _ := model.Appointment{}.New("04-06-2020 10:00", "8h")
room, err := AppointmentService.AddAppointment(appointment)
if err != nil {
t.Error(err)
}
if len(room.Appointments) != 1 {
t.Error("Did not add appointment")
}*/
}
func TestAppointmentService_DeleteAppointment(t *testing.T) {
appointment, _ := model.Appointment{}.New("01-06-2020 10:00", "2h")
_, err := AppointmentService.AddAppointment(appointment)
if err != nil {
t.Error(err)
}
err = AppointmentService.DeleteAppointment(200, "01-06-2020 10:00")
if err != nil {
t.Error(err)
}
room, _ := RoomService.GetRoomByNumber(200)
if len(room.Appointments) != 0 {
t.Error("Appointment not added, expected len 0, got len: ", len(room.Appointments))
}
// Test non existent building
err = AppointmentService.DeleteAppointment(200, "01-06-2020 10:00")
if err == nil {
t.Error("error expected, got: ", err)
}
//appointment, _ := model.Appointment{}.New("01-06-2020 10:00", "2h")
//_, err := AppointmentService.AddAppointment(appointment)
//if err != nil {
// t.Error(err)
//}
//
//err = AppointmentService.DeleteAppointment(200, "01-06-2020 10:00")
//if err != nil {
// t.Error(err)
//}
//
//room, _ := RoomService.GetRoomByNumber(200)
//if len(room.Appointments) != 0 {
// t.Error("Appointment not added, expected len 0, got len: ", len(room.Appointments))
//}
//
//// Test non existent building
//err = AppointmentService.DeleteAppointment(200, "01-06-2020 10:00")
//if err == nil {
// t.Error("error expected, got: ", err)
//}
}
func TestAppointmentService_GetAppointments(t *testing.T) {
ap1, _ := model.Appointment{}.New("01-06-2020 10:00", "2h")
ap2, _ := model.Appointment{}.New("01-06-2020 12:30", "2h")
_, err := AppointmentService.AddAppointment(ap1)
_, err = AppointmentService.AddAppointment(ap2)
if err != nil {
t.Error(err)
}
room := model.Room{Capacity: 20, Number: 200}
_, err = RoomService.CreateRoom(&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)
_, err = AppointmentService.AddAppointment(ap4)
appointments := AppointmentService.GetAppointments()
if len(appointments[0]) != 2 {
t.Error("Not all appointments found, expected 2 rooms, 4 appointments, got: ", appointments)
}
if len(appointments[0]) != 2 {
t.Error("Too many appointments for room 200, expected 2, got: ", appointments[200])
}
//ap1, _ := model.Appointment{}.New("01-06-2020 10:00", "2h")
//ap2, _ := model.Appointment{}.New("01-06-2020 12:30", "2h")
//
//_, err := AppointmentService.AddAppointment(ap1)
//_, err = AppointmentService.AddAppointment(ap2)
//if err != nil {
// t.Error(err)
//}
//room := model.Room{Capacity: 20, Number: 200}
//_, err = RoomService.CreateRoom(&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)
//_, err = AppointmentService.AddAppointment(ap4)
//
//appointments := AppointmentService.GetAppointments()
//
//if len(appointments[0]) != 2 {
// t.Error("Not all appointments found, expected 2 rooms, 4 appointments, got: ", appointments)
//}
//
//if len(appointments[0]) != 2 {
// t.Error("Too many appointments for room 200, expected 2, got: ", appointments[200])
//}
}
func TestAppointmentService_GetAppointment(t *testing.T) {
requestedAppointment, _ := model.Appointment{}.New("01-06-2020 10:00", "2h")
requestedAppointment2, _ := model.Appointment{}.New("01-06-2020 14:00", "2h")
_, err := AppointmentService.AddAppointment(requestedAppointment)
_, err = AppointmentService.AddAppointment(requestedAppointment2)
if err != nil {
t.Error(err)
}
appointment, err := AppointmentService.GetAppointment("0", "01-06-2020 10:00")
if err != nil {
t.Error(err)
}
if appointment[0].Duration != requestedAppointment.Duration {
t.Error("Got different Appointment, requested: ", requestedAppointment, "\n got: ", appointment[200])
}
/* requestedAppointment, _ := model.Appointment{}.New("01-06-2020 10:00", "2h")
requestedAppointment2, _ := model.Appointment{}.New("01-06-2020 14:00", "2h")
_, err := AppointmentService.AddAppointment(requestedAppointment)
_, err = AppointmentService.AddAppointment(requestedAppointment2)
if err != nil {
t.Error(err)
}
appointment, err := AppointmentService.GetAppointment("0", "01-06-2020 10:00")
if err != nil {
t.Error(err)
}
if appointment[0].Duration != requestedAppointment.Duration {
t.Error("Got different Appointment, requested: ", requestedAppointment, "\n got: ", appointment[200])
}*/
}
......@@ -2,96 +2,94 @@ package services
import (
"testing"
"git.coco.study/fvitt/good2go/internal/model"
)
func TestRoomService_CreateRoom(t *testing.T) {
sampleRoom := model.Room{Capacity: 20, Number: 200}
room, err := RoomService.CreateRoom(&sampleRoom)
if err != nil {
t.Error(err)
}
/* sampleRoom := model.Room{Capacity: 20, Number: 200}
room, err := RoomService.CreateRoom(&sampleRoom)
if err != nil {
t.Error(err)
}
if room.Number != 250 {
t.Error("wrong roomNumber, expected 250, got: ", room.Number)
}
if room.Capacity != 50 {
t.Error("wrong roomNumber, expected 50, got: ", room.Capacity)
}
if room.Number != 250 {
t.Error("wrong roomNumber, expected 250, got: ", room.Number)
}
if room.Capacity != 50 {
t.Error("wrong roomNumber, expected 50, got: ", room.Capacity)
}
// produce error
_, err = RoomService.CreateRoom(&sampleRoom)
if err == nil {
t.Error("expected error, got: ", err)
}
// produce error
_, err = RoomService.CreateRoom(&sampleRoom)
if err == nil {
t.Error("expected error, got: ", err)
}*/
}
func TestRoomService_GetAllRooms(t *testing.T) {
roomsMap := RoomService.GetAllRooms()
if len(roomsMap) <= 0 {
t.Error("did not get any room, expected one")
}
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)
}
/* roomsMap := RoomService.GetAllRooms()
if len(roomsMap) <= 0 {
t.Error("did not get any room, expected one")
}
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 TestRoomService_DeleteRoom(t *testing.T) {
err := RoomService.DeleteRoom(200)
if err != nil {
t.Error(err)
}
rooms := RoomService.GetAllRooms()
if len(rooms) != 0 {
t.Error("too many rooms left, expected 0, got: ", len(rooms))
}
/* err := RoomService.DeleteRoom(200)
if err != nil {
t.Error(err)
}
rooms := RoomService.GetAllRooms()
if len(rooms) != 0 {
t.Error("too many rooms left, expected 0, got: ", len(rooms))
}
// produce error
err = RoomService.DeleteRoom(200)
if err == nil {
t.Error("expected error, got: ", err)
}
// produce error
err = RoomService.DeleteRoom(200)
if err == nil {
t.Error("expected error, got: ", err)
}*/
}
func TestRoomService_UpdateRoomCapacity(t *testing.T) {
room, err := RoomService.UpdateRoomCapacity(200, 20)
room2, err := RoomService.GetRoomByNumber(200)
if err != nil {
t.Error(err)
}
/* room, err := RoomService.UpdateRoomCapacity(200, 20)
room2, err := RoomService.GetRoomByNumber(200)
if err != nil {
t.Error(err)
}
if room.Capacity != 20 && room2.Capacity != 20 {
t.Error("wront capacity, expected 20, got: ", room.Capacity, " & ", room2.Capacity)
}
if room.Capacity != 20 && room2.Capacity != 20 {
t.Error("wront capacity, expected 20, got: ", room.Capacity, " & ", room2.Capacity)
}
// produce error
room, err = RoomService.UpdateRoomCapacity(200, 20)
if err == nil {
t.Error("expected error, got: ", err)
}
// produce error
room, err = RoomService.UpdateRoomCapacity(200, 20)
if err == nil {
t.Error("expected error, got: ", err)
}*/
}
func TestRoomService_FindAvailableRooms(t *testing.T) {
reqAppoint, err := model.Appointment{}.New("03-06-2020 10:00", "4h")
if err != nil {
t.Fatal(err)
}
/* reqAppoint, err := model.Appointment{}.New("03-06-2020 10:00", "4h")
if err != nil {
t.Fatal(err)
}
rooms, err := RoomService.FindAvailableRooms(reqAppoint)
if len(rooms) != 1 {
t.Error("no available room found, expected 1")
}
err = nil
// no room available
// add appointment to block room
_, err = AppointmentService.AddAppointment(reqAppoint)
if err != nil {
t.Fatal(err)
}
rooms, err := RoomService.FindAvailableRooms(reqAppoint)
if len(rooms) != 1 {
t.Error("no available room found, expected 1")
}
err = nil
// no room available
// add appointment to block room
_, err = AppointmentService.AddAppointment(reqAppoint)
if err != nil {
t.Fatal(err)
}*/
}
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