Skip to content

Commit

Permalink
Check for slot status before confirming or rejecting a booking request (
Browse files Browse the repository at this point in the history
#798)

* 🔨 Check for slot status before confirming or rejecting a booking request

* 🔨 Extend tests

* 🔨 Remove useless code
  • Loading branch information
devmount authored Dec 20, 2024
1 parent 266d24b commit 7611333
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
1 change: 1 addition & 0 deletions backend/src/appointment/routes/schedule.py
Original file line number Diff line number Diff line change
Expand Up @@ -467,6 +467,7 @@ def decide_on_schedule_availability_slot(
not slot
or not repo.schedule.has_slot(db, schedule.id, slot.id)
or slot.booking_tkn != data.slot_token
or slot.booking_status != BookingStatus.requested
):
raise validation.SlotNotFoundException()

Expand Down
24 changes: 24 additions & 0 deletions backend/test/integration/test_schedule.py
Original file line number Diff line number Diff line change
Expand Up @@ -698,6 +698,7 @@ def test_fail_not_utc(self, with_client, mock_connector, setup_schedule):
headers=auth_headers,
)
assert response.status_code == 404, response.text

data = response.json()

assert data.get('detail', {}).get('id') == 'SLOT_NOT_FOUND'
Expand Down Expand Up @@ -726,6 +727,7 @@ def test_fail_slot_duration_mismatch(self, with_client, mock_connector, setup_sc
headers=auth_headers,
)
assert response.status_code == 404, response.text

data = response.json()

assert data.get('detail', {}).get('id') == 'SLOT_NOT_FOUND'
Expand Down Expand Up @@ -755,6 +757,7 @@ def test_fail_on_invalid_weekday(self, with_client, mock_connector, setup_schedu
headers=auth_headers,
)
assert response.status_code == 404, response.text

data = response.json()

assert data.get('detail', {}).get('id') == 'SLOT_NOT_FOUND'
Expand Down Expand Up @@ -783,6 +786,7 @@ def test_fail_on_before_time_range(self, with_client, mock_connector, setup_sche
headers=auth_headers,
)
assert response.status_code == 404, response.text

data = response.json()

assert data.get('detail', {}).get('id') == 'SLOT_NOT_FOUND'
Expand Down Expand Up @@ -811,6 +815,7 @@ def test_fail_on_after_time_range(self, with_client, mock_connector, setup_sched
headers=auth_headers,
)
assert response.status_code == 404, response.text

data = response.json()

assert data.get('detail', {}).get('id') == 'SLOT_NOT_FOUND'
Expand Down Expand Up @@ -893,6 +898,16 @@ def test_confirm(
assert slot.booking_status == models.BookingStatus.booked
assert appointment.status == models.AppointmentStatus.closed

# Now try to confirm the same event again
response = with_client.put(
'/schedule/public/availability/booking',
json=availability,
headers=auth_headers,
)

assert response.status_code == 404, response.text


def test_deny(
self,
with_db,
Expand Down Expand Up @@ -959,3 +974,12 @@ def test_deny(

assert slot is None
assert appointment is None

# Now try to deny the same event again
response = with_client.put(
'/schedule/public/availability/booking',
json=availability,
headers=auth_headers,
)

assert response.status_code == 404, response.text

0 comments on commit 7611333

Please sign in to comment.