Skip to content

Commit

Permalink
Merge branch 'main' into rvinnakota/update-resolver-to-mutation
Browse files Browse the repository at this point in the history
  • Loading branch information
rohitvinnakota-codecov committed Jun 19, 2024
2 parents ea43bb4 + 6efefaf commit f24dd0d
Show file tree
Hide file tree
Showing 20 changed files with 1,318 additions and 275 deletions.
12 changes: 11 additions & 1 deletion api/internal/owner/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,18 @@ def update_billing_address(self, request, *args, **kwargs):
if not billing_address:
raise ValidationError(detail="No billing_address sent")
owner = self.get_object()

formatted_address = {
"line1": billing_address["line_1"],
"line2": billing_address["line_2"],
"city": billing_address["city"],
"state": billing_address["state"],
"postal_code": billing_address["postal_code"],
"country": billing_address["country"],
}

billing = BillingService(requesting_user=request.current_owner)
billing.update_billing_address(owner, billing_address)
billing.update_billing_address(owner, billing_address=formatted_address)
return Response(self.get_serializer(owner).data)


Expand Down
46 changes: 44 additions & 2 deletions api/internal/tests/views/test_account_viewset.py
Original file line number Diff line number Diff line change
Expand Up @@ -1105,11 +1105,20 @@ def test_update_billing_address_handles_stripe_error(self, stripe_mock):
assert response.data["detail"] == message

@patch("services.billing.stripe.Subscription.retrieve")
@patch("services.billing.stripe.Customer.retrieve")
@patch("services.billing.stripe.PaymentMethod.modify")
@patch("services.billing.stripe.Customer.modify")
def test_update_billing_address(self, modify_customer_mock, retrieve_mock):
def test_update_billing_address(
self,
modify_customer_mock,
modify_payment_mock,
retrieve_customer_mock,
retrieve_sub_mock,
):
self.current_owner.stripe_customer_id = "flsoe"
self.current_owner.stripe_subscription_id = "djfos"
self.current_owner.save()
f = open("./services/tests/samples/stripe_invoice.json")

billing_address = {
"line_1": "45 Fremont St.",
Expand All @@ -1119,6 +1128,37 @@ def test_update_billing_address(self, modify_customer_mock, retrieve_mock):
"country": "US",
"postal_code": "94105",
}

formatted_address = {
"line1": "45 Fremont St.",
"line2": "",
"city": "San Francisco",
"state": "CA",
"country": "US",
"postal_code": "94105",
}

default_payment_method = {
"id": "pm_123",
"card": {
"brand": "visa",
"exp_month": 12,
"exp_year": 2024,
"last4": "abcd",
},
}

subscription_params = {
"default_payment_method": default_payment_method,
"cancel_at_period_end": False,
"current_period_end": 1633512445,
"latest_invoice": json.load(f)["data"][0],
"schedule_id": None,
"collection_method": "charge_automatically",
}

retrieve_sub_mock.return_value = MockSubscription(subscription_params)

kwargs = {
"service": self.current_owner.service,
"owner_username": self.current_owner.username,
Expand All @@ -1128,8 +1168,10 @@ def test_update_billing_address(self, modify_customer_mock, retrieve_mock):
response = self.client.patch(url, data=data, format="json")
assert response.status_code == status.HTTP_200_OK

retrieve_customer_mock.assert_called_once()
modify_payment_mock.assert_called_once()
modify_customer_mock.assert_called_once_with(
self.current_owner.stripe_customer_id, address=billing_address
self.current_owner.stripe_customer_id, address=formatted_address
)

@patch("api.shared.permissions.get_provider")
Expand Down
Loading

0 comments on commit f24dd0d

Please sign in to comment.