Skip to content

Commit 5598da0

Browse files
authored
feat: added-hosted-preferences-to-onboarding-data (#5883)
1 parent 63f943a commit 5598da0

2 files changed

Lines changed: 36 additions & 4 deletions

File tree

api/tests/unit/custom_auth/test_unit_custom_auth_views.py

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,18 @@ def test_get_current_user(staff_user: FFAdminUser, staff_client: APIClient) -> N
5454
"tools": {"completed": True, "integrations": ["integration-1"]},
5555
},
5656
),
57+
(
58+
{
59+
"tasks": [{"name": "task-1"}],
60+
"tools": {"completed": True, "integrations": ["integration-1"]},
61+
"hosting_preferences": ["hosting-preference-1, hosting-preference-2"],
62+
},
63+
{
64+
"tasks": [{"name": "task-1", "completed_at": "2025-01-01T12:00:00Z"}],
65+
"tools": {"completed": True, "integrations": ["integration-1"]},
66+
"hosting_preferences": ["hosting-preference-1, hosting-preference-2"],
67+
},
68+
),
5769
],
5870
)
5971
@freeze_time("2025-01-01T12:00:00Z")
@@ -96,6 +108,14 @@ def test_get_me_should_return_onboarding_object(
96108
},
97109
{"tasks", "tools"},
98110
),
111+
(
112+
{
113+
"tasks": [{"name": "task-1", "completed_at": "2024-01-01T12:00:00Z"}],
114+
"tools": {"completed": True, "integrations": ["integration-1"]},
115+
"hosting_preferences": ["hosting-preference-1, hosting-preference-2"],
116+
},
117+
{"tasks", "tools", "hosting_preferences"},
118+
),
99119
],
100120
)
101121
def test_patch_user_onboarding_updates_only_nested_objects_if_provided(
@@ -128,7 +148,7 @@ def test_patch_user_onboarding_updates_only_nested_objects_if_provided(
128148
).get("integrations")
129149

130150

131-
def test_patch_user_onboarding_returns_error_if_tasks_and_tools_are_missing(
151+
def test_patch_user_onboarding_returns_error_if_preferences_tasks_and_tools_are_missing(
132152
staff_user: FFAdminUser,
133153
staff_client: APIClient,
134154
) -> None:
@@ -141,7 +161,9 @@ def test_patch_user_onboarding_returns_error_if_tasks_and_tools_are_missing(
141161
# Then
142162
assert response.status_code == status.HTTP_400_BAD_REQUEST
143163
assert response.json() == {
144-
"non_field_errors": ["At least one of 'tasks' or 'tools' must be provided."]
164+
"non_field_errors": [
165+
"At least one of 'tasks' or 'tools' or 'hosting_preferences' must be provided."
166+
]
145167
}
146168

147169

api/users/serializers.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,18 +179,28 @@ def validate_completed_at(self, completed_at: datetime | None) -> datetime:
179179
class PatchOnboardingSerializer(serializers.Serializer[None]):
180180
tasks = OnboardingTaskSerializer(many=True, required=False)
181181
tools = OnboardingToolsSerializer(required=False)
182+
hosting_preferences = serializers.ListField(
183+
child=serializers.CharField(), required=False, allow_empty=True
184+
)
182185

183186
def validate(self, data: dict[str, Any]) -> dict[str, Any]:
184-
if "tasks" not in data and "tools" not in data:
187+
if (
188+
"tasks" not in data
189+
and "tools" not in data
190+
and "hosting_preferences" not in data
191+
):
185192
raise serializers.ValidationError(
186-
"At least one of 'tasks' or 'tools' must be provided."
193+
"At least one of 'tasks' or 'tools' or 'hosting_preferences' must be provided."
187194
)
188195
return data
189196

190197

191198
class OnboardingResponseTypeSerializer(serializers.Serializer[None]):
192199
tasks = OnboardingTaskSerializer(many=True, required=False, default=list)
193200
tools = OnboardingToolsSerializer(required=False)
201+
hosting_preferences = serializers.ListField(
202+
child=serializers.CharField(), required=False, allow_empty=True
203+
)
194204

195205

196206
class CustomCurrentUserSerializer(DjoserUserSerializer): # type: ignore[misc]

0 commit comments

Comments
 (0)