Commit 3a797209 authored by Enrico Bollen's avatar Enrico Bollen 💬
Browse files

Merge branch 'testing' into dev

# Conflicts:
#	internal/services/appointment_service.go
parents ecb358bc 031bb548
Pipeline #1855 failed with stages
in 56 seconds
......@@ -5,7 +5,6 @@ import (
"testing"
"git.coco.study/fvitt/good2go/internal/model"
"go.mongodb.org/mongo-driver/bson"
"go.mongodb.org/mongo-driver/mongo"
)
......@@ -25,7 +24,7 @@ func Test_roomRepository_CreateRoom(t *testing.T) {
fmt.Println(err)
}
room, err := repo.GetRoomByID(100)
room, err := repo.GetRoomByNumber(100)
if err != nil {
t.Error(err)
}
......@@ -43,7 +42,7 @@ func Test_roomRepository_UpdateRoom(t *testing.T) {
Capacity: 22,
})
room, err := repo.GetRoomByID(100)
room, err := repo.GetRoomByNumber(100)
if err != nil {
t.Error(err)
}
......@@ -54,23 +53,6 @@ func Test_roomRepository_UpdateRoom(t *testing.T) {
}
func Test_roomRepository_GetRoom(t *testing.T) {
_, err := repo.CreateRoom(&model.Room{Number: 420, Capacity: 22})
if err != nil {
fmt.Println(err)
panic(err)
}
_, err = repo.GetRoom(bson.M{
"number": 420,
})
if err != nil {
t.Error(err)
}
}
func Test_roomRepository_GetAllRooms(t *testing.T) {
rooms := repo.GetAllRooms()
......
......@@ -21,25 +21,20 @@ func (a *appointmentService) AddAppointment(reqAppoint model.Appointment) (room
selectedRooms[0].AddAppointment(reqAppoint)
room = selectedRooms[0]
}
r.RoomRepo.UpdateRoom(room)
return room, err
}
// DeleteAppointment deletes an appointment on higher level.
// Takes room number and start date, finds room and deletes appointment.
func (a *appointmentService) DeleteAppointment(roomNumber int, startDate string) (err error) {
func (a *appointmentService) DeleteAppointment(roomNo int, startDate string) (err error) {
room, err := r.RoomRepo.GetRoomByNumber(roomNumber)
room, err := r.RoomRepo.GetRoomByNumber(roomNo)
if err != nil {
return err
}
room.DeleteAppointment(startDate)
r.RoomRepo.UpdateRoom(room)
return
}
......
......@@ -6,8 +6,7 @@ import (
"git.coco.study/fvitt/good2go/internal/model"
)
func TestBuildingService_CreateRoom(t *testing.T) {
BuildDefBuilding()
func TestRoomService_CreateRoom(t *testing.T) {
sampleRoom := model.Room{Capacity: 20, Number: 200}
room, err := RoomService.CreateRoom(&sampleRoom)
if err != nil {
......@@ -29,30 +28,8 @@ func TestBuildingService_CreateRoom(t *testing.T) {
}
func TestBuildingService_GetRoom(t *testing.T) {
BuildDefBuilding()
// try to get an actual room
room, err := RoomService.GetAllRooms()[0]
if err != nil {
t.Error(err)
}
if room.Number != 200 {
t.Error("got wrong room, expected 200, got: ", room.Number)
}
err = nil
room = nil
// pass wrong room id
room, err = BuildingService.GetRoom("1")
if err == nil {
t.Error("error expected, got: ", err)
}
}
func TestBuildingService_GetAllRooms(t *testing.T) {
BuildDefBuilding()
roomsMap, _ := BuildingService.GetAllRooms()
func TestRoomService_GetAllRooms(t *testing.T) {
roomsMap := RoomService.GetAllRooms()
if len(roomsMap) <= 0 {
t.Error("did not get any room, expected one")
}
......@@ -64,31 +41,27 @@ func TestBuildingService_GetAllRooms(t *testing.T) {
}
}
func TestBuildingService_DeleteRoom(t *testing.T) {
BuildDefBuilding()
err := BuildingService.DeleteRoom("0")
func TestRoomService_DeleteRoom(t *testing.T) {
err := RoomService.DeleteRoom(200)
if err != nil {
t.Error(err)
}
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))
}
rooms := RoomService.GetAllRooms()
if len(rooms) != 0 {
t.Error("too many rooms left, expected 0, got: ", len(rooms))
}
// produce error
err = BuildingService.DeleteRoom("1")
err = RoomService.DeleteRoom(200)
if err == nil {
t.Error("expected error, got: ", err)
}
}
func TestBuildingService_UpdateRoomCapacity(t *testing.T) {
BuildDefBuilding()
room, err := BuildingService.UpdateRoomCapacity("0", 20)
room2, err := BuildingService.GetRoom("0")
func TestRoomService_UpdateRoomCapacity(t *testing.T) {
room, err := RoomService.UpdateRoomCapacity(200, 20)
room2, err := RoomService.GetRoomByNumber(200)
if err != nil {
t.Error(err)
}
......@@ -98,20 +71,19 @@ func TestBuildingService_UpdateRoomCapacity(t *testing.T) {
}
// produce error
room, err = BuildingService.UpdateRoomCapacity("1", 20)
room, err = RoomService.UpdateRoomCapacity(200, 20)
if err == nil {
t.Error("expected error, got: ", err)
}
}
func TestBuildingService_FindAvailableRooms(t *testing.T) {
BuildDefBuilding()
func TestRoomService_FindAvailableRooms(t *testing.T) {
reqAppoint, err := model.Appointment{}.New("03-06-2020 10:00", "4h")
if err != nil {
t.Fatal(err)
}
rooms, err := BuildingService.FindAvailableRooms(reqAppoint)
rooms, err := RoomService.FindAvailableRooms(reqAppoint)
if len(rooms) != 1 {
t.Error("no available room found, expected 1")
}
......
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