Remove ProductService dependency from ProductVariantService

This commit is contained in:
Sebastian Rindom
2020-03-30 17:17:25 +02:00
parent 808d0912e3
commit 51c97abec9
3 changed files with 0 additions and 80 deletions

View File

@@ -1,6 +1,3 @@
module.exports = {
testEnvironment: "node",
testPathIgnorePatterns: [
"mocks"
]
}

View File

@@ -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", () => {

View File

@@ -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 } } }