fix(medusa): Remove unsupported Discount endpoints (#1367)

This commit is contained in:
Oliver Windall Juhl authored and GitHub committed 2022-04-19 13:39:49 +02:00
1 parent 95ea8fa385
commit 9acee2799e
9 files changed
+20357 -23498

No files matched your search

@@ -1,62 +0,0 @@
import { IdMap } from "medusa-test-utils"
import { request } from "../../../../../helpers/test-request"
import { DiscountServiceMock } from "../../../../../services/__mocks__/discount"
describe("POST /admin/discounts/:discount_id/products/:product_id", () => {
describe("successful addition", () => {
let subject
beforeAll(async () => {
subject = await request(
"POST",
`/admin/discounts/${IdMap.getId("total10")}/products/${IdMap.getId(
"testVariant"
)}`,
{
adminSession: {
jwt: {
userId: IdMap.getId("admin_user"),
},
},
}
)
})
it("returns 200", () => {
expect(subject.status).toEqual(200)
})
it("calls service retrieve", () => {
expect(DiscountServiceMock.retrieve).toHaveBeenCalledTimes(1)
expect(DiscountServiceMock.retrieve).toHaveBeenCalledWith(
IdMap.getId("total10"),
{
select: [
"id",
"code",
"is_dynamic",
"is_disabled",
"rule_id",
"parent_discount_id",
"usage_limit",
"usage_count",
"starts_at",
"ends_at",
"created_at",
"updated_at",
"deleted_at",
"metadata",
"valid_duration",
],
relations: ["rule", "parent_discount", "regions", "rule.conditions"],
}
)
expect(DiscountServiceMock.addValidProduct).toHaveBeenCalledTimes(1)
expect(DiscountServiceMock.addValidProduct).toHaveBeenCalledWith(
IdMap.getId("total10"),
IdMap.getId("testVariant")
)
})
})
})
@@ -1,71 +0,0 @@
import { IdMap } from "medusa-test-utils"
import { request } from "../../../../../helpers/test-request"
import { DiscountServiceMock } from "../../../../../services/__mocks__/discount"
const defaultFields = [
"id",
"code",
"is_dynamic",
"is_disabled",
"rule_id",
"parent_discount_id",
"usage_limit",
"usage_count",
"starts_at",
"ends_at",
"created_at",
"updated_at",
"deleted_at",
"metadata",
"valid_duration",
]
const defaultRelations = [
"rule",
"parent_discount",
"regions",
"rule.conditions",
]
describe("DELETE /admin/discounts/:discount_id/products/:product_id", () => {
describe("successful addition", () => {
let subject
beforeAll(async () => {
subject = await request(
"DELETE",
`/admin/discounts/${IdMap.getId("total10")}/products/${IdMap.getId(
"testVariant"
)}`,
{
adminSession: {
jwt: {
userId: IdMap.getId("admin_user"),
},
},
}
)
})
it("returns 200", () => {
expect(subject.status).toEqual(200)
})
it("calls service retrieve", () => {
expect(DiscountServiceMock.retrieve).toHaveBeenCalledTimes(1)
expect(DiscountServiceMock.retrieve).toHaveBeenCalledWith(
IdMap.getId("total10"),
{
select: defaultFields,
relations: defaultRelations,
}
)
expect(DiscountServiceMock.removeValidProduct).toHaveBeenCalledTimes(1)
expect(DiscountServiceMock.removeValidProduct).toHaveBeenCalledWith(
IdMap.getId("total10"),
IdMap.getId("testVariant")
)
})
})
})
@@ -1,37 +0,0 @@
import { defaultAdminDiscountsFields, defaultAdminDiscountsRelations } from "."
import { Discount } from "../../../.."
import DiscountService from "../../../../services/discount"
/**
* @oas [post] /discounts/{id}/products/{product_id}
* operationId: "PostDiscountsDiscountProductsProduct"
* summary: "Adds Product availability"
* description: "Adds a Product to the list of Products that a Discount can be used for."
* x-authenticated: true
* parameters:
* - (path) id=* {string} The id of the Discount.
* - (path) product_id=* {string} The id of the Product.
* tags:
* - Discount
* responses:
* 200:
* description: OK
* content:
* application/json:
* schema:
* properties:
* discount:
* $ref: "#/components/schemas/discount"
*/
export default async (req, res) => {
const { discount_id, product_id } = req.params
const discountService: DiscountService = req.scope.resolve("discountService")
await discountService.addValidProduct(discount_id, product_id)
const discount: Discount = await discountService.retrieve(discount_id, {
select: defaultAdminDiscountsFields,
relations: defaultAdminDiscountsRelations,
})
res.status(200).json({ discount })
}
@@ -39,16 +39,6 @@ export default (app) => {
middlewares.wrap(require("./delete-dynamic-code").default)
)
// Discount valid variants management
route.post(
"/:discount_id/products/:product_id",
middlewares.wrap(require("./add-valid-product").default)
)
route.delete(
"/:discount_id/products/:product_id",
middlewares.wrap(require("./remove-valid-product").default)
)
// Discount region management
route.post(
"/:discount_id/regions/:region_id",
@@ -98,7 +88,6 @@ export type AdminDiscountsListRes = PaginatedResponse & {
}
export * from "./add-region"
export * from "./add-valid-product"
export * from "./create-discount"
export * from "./create-dynamic-code"
export * from "./delete-discount"
@@ -107,5 +96,4 @@ export * from "./get-discount"
export * from "./get-discount-by-code"
export * from "./list-discounts"
export * from "./remove-region"
export * from "./remove-valid-product"
export * from "./update-discount"
@@ -1,36 +0,0 @@
import { defaultAdminDiscountsFields, defaultAdminDiscountsRelations } from "."
import DiscountService from "../../../../services/discount"
/**
* @oas [delete] /discounts/{id}/products/{product_id}
* operationId: "DeleteDiscountsDiscountProductsProduct"
* summary: "Remove Product availability"
* description: "Removes a Product from the list of Products that a Discount can be used for."
* x-authenticated: true
* parameters:
* - (path) id=* {string} The id of the Discount.
* - (path) product_id=* {string} The id of the Product.
* tags:
* - Discount
* responses:
* 200:
* description: OK
* content:
* application/json:
* schema:
* properties:
* discount:
* $ref: "#/components/schemas/discount"
*/
export default async (req, res) => {
const { discount_id, product_id } = req.params
const discountService: DiscountService = req.scope.resolve("discountService")
await discountService.removeValidProduct(discount_id, product_id)
const discount = await discountService.retrieve(discount_id, {
select: defaultAdminDiscountsFields,
relations: defaultAdminDiscountsRelations,
})
res.status(200).json({ discount })
}