Skip to content

Commit

Permalink
[ORG-70] Get all events endpoint is not showing deleted events (#74)
Browse files Browse the repository at this point in the history
* add check to not show deleted events in getallevents

* add test

* black
  • Loading branch information
carlotacb authored Jan 5, 2024
1 parent 72fd964 commit 77ffbe8
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
3 changes: 2 additions & 1 deletion organizator_api/app/events/infrastructure/http/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ def get_all_events(request: HttpRequest) -> HttpResponse:

events_response = []
for event in all_events:
events_response.append(EventResponse.from_event(event).to_dict())
if event.deleted_at is None:
events_response.append(EventResponse.from_event(event).to_dict())

return HttpResponse(
status=200, content=json.dumps(events_response), content_type="application/json"
Expand Down
14 changes: 14 additions & 0 deletions organizator_api/tests/events/infrastructure/http/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,20 @@ def test__given_events_in_db__when_get_all_events__then_returns_the_events_list(
b'[{"id": "ef6f6fb3-ba12-43dd-a0da-95de8125b1cc", "name": "HackUPC 2023", "url": "https://www.hackupc.com/", "description": "The biggest student hackathon in Europe", "start_date": "2023-05-12T16:00:00Z", "end_date": "2023-05-14T18:00:00Z", "location": "UPC Campus Nord", "header_image": "https://hackupc.com/ogimage.png", "deleted": false}, {"id": "be0f4c18-4a7c-4c1e-8a62-fc50916b6c88", "name": "HackUPC 2022", "url": "https://www.hackupc.com/", "description": "The biggest student hackathon in Europe", "start_date": "2023-05-12T16:00:00Z", "end_date": "2023-05-14T18:00:00Z", "location": "UPC Campus Nord", "header_image": "https://hackupc.com/ogimage.png", "deleted": false}]',
)

def test__given_event_deleted_in_db__when_get_all_events__then_it_returns_empty_list(
self,
) -> None:
# Given
event = EventFactory().create(deleted_at=datetime.now())
self.event_repository.create(event)

# When
response = self.client.get("/organizator-api/events/")

# Then
self.assertEqual(response.status_code, 200)
self.assertEqual(response.content, b"[]")

def test__given_events_in_db__when_get_all_upcoming_events__then_returns_the_events_list(
self,
) -> None:
Expand Down

0 comments on commit 77ffbe8

Please sign in to comment.