fix(medusa): keep country_code when partially updating cart addresses (#2683)

**What**
- Fixes a bug where `country_code` was dropped when partially updating a shipping or billing address on a cart.
This commit is contained in:
Kasper Fabricius Kristensen
2022-12-12 14:03:54 +00:00
committed by GitHub
parent d68e81fb3d
commit 33aa3edb80
5 changed files with 51 additions and 10 deletions
@@ -1,12 +1,12 @@
import _ from "lodash"
import { MedusaError } from "medusa-core-utils"
import { IdMap, MockManager, MockRepository } from "medusa-test-utils"
import { FlagRouter } from "../../utils/flag-router"
import CartService from "../cart"
import { InventoryServiceMock } from "../__mocks__/inventory"
import { LineItemAdjustmentServiceMock } from "../__mocks__/line-item-adjustment"
import { FlagRouter } from "../../utils/flag-router"
import { taxProviderServiceMock } from "../__mocks__/tax-provider"
import { newTotalsServiceMock } from "../__mocks__/new-totals"
import { taxProviderServiceMock } from "../__mocks__/tax-provider"
const eventBusService = {
emit: jest.fn(),
@@ -1100,7 +1100,7 @@ describe("CartService", () => {
last_name: "James",
address_1: "24 Dunks Drive",
city: "Los Angeles",
country_code: "US",
country_code: "us",
province: "CA",
postal_code: "93011",
phone: "+1 (222) 333 4444",
+3 -5
View File
@@ -1238,8 +1238,6 @@ class CartService extends TransactionBaseService {
address = addressOrId as Address
}
address.country_code = address.country_code?.toLowerCase() ?? null
if (address.id) {
cart.billing_address = await addrRepo.save(address)
} else {
@@ -1284,11 +1282,11 @@ class CartService extends TransactionBaseService {
address = addressOrId as Address
}
address.country_code = address.country_code?.toLowerCase() ?? null
if (
address.country_code &&
!cart.region.countries.find(({ iso_2 }) => address.country_code === iso_2)
!cart.region.countries.find(
({ iso_2 }) => address.country_code?.toLowerCase() === iso_2
)
) {
throw new MedusaError(
MedusaError.Types.INVALID_DATA,