Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Fabian Vitt
good2go
Commits
68c11d6e
Commit
68c11d6e
authored
Jun 04, 2020
by
Enrico Bollen
💬
Browse files
Dev
parent
94bfe152
Changes
5
Hide whitespace changes
Inline
Side-by-side
api/rest/main.go
View file @
68c11d6e
...
...
@@ -31,7 +31,6 @@ func Init() {
r
.
Use
(
m
.
SentryHandler
)
// Register all the Routers
h
.
AppointmentRouter
.
AttachRouter
(
r
)
h
.
RoomRouter
.
AttachRouter
(
r
)
h
.
HomeRouter
.
AttachRouter
(
r
)
...
...
database/mongo/repositories/room_repository_test.go
View file @
68c11d6e
...
...
@@ -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
.
GetRoomBy
ID
(
100
)
room
,
err
:=
repo
.
GetRoomBy
Number
(
100
)
if
err
!=
nil
{
t
.
Error
(
err
)
}
...
...
@@ -43,7 +42,7 @@ func Test_roomRepository_UpdateRoom(t *testing.T) {
Capacity
:
22
,
})
room
,
err
:=
repo
.
GetRoomBy
ID
(
100
)
room
,
err
:=
repo
.
GetRoomBy
Number
(
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
()
...
...
internal/services/appointment_service.go
View file @
68c11d6e
...
...
@@ -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
(
roomN
umber
int
,
startDate
string
)
(
err
error
)
{
func
(
a
*
appointmentService
)
DeleteAppointment
(
roomN
o
int
,
startDate
string
)
(
err
error
)
{
room
,
err
:=
r
.
RoomRepo
.
GetRoomByNumber
(
roomN
umber
)
room
,
err
:=
r
.
RoomRepo
.
GetRoomByNumber
(
roomN
o
)
if
err
!=
nil
{
return
err
}
room
.
DeleteAppointment
(
startDate
)
r
.
RoomRepo
.
UpdateRoom
(
room
)
return
}
...
...
internal/services/appointment_service_test.go
View file @
68c11d6e
...
...
@@ -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
(
"
2
0-0
5
-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("0
4
-0
6
-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])
}
*/
}
internal/services/room_service_test.go
View file @
68c11d6e
...
...
@@ -2,124 +2,94 @@ package services
import
(
"testing"
"git.coco.study/fvitt/good2go/internal/model"
)
func
TestBuildingService_CreateRoom
(
t
*
testing
.
T
)
{
BuildDefBuilding
()
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
)
}
// produce error
_
,
err
=
RoomService
.
CreateRoom
(
&
sampleRoom
)
if
err
==
nil
{
t
.
Error
(
"expected error, got: "
,
err
)
}
}
func
TestRoomService_CreateRoom
(
t
*
testing
.
T
)
{
/* sampleRoom := model.Room{Capacity: 20, Number: 200}
room, err := RoomService.CreateRoom(&sampleRoom)
if err != nil {
t.Error(err)
}
func
TestBuildingService_GetRoom
(
t
*
testing
.
T
)
{
BuildDefBuilding
()
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)
}
// 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
// produce error
_, err = RoomService.CreateRoom(&sampleRoom)
if err == nil {
t.Error("expected error, got: ", err)
}*/
// 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
()
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_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)
}*/
}
func
TestBuildingService_DeleteRoom
(
t
*
testing
.
T
)
{
BuildDefBuilding
()
err
:=
BuildingService
.
DeleteRoom
(
"0"
)
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
))
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))
}
}
// produce error
err
=
Building
Service
.
DeleteRoom
(
"1"
)
if
err
==
nil
{
t
.
Error
(
"expected error, got: "
,
err
)
}
// produce error
err =
Room
Service.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"
)
if
err
!=
nil
{
t
.
Error
(
err
)
}
func
TestRoomService_UpdateRoomCapacity
(
t
*
testing
.
T
)
{
/* 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
=
Building
Service
.
UpdateRoomCapacity
(
"1"
,
20
)
if
err
==
nil
{
t
.
Error
(
"expected error, got: "
,
err
)
}
// produce error
room, err =
Room
Service.UpdateRoomCapacity(
200
, 20)
if err == nil {
t.Error("expected error, got: ", err)
}
*/
}
func
TestBuildingService_FindAvailableRooms
(
t
*
testing
.
T
)
{
BuildDefBuilding
()
reqAppoint
,
err
:=
model
.
Appointment
{}
.
New
(
"03-06-2020 10:00"
,
"4h"
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
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
:=
Building
Service
.
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 :=
Room
Service.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)
}
*/
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment