diff --git a/internal/handlers/handlers_test.go b/internal/handlers/handlers_test.go index 50c3e6b..1d32793 100644 --- a/internal/handlers/handlers_test.go +++ b/internal/handlers/handlers_test.go @@ -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) { diff --git a/internal/repository/dbrepo/test-repo.go b/internal/repository/dbrepo/test-repo.go index 5f495b1..45fc8ee 100644 --- a/internal/repository/dbrepo/test-repo.go +++ b/internal/repository/dbrepo/test-repo.go @@ -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