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

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

View File

@@ -333,6 +333,7 @@ describe("ProductVariantService", () => {
expect(productVariantRepository.update).toHaveBeenCalledWith(
{ id: IdMap.getId("ironman") },
{
id: IdMap.getId("ironman"),
title: "new title",
}
)
@@ -361,6 +362,7 @@ describe("ProductVariantService", () => {
expect(productVariantRepository.update).toHaveBeenCalledWith(
{ id: IdMap.getId("ironman") },
{
id: IdMap.getId("ironman"),
title: "new title 2",
}
)
@@ -415,6 +417,7 @@ describe("ProductVariantService", () => {
expect(productVariantRepository.update).toHaveBeenCalledWith(
{ id: IdMap.getId("ironman") },
{
id: IdMap.getId("ironman"),
title: "new title",
metadata: {
testing: "this",
@@ -444,6 +447,7 @@ describe("ProductVariantService", () => {
expect(productVariantRepository.update).toHaveBeenCalledWith(
{ id: IdMap.getId("ironman") },
{
id: IdMap.getId("ironman"),
inventory_quantity: 98,
title: "new title",
}

View File

@@ -396,7 +396,10 @@ class ProductVariantService extends TransactionBaseService {
// No need to update if nothing on the variant has changed
if (shouldUpdate) {
const { id } = variant
const rawResult = await variantRepo.update({ id }, toUpdate)
const rawResult = await variantRepo.update(
{ id },
{ id, ...toUpdate }
)
result = variantRepo.create({
...variant,
...rawResult.generatedMaps[0],