diff --git a/integration-tests/http/__tests__/product/admin/product.spec.ts b/integration-tests/http/__tests__/product/admin/product.spec.ts index edefbc4a8f..172b2c8d95 100644 --- a/integration-tests/http/__tests__/product/admin/product.spec.ts +++ b/integration-tests/http/__tests__/product/admin/product.spec.ts @@ -3043,12 +3043,20 @@ medusaIntegrationTestRunner({ describe("batch methods", () => { it("successfully creates, updates, and deletes products", async () => { const createPayload = getProductFixture({ + weight: 100, + length: 200, + height: 300, + width: 400, title: "Test batch create", handle: "test-batch-create", shipping_profile_id: shippingProfile.id, }) const updatePayload = { + weight: 101, + length: 201, + height: 301, + width: 401, id: publishedProduct.id, title: "Test batch update", } diff --git a/packages/modules/product/integration-tests/__tests__/product-module-service/products.spec.ts b/packages/modules/product/integration-tests/__tests__/product-module-service/products.spec.ts index 72acb05824..1f95555f68 100644 --- a/packages/modules/product/integration-tests/__tests__/product-module-service/products.spec.ts +++ b/packages/modules/product/integration-tests/__tests__/product-module-service/products.spec.ts @@ -33,6 +33,7 @@ import { jest.setTimeout(300000) moduleIntegrationTestRunner({ + debug: true, moduleName: Modules.PRODUCT, injectedDependencies: { [Modules.EVENT_BUS]: new MockEventBusService(), @@ -127,6 +128,10 @@ moduleIntegrationTestRunner({ productOne = service.createProducts({ title: "product 1", status: ProductStatus.PUBLISHED, + weight: 100, + length: 200, + height: 300, + width: 400, options: [ { title: "opt-title", @@ -236,6 +241,11 @@ moduleIntegrationTestRunner({ productBefore.images = data.images productBefore.thumbnail = data.thumbnail productBefore.tag_ids = data.tag_ids + // Update the weight/length/height/width to ensure we are compensating the type mismatch with the DB + productBefore.weight = 101 + productBefore.length = 201 + productBefore.height = 301 + productBefore.width = 401 const updatedProducts = await service.upsertProducts([productBefore]) expect(updatedProducts).toHaveLength(1) @@ -270,6 +280,11 @@ moduleIntegrationTestRunner({ discountable: productBefore.discountable, thumbnail: images[0].url, status: productBefore.status, + // TODO: Notice how the weight/length/height/width are strings, not respecting the ProductDTO typings + weight: "101", + length: "201", + height: "301", + width: "401", images: expect.arrayContaining([ expect.objectContaining({ id: expect.any(String), diff --git a/packages/modules/product/src/repositories/product.ts b/packages/modules/product/src/repositories/product.ts index 2b8380441b..7095954e2a 100644 --- a/packages/modules/product/src/repositories/product.ts +++ b/packages/modules/product/src/repositories/product.ts @@ -21,6 +21,8 @@ export class ProductRepository extends DALUtils.mikroOrmBaseRepositoryFactory( ) => void, context: Context = {} ): Promise[]> { + updates.forEach((update) => this.correctUpdateDTOTypes(update)) + const products = await this.find( buildQuery({ id: updates.map((p) => p.id) }, { relations: ["*"] }), context @@ -80,6 +82,15 @@ export class ProductRepository extends DALUtils.mikroOrmBaseRepositoryFactory( .filter((product) => product !== undefined) } + // We should probably fix the column types in the database to avoid this + // It would also match the types in ProductVariant, which are already numbers + protected correctUpdateDTOTypes(update: any) { + update.weight = update.weight?.toString() + update.length = update.length?.toString() + update.height = update.height?.toString() + update.width = update.width?.toString() + } + /** * In order to be able to have a strict not in categories, and prevent a product * to be return in the case it also belongs to other categories, we need to