From 51c97abec9d15e1385284ca6d5f65c55a5e72709 Mon Sep 17 00:00:00 2001 From: Sebastian Rindom Date: Mon, 30 Mar 2020 17:17:25 +0200 Subject: [PATCH] Remove ProductService dependency from ProductVariantService --- packages/medusa/jest.config.js | 3 -- .../src/services/__tests__/product-variant.js | 45 ------------------- .../medusa/src/services/product-variant.js | 32 ------------- 3 files changed, 80 deletions(-) diff --git a/packages/medusa/jest.config.js b/packages/medusa/jest.config.js index 574c399887..82513aa071 100644 --- a/packages/medusa/jest.config.js +++ b/packages/medusa/jest.config.js @@ -1,6 +1,3 @@ module.exports = { testEnvironment: "node", - testPathIgnorePatterns: [ - "mocks" - ] } diff --git a/packages/medusa/src/services/__tests__/product-variant.js b/packages/medusa/src/services/__tests__/product-variant.js index 772663a4a7..d80e392c59 100644 --- a/packages/medusa/src/services/__tests__/product-variant.js +++ b/packages/medusa/src/services/__tests__/product-variant.js @@ -312,36 +312,6 @@ describe("ProductVariantService", () => { ) }) - it("throw error if product with variant does not exist", async () => { - try { - await productVariantService.addOptionValue( - IdMap.getId("failId"), - IdMap.getId("testOptionId"), - "testValue" - ) - } catch (err) { - expect(err.message).toEqual( - `Products with variant: ${IdMap.getId("failId")} was not found` - ) - } - }) - - it("throw error if product does not have option id", async () => { - try { - await productVariantService.addOptionValue( - IdMap.getId("testVariant"), - IdMap.getId("failOptionId"), - "testValue" - ) - } catch (err) { - expect(err.message).toEqual( - `Associated product does not have option: ${IdMap.getId( - "failOptionId" - )}` - ) - } - }) - it("throw error if option value is not string", async () => { try { await productVariantService.addOptionValue( @@ -379,21 +349,6 @@ describe("ProductVariantService", () => { { $pull: { options: { option_id: IdMap.getId("testing") } } } ) }) - - it("throw error if product still has the option id of the option value we are trying to delete", async () => { - try { - await productVariantService.deleteOptionValue( - IdMap.getId("testVariant"), - IdMap.getId("testOptionId") - ) - } catch (err) { - expect(err.message).toEqual( - `Associated product has option with id: ${IdMap.getId( - "testOptionId" - )}` - ) - } - }) }) describe("delete", () => { diff --git a/packages/medusa/src/services/product-variant.js b/packages/medusa/src/services/product-variant.js index 4fb725bfbd..1291d717d6 100644 --- a/packages/medusa/src/services/product-variant.js +++ b/packages/medusa/src/services/product-variant.js @@ -308,22 +308,6 @@ class ProductVariantService extends BaseService { * @return {Promise} the result of the update operation. */ async addOptionValue(variantId, optionId, optionValue) { - const products = await this.productService_.list({ variants: variantId }) - if (!products.length) { - throw new MedusaError( - MedusaError.Types.NOT_FOUND, - `Products with variant: ${variantId} was not found` - ) - } - - const product = products[0] - if (!product.options.find(o => o._id === optionId)) { - throw new MedusaError( - MedusaError.Types.NOT_FOUND, - `Associated product does not have option: ${optionId}` - ) - } - const variant = await this.retrieve(variantId) if (typeof optionValue !== "string" && typeof optionValue !== "number") { @@ -350,22 +334,6 @@ class ProductVariantService extends BaseService { * @return {Promise} the result of the update operation. */ async deleteOptionValue(variantId, optionId) { - const products = await this.productService_.list({ variants: variantId }) - if (!products.length) { - throw new MedusaError( - MedusaError.Types.NOT_FOUND, - `Products with variant: ${variantId} was not found` - ) - } - - const product = products[0] - if (product.options.find(o => o._id === optionId)) { - throw new MedusaError( - MedusaError.Types.INVALID_DATA, - `Associated product has option with id: ${optionId}` - ) - } - return this.productVariantModel_.updateOne( { _id: variantId }, { $pull: { options: { option_id: optionId } } }