Skip to content

Commit

Permalink
Merge branch 'develop' into test-node-20
Browse files Browse the repository at this point in the history
  • Loading branch information
riqwan authored Jan 4, 2024
2 parents 99cec39 + 7f62ab1 commit 3357885
Show file tree
Hide file tree
Showing 34 changed files with 806 additions and 163 deletions.
8 changes: 8 additions & 0 deletions .changeset/fuzzy-ears-look.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
"@medusajs/pricing": patch
"@medusajs/types": patch
"@medusajs/utils": patch
---

feat(pricing, types): add soft deletion for money-amounts
feat(utils): cascade soft delete across 1:1 relationships
6 changes: 6 additions & 0 deletions .changeset/smart-zoos-nail.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@medusajs/medusa": patch
"medusa-payment-stripe": patch
---

fix(medusa, medusa-payment-stripe): fix stripe error handling
1 change: 1 addition & 0 deletions .github/workflows/test-cli-with-database.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ jobs:
uses: ./.github/actions/setup-server
with:
cache-extension: "cli-test"
node-version: "16.14"

- name: Install Medusa cli
run: npm i -g @medusajs/medusa-cli
Expand Down
14 changes: 7 additions & 7 deletions packages/medusa-payment-stripe/src/core/stripe-base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -322,16 +322,16 @@ abstract class StripeBase extends AbstractPaymentProcessor {

protected buildError(
message: string,
e: Stripe.StripeRawError | PaymentProcessorError | Error
error: Stripe.StripeRawError | PaymentProcessorError | Error
): PaymentProcessorError {
return {
error: message,
code: "code" in e ? e.code : "",
detail: isPaymentProcessorError(e)
? `${e.error}${EOL}${e.detail ?? ""}`
: "detail" in e
? e.detail
: e.message ?? "",
code: "code" in error ? error.code : "unknown",
detail: isPaymentProcessorError(error)
? `${error.error}${EOL}${error.detail ?? ""}`
: "detail" in error
? error.detail
: error.message ?? "",
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion packages/medusa/src/interfaces/payment-processor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -777,5 +777,5 @@ export abstract class AbstractPaymentProcessor implements PaymentProcessor {
export function isPaymentProcessorError(
obj: any
): obj is PaymentProcessorError {
return obj && typeof obj === "object" && (obj.error || obj.code || obj.detail)
return obj && typeof obj === "object" && obj.error && obj.code && obj.detail
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ import { initialize } from "../../../../src"
import { createCurrencies } from "../../../__fixtures__/currency"
import { createMoneyAmounts } from "../../../__fixtures__/money-amount"
import { DB_URL, MikroOrmWrapper } from "../../../utils"
import { createPriceSetMoneyAmounts } from "../../../__fixtures__/price-set-money-amount"
import { createPriceSets } from "../../../__fixtures__/price-set"
import { createRuleTypes } from "../../../__fixtures__/rule-type"
import { createPriceRules } from "../../../__fixtures__/price-rule"
import { createPriceSetMoneyAmountRules } from "../../../__fixtures__/price-set-money-amount-rules"

jest.setTimeout(30000)

Expand Down Expand Up @@ -264,6 +269,94 @@ describe("PricingModule Service - MoneyAmount", () => {
})
})

describe("softDeleteMoneyAmounts", () => {
const id = "money-amount-USD"

it("should softDelete priceSetMoneyAmount and PriceRule when soft-deleting money amount", async () => {
await createPriceSets(testManager)
await createRuleTypes(testManager)
await createPriceSetMoneyAmounts(testManager)
await createPriceRules(testManager)
await createPriceSetMoneyAmountRules(testManager)
await service.softDeleteMoneyAmounts([id])

const [moneyAmount] = await service.listMoneyAmounts(
{
id: [id],
},
{
relations: [
"price_set_money_amount",
"price_set_money_amount.price_rules",
],
withDeleted: true,
}
)

expect(moneyAmount).toBeTruthy()

const deletedAt = moneyAmount.deleted_at

expect(moneyAmount).toEqual(
expect.objectContaining({
deleted_at: deletedAt,
price_set_money_amount: expect.objectContaining({
deleted_at: deletedAt,
price_rules: [
expect.objectContaining({
deleted_at: deletedAt,
}),
],
}),
})
)
})
})

describe("restoreDeletedMoneyAmounts", () => {
const id = "money-amount-USD"

it("should restore softDeleted priceSetMoneyAmount and PriceRule when restoring soft-deleting money amount", async () => {
await createPriceSets(testManager)
await createRuleTypes(testManager)
await createPriceSetMoneyAmounts(testManager)
await createPriceRules(testManager)
await createPriceSetMoneyAmountRules(testManager)
await service.softDeleteMoneyAmounts([id])
await service.restoreDeletedMoneyAmounts([id])

const [moneyAmount] = await service.listMoneyAmounts(
{
id: [id],
},
{
relations: [
"price_set_money_amount",
"price_set_money_amount.price_rules",
],
}
)

expect(moneyAmount).toBeTruthy()

const deletedAt = null

expect(moneyAmount).toEqual(
expect.objectContaining({
deleted_at: deletedAt,
price_set_money_amount: expect.objectContaining({
deleted_at: deletedAt,
price_rules: [
expect.objectContaining({
deleted_at: deletedAt,
}),
],
}),
})
)
})
})

describe("updateMoneyAmounts", () => {
const id = "money-amount-USD"

Expand Down
1 change: 1 addition & 0 deletions packages/pricing/src/joiner-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export const LinkableKeys = {
price_list_id: PriceList.name,
price_set_money_amount_id: PriceSetMoneyAmount.name,
}

const entityLinkableKeysMap: MapToConfig = {}
Object.entries(LinkableKeys).forEach(([key, value]) => {
entityLinkableKeysMap[value] ??= []
Expand Down
Loading

0 comments on commit 3357885

Please sign in to comment.