Skip to content

Commit 0235f18

Browse files
authored
fix: optional-and-default-values-for-tasks-in-me-endpoint (#5646)
1 parent 6a2ba6d commit 0235f18

2 files changed

Lines changed: 35 additions & 14 deletions

File tree

api/tests/unit/custom_auth/test_unit_custom_auth_views.py

Lines changed: 34 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
import pytest
55
from django.urls import reverse
6+
from freezegun import freeze_time
67
from rest_framework import status
78
from rest_framework.test import APIClient
89

@@ -26,13 +27,39 @@ def test_get_current_user(staff_user: FFAdminUser, staff_client: APIClient) -> N
2627
assert response_json["uuid"] == str(staff_user.uuid)
2728

2829

29-
def test_get_me_should_return_onboarding_object(db: None) -> None:
30+
@pytest.mark.parametrize(
31+
"onboarding_data, expected_response",
32+
[
33+
(None, None),
34+
(
35+
{"tasks": [{"name": "task-1"}]},
36+
{"tasks": [{"name": "task-1", "completed_at": "2025-01-01T12:00:00Z"}]},
37+
),
38+
(
39+
{"tools": {"completed": True, "integrations": ["integration-1"]}},
40+
{
41+
"tasks": [],
42+
"tools": {"completed": True, "integrations": ["integration-1"]},
43+
},
44+
),
45+
(
46+
{
47+
"tasks": [{"name": "task-1"}],
48+
"tools": {"completed": True, "integrations": ["integration-1"]},
49+
},
50+
{
51+
"tasks": [{"name": "task-1", "completed_at": "2025-01-01T12:00:00Z"}],
52+
"tools": {"completed": True, "integrations": ["integration-1"]},
53+
},
54+
),
55+
],
56+
)
57+
@freeze_time("2025-01-01T12:00:00Z")
58+
def test_get_me_should_return_onboarding_object(
59+
db: None, onboarding_data: dict[str, Any], expected_response: dict[str, Any]
60+
) -> None:
3061
# Given
31-
onboarding = {
32-
"tasks": [{"name": "task-1"}],
33-
"tools": {"completed": True, "integrations": ["integration-1"]},
34-
}
35-
onboarding_serialized = json.dumps(onboarding)
62+
onboarding_serialized = json.dumps(onboarding_data)
3663
new_user = FFAdminUser.objects.create(
3764
email="testuser@mail.com",
3865
onboarding_data=onboarding_serialized,
@@ -49,13 +76,7 @@ def test_get_me_should_return_onboarding_object(db: None) -> None:
4976
# Then
5077
assert response.status_code == status.HTTP_200_OK
5178
response_json = response.json()
52-
assert response_json["onboarding"] is not None
53-
assert response_json["onboarding"].get("tools", {}).get("completed") is True
54-
assert response_json["onboarding"].get("tools", {}).get("integrations") == [
55-
"integration-1"
56-
]
57-
assert response_json["onboarding"].get("tasks") is not None
58-
assert response_json["onboarding"].get("tasks", [])[0].get("name") == "task-1"
79+
assert response_json["onboarding"] == expected_response
5980

6081

6182
@pytest.mark.parametrize(

api/users/serializers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ def validate(self, data: dict[str, Any]) -> dict[str, Any]:
189189

190190

191191
class OnboardingResponseTypeSerializer(serializers.Serializer[None]):
192-
tasks = OnboardingTaskSerializer(many=True)
192+
tasks = OnboardingTaskSerializer(many=True, required=False, default=list)
193193
tools = OnboardingToolsSerializer(required=False)
194194

195195

0 commit comments

Comments
 (0)