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
031bb548
Commit
031bb548
authored
Jun 04, 2020
by
Enrico Bollen
💬
Browse files
adjust tests to new functions
parent
80b57dce
Pipeline
#1850
failed with stages
in 54 seconds
Changes
4
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
database/mongo/repositories/room_repository_test.go
View file @
031bb548
...
...
@@ -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 @
031bb548
...
...
@@ -26,9 +26,9 @@ func (a *appointmentService) AddAppointment(reqAppoint model.Appointment) (room
// DeleteAppointment deletes an appointment on higher level.
// Takes room number and start date, finds room and deletes appointment.
func
(
a
*
appointmentService
)
DeleteAppointment
(
room
ID
str
in
g
,
startDate
string
)
(
err
error
)
{
func
(
a
*
appointmentService
)
DeleteAppointment
(
room
No
in
t
,
startDate
string
)
(
err
error
)
{
room
,
err
:=
r
.
RoomRepo
.
GetRoomBy
ID
(
room
ID
)
room
,
err
:=
r
.
RoomRepo
.
GetRoomBy
Number
(
room
No
)
if
err
!=
nil
{
return
err
}
...
...
internal/services/appointment_service_test.go
View file @
031bb548
package
services
import
(
"log"
"testing"
"git.coco.study/fvitt/good2go/internal/model"
)
func
TestAppointmentService_AddAppointment
(
t
*
testing
.
T
)
{
BuildDefBuilding
()
appointment
,
_
:=
model
.
Appointment
{}
.
New
(
"20-05-2020 10:00"
,
"8h"
)
room
,
err
:=
AppointmentService
.
AddAppointment
(
appointment
)
if
err
!=
nil
{
...
...
@@ -20,36 +18,30 @@ func TestAppointmentService_AddAppointment(t *testing.T) {
}
func
TestAppointmentService_DeleteAppointment
(
t
*
testing
.
T
)
{
BuildDefBuilding
()
appointment
,
_
:=
model
.
Appointment
{}
.
New
(
"01-06-2020 10:00"
,
"2h"
)
_
,
err
:=
AppointmentService
.
AddAppointment
(
appointment
)
if
err
!=
nil
{
t
.
Error
(
err
)
}
err
=
AppointmentService
.
DeleteAppointment
(
"0"
,
200
,
"01-06-2020 10:00"
)
building
,
err
:=
BuildingService
.
GetBuilding
(
"0"
)
err
=
AppointmentService
.
DeleteAppointment
(
200
,
"01-06-2020 10:00"
)
if
err
!=
nil
{
log
.
Fatal
(
err
)
}
else
{
for
_
,
room
:=
range
building
.
Rooms
{
if
room
.
Number
==
200
{
if
len
(
room
.
Appointments
)
!=
0
{
t
.
Error
(
"Appointment not added, expected len 0, got len: "
,
len
(
room
.
Appointments
))
}
}
}
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
(
"1"
,
200
,
"01-06-2020 10:00"
)
err
=
AppointmentService
.
DeleteAppointment
(
200
,
"01-06-2020 10:00"
)
if
err
==
nil
{
t
.
Error
(
"error expected, got: "
,
err
)
}
}
func
TestAppointmentService_GetAppointments
(
t
*
testing
.
T
)
{
BuildDefBuilding
()
ap1
,
_
:=
model
.
Appointment
{}
.
New
(
"01-06-2020 10:00"
,
"2h"
)
ap2
,
_
:=
model
.
Appointment
{}
.
New
(
"01-06-2020 12:30"
,
"2h"
)
...
...
@@ -60,7 +52,7 @@ func TestAppointmentService_GetAppointments(t *testing.T) {
t
.
Error
(
err
)
}
room
:=
model
.
Room
{
Capacity
:
20
,
Number
:
200
}
_
,
err
=
Building
Service
.
CreateRoom
(
"0"
,
&
room
)
_
,
err
=
Room
Service
.
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
)
...
...
@@ -78,7 +70,6 @@ func TestAppointmentService_GetAppointments(t *testing.T) {
}
func
TestAppointmentService_GetAppointment
(
t
*
testing
.
T
)
{
BuildDefBuilding
()
requestedAppointment
,
_
:=
model
.
Appointment
{}
.
New
(
"01-06-2020 10:00"
,
"2h"
)
requestedAppointment2
,
_
:=
model
.
Appointment
{}
.
New
(
"01-06-2020 14:00"
,
"2h"
)
_
,
err
:=
AppointmentService
.
AddAppointment
(
requestedAppointment
)
...
...
@@ -96,29 +87,3 @@ func TestAppointmentService_GetAppointment(t *testing.T) {
t
.
Error
(
"Got different Appointment, requested: "
,
requestedAppointment
,
"
\n
got: "
,
appointment
[
200
])
}
}
// Resets building
func
ResetBuildingManager
()
{
BuildingService
.
New
()
building
:=
&
model
.
Building
{}
building
=
building
.
New
(
"08:00"
,
"10h"
,
[]
string
{
"mon"
})
BuildingService
.
CreateBuilding
(
building
)
}
// Resets building(0) and adds room 200 with capacity 40
func
BuildDefBuilding
()
{
ResetBuildingManager
()
buildings
,
_
:=
BuildingService
.
GetAllBuildings
()
_
,
err
:=
BuildingService
.
CreateRoom
(
buildings
[
0
]
.
ID
.
String
(),
&
model
.
Room
{
Number
:
200
,
Capacity
:
40
,
})
if
err
!=
nil
{
log
.
Fatal
(
"BuildDefBuilding: "
,
err
)
}
}
internal/services/room_service_test.go
View file @
031bb548
...
...
@@ -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
=
Building
Service
.
DeleteRoom
(
"1"
)
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"
)
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
=
Building
Service
.
UpdateRoomCapacity
(
"1"
,
20
)
room
,
err
=
Room
Service
.
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
:=
Building
Service
.
FindAvailableRooms
(
reqAppoint
)
rooms
,
err
:=
Room
Service
.
FindAvailableRooms
(
reqAppoint
)
if
len
(
rooms
)
!=
1
{
t
.
Error
(
"no available room found, expected 1"
)
}
...
...
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