finish availabilityjson test

This commit is contained in:
vinchent 2024-07-14 14:57:13 +02:00
parent 3f1dfeabc2
commit 4debe0e14e
2 changed files with 39 additions and 1 deletions

View File

@ -276,7 +276,18 @@ var availabilityJSONTests = []struct {
EndDate: "2050-01-02",
RoomID: "1",
}},
{"wrong date", []postData{
{"not available", []postData{
{key: "start", value: "2050-01-01"},
{key: "end", value: "2050-01-02"},
{key: "room_id", value: "2"},
}, jsonResponse{
OK: false,
Message: "",
StartDate: "2050-01-01",
EndDate: "2050-01-02",
RoomID: "2",
}},
{"wrong start date", []postData{
{key: "start", value: "2050-01"},
{key: "end", value: "2050-01-02"},
{key: "room_id", value: "1"},
@ -284,6 +295,30 @@ var availabilityJSONTests = []struct {
OK: false,
Message: "Wrong startDate",
}},
{"wrong end date", []postData{
{key: "start", value: "2050-01-01"},
{key: "end", value: "wrong"},
{key: "room_id", value: "1"},
}, jsonResponse{
OK: false,
Message: "Wrong endDate",
}},
{"wrong room id", []postData{
{key: "start", value: "2050-01-01"},
{key: "end", value: "2050-01-02"},
{key: "room_id", value: "x"},
}, jsonResponse{
OK: false,
Message: "Wrong roomID",
}},
{"not available", []postData{
{key: "start", value: "2050-01-01"},
{key: "end", value: "2050-01-02"},
{key: "room_id", value: "100"},
}, jsonResponse{
OK: false,
Message: "Error connecting to database",
}},
}
func Test_AvailabilityJSON(t *testing.T) {

View File

@ -30,6 +30,9 @@ func (m *testDBRepo) InsertRoomRestriction(r models.RoomRestriction) error {
// SearchAvailabilityByDatesByRoomID returns true if availability exists for roomID, and false if no availability
func (m *testDBRepo) SearchAvailabilityByDatesByRoomID(start, end time.Time, roomID int) (bool, error) {
if roomID == 2 {
return false, nil
}
if roomID == 100 {
return false, errors.New("deliberate error")
}
return true, nil