Skip to content
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
26 changes: 24 additions & 2 deletions api/tests/unit/custom_auth/test_unit_custom_auth_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,18 @@ def test_get_current_user(staff_user: FFAdminUser, staff_client: APIClient) -> N
"tools": {"completed": True, "integrations": ["integration-1"]},
},
),
(
{
"tasks": [{"name": "task-1"}],
"tools": {"completed": True, "integrations": ["integration-1"]},
"hosting_preferences": ["hosting-preference-1, hosting-preference-2"],
},
{
"tasks": [{"name": "task-1", "completed_at": "2025-01-01T12:00:00Z"}],
"tools": {"completed": True, "integrations": ["integration-1"]},
"hosting_preferences": ["hosting-preference-1, hosting-preference-2"],
},
),
],
)
@freeze_time("2025-01-01T12:00:00Z")
Expand Down Expand Up @@ -96,6 +108,14 @@ def test_get_me_should_return_onboarding_object(
},
{"tasks", "tools"},
),
(
{
"tasks": [{"name": "task-1", "completed_at": "2024-01-01T12:00:00Z"}],
"tools": {"completed": True, "integrations": ["integration-1"]},
"hosting_preferences": ["hosting-preference-1, hosting-preference-2"],
},
{"tasks", "tools", "hosting_preferences"},
),
],
)
def test_patch_user_onboarding_updates_only_nested_objects_if_provided(
Expand Down Expand Up @@ -128,7 +148,7 @@ def test_patch_user_onboarding_updates_only_nested_objects_if_provided(
).get("integrations")


def test_patch_user_onboarding_returns_error_if_tasks_and_tools_are_missing(
def test_patch_user_onboarding_returns_error_if_preferences_tasks_and_tools_are_missing(
staff_user: FFAdminUser,
staff_client: APIClient,
) -> None:
Expand All @@ -141,7 +161,9 @@ def test_patch_user_onboarding_returns_error_if_tasks_and_tools_are_missing(
# Then
assert response.status_code == status.HTTP_400_BAD_REQUEST
assert response.json() == {
"non_field_errors": ["At least one of 'tasks' or 'tools' must be provided."]
"non_field_errors": [
"At least one of 'tasks' or 'tools' or 'hosting_preferences' must be provided."
]
}


Expand Down
14 changes: 12 additions & 2 deletions api/users/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,18 +179,28 @@ def validate_completed_at(self, completed_at: datetime | None) -> datetime:
class PatchOnboardingSerializer(serializers.Serializer[None]):
tasks = OnboardingTaskSerializer(many=True, required=False)
tools = OnboardingToolsSerializer(required=False)
hosting_preferences = serializers.ListField(
child=serializers.CharField(), required=False, allow_empty=True
)

def validate(self, data: dict[str, Any]) -> dict[str, Any]:
if "tasks" not in data and "tools" not in data:
if (
"tasks" not in data
and "tools" not in data
and "hosting_preferences" not in data
):
raise serializers.ValidationError(
"At least one of 'tasks' or 'tools' must be provided."
"At least one of 'tasks' or 'tools' or 'hosting_preferences' must be provided."
)
return data


class OnboardingResponseTypeSerializer(serializers.Serializer[None]):
tasks = OnboardingTaskSerializer(many=True, required=False, default=list)
tools = OnboardingToolsSerializer(required=False)
hosting_preferences = serializers.ListField(
child=serializers.CharField(), required=False, allow_empty=True
)


class CustomCurrentUserSerializer(DjoserUserSerializer): # type: ignore[misc]
Expand Down
Loading