Skip to content

Commit

Permalink
Change value and add new test for Google Analytics (#2318)
Browse files Browse the repository at this point in the history
  • Loading branch information
JenniWhitman authored Aug 2, 2024
1 parent 9a2ff6a commit 78e6041
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 5 deletions.
8 changes: 4 additions & 4 deletions ecommerce/views/v0/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -718,9 +718,9 @@ def _create_ga4_context(self, order):
"item_id": line.purchased_object_id,
"item_name": line.item_description,
"affiliation": "MITx Online",
"discount": str(line.discounted_price),
"price": str(line.total_price),
"quantity": line.quantity,
"discount": float(line.discounted_price),
"price": float(line.total_price),
"quantity": int(line.quantity),
"item_category": "Series",
}
if line.purchased_content_type.model == "programrun":
Expand All @@ -730,7 +730,7 @@ def _create_ga4_context(self, order):
payload_items.append(line_object)
ga_purchase_payload = {
"transaction_id": order.reference_number,
"value": str(order.total_price_paid),
"value": float(order.total_price_paid),
"tax": 0.00,
"shipping": 0.00,
"currency": "USD",
Expand Down
28 changes: 27 additions & 1 deletion ecommerce/views_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
)
from flexiblepricing.constants import FlexiblePriceStatus
from flexiblepricing.factories import FlexiblePriceFactory, FlexiblePriceTierFactory
from main import features
from main.constants import (
USER_MSG_COOKIE_NAME,
USER_MSG_TYPE_COURSE_NON_UPGRADABLE,
Expand Down Expand Up @@ -1047,7 +1048,6 @@ def test_bulk_discount_create(admin_drf_client, use_redemption_type_flags):
"""
Try to make some bulk discounts.
"""

test_payload = {
"discount_type": DISCOUNT_TYPE_PERCENT_OFF,
"payment_type": PAYMENT_TYPE_CUSTOMER_SUPPORT,
Expand Down Expand Up @@ -1080,3 +1080,29 @@ def test_bulk_discount_create(admin_drf_client, use_redemption_type_flags):
assert discounts[0].redemption_type == REDEMPTION_TYPE_ONE_TIME
assert discounts[0].amount == 50
assert discounts[0].is_bulk


def test_checkout_interstitial_google_analytics_object(
settings, user, user_client, products
):
"""
Tests that the interstitial page receives the correct GA structure
"""
settings.OPENEDX_SERVICE_WORKER_API_TOKEN = "mock_api_token" # noqa: S105
settings.FEATURES[features.ENABLE_GOOGLE_ANALYTICS_DATA_PUSH] = True

product = products[0]
basket = create_basket_with_product(user, product)
PendingOrder.create_from_basket(basket)
resp = user_client.get(reverse("checkout_interstitial_page"))
assert resp.status_code == 200

ga_purchase_payload = resp.context["ga_purchase_payload"]
assert isinstance(ga_purchase_payload["value"], float)
assert isinstance(ga_purchase_payload["items"], list)
assert isinstance(ga_purchase_payload["shipping"], float)
assert isinstance(ga_purchase_payload["tax"], float)
for item in ga_purchase_payload["items"]:
assert isinstance(item["discount"], float)
assert isinstance(item["price"], float)
assert isinstance(item["quantity"], int)

0 comments on commit 78e6041

Please sign in to comment.