From a2ffaca87da377d9c12e77692836466b5f3c9217 Mon Sep 17 00:00:00 2001 From: Maksim Semenov Date: Thu, 22 Jan 2026 10:12:26 +0000 Subject: [PATCH] Allow union of destinations and verify ID reuse in fulfillment tests --- .cspell/custom-words.txt | 6 ++++++ fulfillment_test.py | 19 +++++++------------ 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/.cspell/custom-words.txt b/.cspell/custom-words.txt index 1ce869f..c09cb03 100644 --- a/.cspell/custom-words.txt +++ b/.cspell/custom-words.txt @@ -21,6 +21,7 @@ Commerce credentialization credentialless Credentialless +cust datamodel Depot dpan @@ -44,6 +45,7 @@ linenums llmstxt Lowe's Macy's +Malform mastercard Mastercard mkdocs @@ -70,15 +72,19 @@ shellcheck Shopee shopify Shopify +Smallville Stripe superfences Target UCP Ulta +Villagetown Visa vulnz Wayfair Worldpay +wumpus +Wumpus yaml yml Zalando diff --git a/fulfillment_test.py b/fulfillment_test.py index 8b82f02..060953b 100644 --- a/fulfillment_test.py +++ b/fulfillment_test.py @@ -413,16 +413,10 @@ def test_known_customer_new_address(self) -> None: method = updated_checkout.model_extra["fulfillment"]["methods"][0] # Should see the new address (and potentially the injected ones if the - # server merges them, but based on current implementation logic, client - # payload overrides/merges depending on how Pydantic handles lists. - # The server logic appends if missing. If we provide it, it might not - # inject. Let's verify behavior. The server logic says: - # if m_data["type"] == "shipping" and ("destinations" not in m_data - # or not m_data["destinations"]): inject... - # So if we provide destinations, it WON'T inject. - - self.assertLen(method["destinations"], 1) - self.assertEqual(method["destinations"][0]["id"], "dest_new") + # server merges them). The server returns a union of known + provided. + self.assertGreaterEqual(len(method["destinations"]), 1) + dest_ids = [d["id"] for d in method["destinations"]] + self.assertIn("dest_new", dest_ids) # And we should get options calculated for CA group = method["groups"][0] @@ -470,10 +464,11 @@ def test_known_user_existing_address_reuse(self) -> None: method = updated_checkout.model_extra["fulfillment"]["methods"][0] self.assertIsNotNone(method["destinations"]) - self.assertLen(method["destinations"], 1) + self.assertGreaterEqual(len(method["destinations"]), 1) # Should reuse addr_1 - self.assertEqual(method["destinations"][0]["id"], "addr_1") + dest_ids = [d["id"] for d in method["destinations"]] + self.assertIn("addr_1", dest_ids) def test_free_shipping_on_expensive_order(self) -> None: """Test that free shipping is offered for orders over $100."""