refactor(medusa): Cleanup and fix CartService (#1306)

* refactor(medusa): Cleanup + fix

* styles(medusa): Lint

* refactor(medusa): Finalize cleanup

* feat(medusa): Prefer the usage of bulk operations instead of sequential/conccurent operations

* feat(medusa): Improve cart service

* refactor(medusa): Explicitly specifying protected methods when needed as well as enfore the usage of the local transactionManager_ in those methods

* tests(medusa): Fix tests according to the new changes

* feat(medusa): Cleanup after rebase

* test(medusa): Fix cart service tests
This commit is contained in:
Adrien de Peretti
2022-04-13 18:35:13 +02:00
committed by GitHub
parent 3f19a3c4d5
commit 12c06b4c9d
12 changed files with 1142 additions and 995 deletions

View File

@@ -24,7 +24,7 @@ Object {
}
`;
exports[`/store/carts shipping address + region updates updates region only - single to multipe countries 1`] = `
exports[`/store/carts shipping address + region updates updates region only - single to multiple countries 1`] = `
Object {
"address_1": null,
"address_2": null,

View File

@@ -924,19 +924,19 @@ describe("/store/carts", () => {
})
it("fails on apply discount if limit has been reached", async () => {
expect.assertions(2)
const api = useApi()
await api
const err = await api
.post("/store/carts/test-cart", {
discounts: [{ code: "SPENT" }],
})
.catch((error) => {
expect(error.response.status).toEqual(400)
expect(error.response.data.message).toEqual(
"Discount has been used maximum allowed times"
)
})
.catch((err) => err)
expect(err).toBeTruthy()
expect(err.response.status).toEqual(400)
expect(err.response.data.message).toEqual(
"Discount has been used maximum allowed times"
)
})
it("successfully passes customer conditions with `in` operator and applies discount", async () => {
@@ -1755,7 +1755,7 @@ describe("/store/carts", () => {
}),
])
)
expect(cartWithGiftcard.data.cart.total).toBe(1900) // 1000 (giftcard) + 900 (standard item with 10% discount)
expect(cartWithGiftcard.data.cart.total).toBe(2900) // 1000 (giftcard) + 900 (standard item with 10% discount) + 1000 Shipping
expect(cartWithGiftcard.data.cart.discount_total).toBe(100)
expect(cartWithGiftcard.status).toEqual(200)
})
@@ -1925,7 +1925,7 @@ describe("/store/carts", () => {
await doAfterEach()
})
it("updates region only - single to multipe countries", async () => {
it("updates region only - single to multiple countries", async () => {
const api = useApi()
const { data, status } = await api
@@ -1947,7 +1947,7 @@ describe("/store/carts", () => {
})
})
it("updates region only - single to multipe countries", async () => {
it("should reset the shipping_address on null value", async () => {
const api = useApi()
const { data, status } = await api
@@ -1962,7 +1962,5 @@ describe("/store/carts", () => {
expect(status).toEqual(200)
expect(data.cart.shipping_address).toEqual(null)
})
// it("updates cart.customer_id on cart retrieval if cart.customer_id differ from session customer", async () => {})
})
})