Skip to content

Commit

Permalink
(PC-31318)[API] fix: handle legacy activity serialization
Browse files Browse the repository at this point in the history
  • Loading branch information
dnguyen1-pass committed Aug 14, 2024
1 parent 260838a commit 88add31
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
6 changes: 4 additions & 2 deletions api/src/pcapi/routes/native/v1/serialization/account.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,9 +172,11 @@ def get(self, key: str, default: typing.Any | None = None) -> typing.Any:
user_subscription_state = subscription_api.get_user_subscription_state(user)
return user_subscription_state.subscription_message
if key == "activityId":
if user.activity is None:
try:
activity = users_models.ActivityEnum(user.activity)
return profile_options.ActivityIdEnum(activity.name)
except ValueError:
return None
return profile_options.ActivityIdEnum(users_models.ActivityEnum(user.activity).name)

return super().get(key, default)

Expand Down
10 changes: 10 additions & 0 deletions api/tests/routes/native/v1/account_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,16 @@ def test_get_user_profile_empty_first_name(self, client, app):
assert not response.json["isBeneficiary"]
assert response.json["roles"] == []

def test_get_user_profile_legacy_activity(self, client):
users_factories.UserFactory(email=self.identifier, activity="activity not in enum")

expected_num_queries = 4 # user + beneficiary_fraud_review + deposit + booking
with assert_num_queries(expected_num_queries):
response = client.with_token(email=self.identifier).get("/native/v1/me")

assert response.status_code == 200
assert "activity" not in response.json

def test_get_user_profile_recredit_amount_to_show(self, client, app):
with time_machine.travel("2020-01-01"):
users_factories.UnderageBeneficiaryFactory(email=self.identifier)
Expand Down

0 comments on commit 88add31

Please sign in to comment.