fix(medusa): Variant update should include the id for the listeners to be able to identify the entity (#3539)

* fix(medusa): Variant update should include the id for the listeners to be able to identify the entity

* fix unit tests

* Create brave-seahorses-film.md
This commit is contained in:
Adrien de Peretti
2023-03-21 16:15:05 +01:00
committed by GitHub
parent 17f615ef30
commit 98fe8fd00a
3 changed files with 13 additions and 1 deletions
+5
View File
@@ -0,0 +1,5 @@
---
"@medusajs/medusa": patch
---
Fix(medusa): Variant update should include the id for the listeners to be able to identify the entity
@@ -333,6 +333,7 @@ describe("ProductVariantService", () => {
expect(productVariantRepository.update).toHaveBeenCalledWith( expect(productVariantRepository.update).toHaveBeenCalledWith(
{ id: IdMap.getId("ironman") }, { id: IdMap.getId("ironman") },
{ {
id: IdMap.getId("ironman"),
title: "new title", title: "new title",
} }
) )
@@ -361,6 +362,7 @@ describe("ProductVariantService", () => {
expect(productVariantRepository.update).toHaveBeenCalledWith( expect(productVariantRepository.update).toHaveBeenCalledWith(
{ id: IdMap.getId("ironman") }, { id: IdMap.getId("ironman") },
{ {
id: IdMap.getId("ironman"),
title: "new title 2", title: "new title 2",
} }
) )
@@ -415,6 +417,7 @@ describe("ProductVariantService", () => {
expect(productVariantRepository.update).toHaveBeenCalledWith( expect(productVariantRepository.update).toHaveBeenCalledWith(
{ id: IdMap.getId("ironman") }, { id: IdMap.getId("ironman") },
{ {
id: IdMap.getId("ironman"),
title: "new title", title: "new title",
metadata: { metadata: {
testing: "this", testing: "this",
@@ -444,6 +447,7 @@ describe("ProductVariantService", () => {
expect(productVariantRepository.update).toHaveBeenCalledWith( expect(productVariantRepository.update).toHaveBeenCalledWith(
{ id: IdMap.getId("ironman") }, { id: IdMap.getId("ironman") },
{ {
id: IdMap.getId("ironman"),
inventory_quantity: 98, inventory_quantity: 98,
title: "new title", title: "new title",
} }
@@ -396,7 +396,10 @@ class ProductVariantService extends TransactionBaseService {
// No need to update if nothing on the variant has changed // No need to update if nothing on the variant has changed
if (shouldUpdate) { if (shouldUpdate) {
const { id } = variant const { id } = variant
const rawResult = await variantRepo.update({ id }, toUpdate) const rawResult = await variantRepo.update(
{ id },
{ id, ...toUpdate }
)
result = variantRepo.create({ result = variantRepo.create({
...variant, ...variant,
...rawResult.generatedMaps[0], ...rawResult.generatedMaps[0],