Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: include log messages for rsvp changes #308

Merged
merged 4 commits into from
Jan 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions apps/api/src/routers/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,7 @@ async def rsvp(
elif user_record["status"] == Status.ATTENDING:
new_status = Status.VOID
else:
log.warning(f"User {user.uid} has not signed waiver. Status has not changed.")
raise HTTPException(
status.HTTP_403_FORBIDDEN,
"Waiver must be signed before being able to RSVP.",
Expand All @@ -240,4 +241,7 @@ async def rsvp(
Collection.USERS, {"_id": user.uid}, {"status": new_status}
)

old_status = user_record["status"]
log.info(f"User {user.uid} changed status from {old_status} to {new_status}.")

return RedirectResponse("/portal", status.HTTP_303_SEE_OTHER)
18 changes: 18 additions & 0 deletions apps/api/tests/test_user.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from routers import user
from services.mongodb_handler import Collection
from utils.user_record import Status
from models.ApplicationData import Decision

app = FastAPI()
app.include_router(user.router)
Expand Down Expand Up @@ -116,3 +117,20 @@ def test_user_with_status_attending_un_rsvp_changes_status_to_void(
)

assert res.status_code == 303


@patch("services.mongodb_handler.update_one", autospec=True)
IanWearsHat marked this conversation as resolved.
Show resolved Hide resolved
IanWearsHat marked this conversation as resolved.
Show resolved Hide resolved
@patch("services.mongodb_handler.retrieve_one", autospec=True)
def test_user_with_status_accepted_un_rsvp_returns_403(
mock_mongodb_handler_retrieve_one: AsyncMock,
mock_mongodb_handler_update_one: AsyncMock,
) -> None:
"""Test user with ACCEPTED status has no status change after RSVP."""
mock_mongodb_handler_retrieve_one.return_value = {"status": Decision.ACCEPTED}

client = UserTestClient(GuestUser(email="[email protected]"), app)
res = client.post("/rsvp", follow_redirects=False)

mock_mongodb_handler_update_one.assert_not_awaited()

assert res.status_code == 403