Merge branch 'master' into develop

This commit is contained in:
olivermrbl committed 2023-03-01 18:33:28 +01:00
commit 947687d3f7
5 files changed
+31 -16

No files matched your search

+5
View File
@@ -0,0 +1,5 @@
---
"@medusajs/medusa": patch
---
Fix(medusa): All payment sessions should be removed if cart total reach 0
+5
View File
@@ -0,0 +1,5 @@
---
"@medusajs/medusa": patch
---
feat(medusa): Use Bull `jobId` option to identify duplicates
@@ -1706,8 +1706,8 @@ describe("CartService", () => {
expect(paymentSessionRepositoryMock.create).toHaveBeenCalledTimes(1) expect(paymentSessionRepositoryMock.create).toHaveBeenCalledTimes(1)
expect(paymentSessionRepositoryMock.save).toHaveBeenCalledTimes(2) // create and update expect(paymentSessionRepositoryMock.save).toHaveBeenCalledTimes(2) // create and update
expect(paymentSessionRepositoryMock.delete).toHaveBeenCalledTimes(1) expect(paymentSessionRepositoryMock.remove).toHaveBeenCalledTimes(1)
expect(paymentSessionRepositoryMock.delete).toHaveBeenCalledWith({ expect(paymentSessionRepositoryMock.remove).toHaveBeenCalledWith({
provider_id: "not_in_region", provider_id: "not_in_region",
}) })
}) })
@@ -1715,12 +1715,12 @@ describe("CartService", () => {
it("removes if cart total === 0", async () => { it("removes if cart total === 0", async () => {
await cartService.setPaymentSessions(IdMap.getId("cart-remove")) await cartService.setPaymentSessions(IdMap.getId("cart-remove"))
expect(paymentSessionRepositoryMock.delete).toHaveBeenCalledTimes(2) expect(paymentSessionRepositoryMock.remove).toHaveBeenCalledTimes(2)
expect(paymentSessionRepositoryMock.delete).toHaveBeenCalledWith({ expect(paymentSessionRepositoryMock.remove).toHaveBeenCalledWith({
provider_id: provider1Id, provider_id: provider1Id,
}) })
expect(paymentSessionRepositoryMock.delete).toHaveBeenCalledWith({ expect(paymentSessionRepositoryMock.remove).toHaveBeenCalledWith({
provider_id: provider2Id, provider_id: provider2Id,
}) })
}) })
@@ -1728,12 +1728,12 @@ describe("CartService", () => {
it("removes if cart total < 0", async () => { it("removes if cart total < 0", async () => {
await cartService.setPaymentSessions(IdMap.getId("cart-negative")) await cartService.setPaymentSessions(IdMap.getId("cart-negative"))
expect(paymentSessionRepositoryMock.delete).toHaveBeenCalledTimes(2) expect(paymentSessionRepositoryMock.remove).toHaveBeenCalledTimes(2)
expect(paymentSessionRepositoryMock.delete).toHaveBeenCalledWith({ expect(paymentSessionRepositoryMock.remove).toHaveBeenCalledWith({
provider_id: provider1Id, provider_id: provider1Id,
}) })
expect(paymentSessionRepositoryMock.delete).toHaveBeenCalledWith({ expect(paymentSessionRepositoryMock.remove).toHaveBeenCalledWith({
provider_id: provider2Id, provider_id: provider2Id,
}) })
}) })
+1 -1
View File
@@ -1846,7 +1846,7 @@ class CartService extends TransactionBaseService {
return paymentProviderServiceTx.deleteSession(session) return paymentProviderServiceTx.deleteSession(session)
} }
return psRepo.delete(session) return psRepo.remove(session)
} }
// In the case of a cart that has a total <= 0 we can return prematurely. // In the case of a cart that has a total <= 0 we can return prematurely.
+12 -7
View File
@@ -1,4 +1,4 @@
import Bull from "bull" import Bull, { JobOptions } from "bull"
import Redis from "ioredis" import Redis from "ioredis"
import { isDefined } from "medusa-core-utils" import { isDefined } from "medusa-core-utils"
import { EntityManager } from "typeorm" import { EntityManager } from "typeorm"
@@ -40,14 +40,16 @@ type SubscriberDescriptor = {
subscriber: Subscriber subscriber: Subscriber
} }
type EmitOptions = { export type EmitOptions = {
delay?: number delay?: number
attempts: number attempts: number
backoff?: { backoff?: {
type: "fixed" | "exponential" type: "fixed" | "exponential"
delay: number delay: number
} }
} } & JobOptions
const COMPLETED_JOB_TTL = 10000
/** /**
* Can keep track of multiple subscribers to different events and run the * Can keep track of multiple subscribers to different events and run the
@@ -225,10 +227,13 @@ export default class EventBusService {
data: T, data: T,
options: Record<string, unknown> & EmitOptions = { attempts: 1 } options: Record<string, unknown> & EmitOptions = { attempts: 1 }
): Promise<StagedJob | void> { ): Promise<StagedJob | void> {
const opts: { removeOnComplete: boolean } & EmitOptions = { const opts: EmitOptions = {
removeOnComplete: true, removeOnComplete: {
attempts: 1, age: COMPLETED_JOB_TTL,
},
...options,
} }
if (typeof options.attempts === "number") { if (typeof options.attempts === "number") {
opts.attempts = options.attempts opts.attempts = options.attempts
if (isDefined(options.backoff)) { if (isDefined(options.backoff)) {
@@ -295,7 +300,7 @@ export default class EventBusService {
this.queue_ this.queue_
.add( .add(
{ eventName: job.event_name, data: job.data }, { eventName: job.event_name, data: job.data },
job.options ?? { removeOnComplete: true } { jobId: job.id, ...job.options }
) )
.then(async () => { .then(async () => {
await stagedJobRepo.remove(job) await stagedJobRepo.remove(job)