Skip to content

Commit

Permalink
fixup! ♻️(backend) api teams list ordering
Browse files Browse the repository at this point in the history
  • Loading branch information
AntoLC committed Feb 9, 2024
1 parent 37744d8 commit 64e1b1d
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 69 deletions.
59 changes: 57 additions & 2 deletions src/backend/core/tests/teams/test_core_api_teams_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@
from rest_framework.status import HTTP_200_OK, HTTP_401_UNAUTHORIZED
from rest_framework.test import APIClient

from core import factories, models
from core.api import serializers
from core import factories

from ..utils import OIDCToken

Expand Down Expand Up @@ -116,3 +115,59 @@ def test_api_teams_list_authenticated_distinct():
content = response.json()
assert len(content["results"]) == 1
assert content["results"][0]["id"] == str(team.id)


def test_api_teams_order():
"""
Test that the endpoint GET teams is sorted in created_at descending order by default.
"""
identity = factories.IdentityFactory()
user = identity.user
jwt_token = OIDCToken.for_user(user)

team_ids = [
str(team.id) for team in factories.TeamFactory.create_batch(5, users=[user])
]

response = APIClient().get(
"/api/v1.0/teams/",
HTTP_AUTHORIZATION=f"Bearer {jwt_token}",
)

assert response.status_code == 200

response_data = response.json()
response_team_ids = [team["id"] for team in response_data["results"]]

team_ids.reverse()
assert (
response_team_ids == team_ids
), "created_at values are not sorted from newest to oldest"


def test_api_teams_order_param():
"""
Test that the 'created_at' field is sorted in ascending order
when the 'ordering' query parameter is set.
"""
identity = factories.IdentityFactory()
user = identity.user
jwt_token = OIDCToken.for_user(user)

team_ids = [
str(team.id) for team in factories.TeamFactory.create_batch(5, users=[user])
]

response = APIClient().get(
"/api/v1.0/teams/?ordering=created_at",
HTTP_AUTHORIZATION=f"Bearer {jwt_token}",
)
assert response.status_code == 200

response_data = response.json()

response_team_ids = [team["id"] for team in response_data["results"]]

assert (
response_team_ids == team_ids
), "created_at values are not sorted from oldest to newest"
67 changes: 0 additions & 67 deletions src/backend/core/tests/test_api_teams.py

This file was deleted.

0 comments on commit 64e1b1d

Please sign in to comment.