chore(medusa): use batch/add and batch/remove endpoints for promotion rules (#6701)

This commit is contained in:
Riqwan Thamir
2024-03-14 19:07:48 +01:00
committed by GitHub
parent c384ede3b1
commit 7be0a2cf6d
10 changed files with 208 additions and 213 deletions

View File

@@ -44,11 +44,11 @@ medusaIntegrationTestRunner({
})
})
describe("POST /admin/promotions/:id/rules", () => {
describe("POST /admin/promotions/:id/rules/batch/add", () => {
it("should throw error when required params are missing", async () => {
const { response } = await api
.post(
`/admin/promotions/${standardPromotion.id}/rules`,
`/admin/promotions/${standardPromotion.id}/rules/batch/add`,
{
rules: [
{
@@ -72,7 +72,7 @@ medusaIntegrationTestRunner({
it("should throw error when promotion does not exist", async () => {
const { response } = await api
.post(
`/admin/promotions/does-not-exist/rules`,
`/admin/promotions/does-not-exist/rules/batch/add`,
{
rules: [
{
@@ -95,7 +95,7 @@ medusaIntegrationTestRunner({
it("should add rules to a promotion successfully", async () => {
const response = await api.post(
`/admin/promotions/${standardPromotion.id}/rules`,
`/admin/promotions/${standardPromotion.id}/rules/batch/add`,
{
rules: [
{
@@ -129,11 +129,11 @@ medusaIntegrationTestRunner({
})
})
describe("POST /admin/promotions/:id/target-rules", () => {
describe("POST /admin/promotions/:id/target-rules/batch/add", () => {
it("should throw error when required params are missing", async () => {
const { response } = await api
.post(
`/admin/promotions/${standardPromotion.id}/target-rules`,
`/admin/promotions/${standardPromotion.id}/target-rules/batch/add`,
{
rules: [
{
@@ -157,7 +157,7 @@ medusaIntegrationTestRunner({
it("should throw error when promotion does not exist", async () => {
const { response } = await api
.post(
`/admin/promotions/does-not-exist/target-rules`,
`/admin/promotions/does-not-exist/target-rules/batch/add`,
{
rules: [
{
@@ -180,7 +180,7 @@ medusaIntegrationTestRunner({
it("should add target rules to a promotion successfully", async () => {
const response = await api.post(
`/admin/promotions/${standardPromotion.id}/target-rules`,
`/admin/promotions/${standardPromotion.id}/target-rules/batch/add`,
{
rules: [
{
@@ -216,11 +216,11 @@ medusaIntegrationTestRunner({
})
})
describe("POST /admin/promotions/:id/buy-rules", () => {
describe("POST /admin/promotions/:id/buy-rules/batch/add", () => {
it("should throw error when required params are missing", async () => {
const { response } = await api
.post(
`/admin/promotions/${standardPromotion.id}/buy-rules`,
`/admin/promotions/${standardPromotion.id}/buy-rules/batch/add`,
{
rules: [
{
@@ -244,7 +244,7 @@ medusaIntegrationTestRunner({
it("should throw error when promotion does not exist", async () => {
const { response } = await api
.post(
`/admin/promotions/does-not-exist/buy-rules`,
`/admin/promotions/does-not-exist/buy-rules/batch/add`,
{
rules: [
{
@@ -268,7 +268,7 @@ medusaIntegrationTestRunner({
it("should throw an error when trying to add buy rules to a standard promotion", async () => {
const { response } = await api
.post(
`/admin/promotions/${standardPromotion.id}/buy-rules`,
`/admin/promotions/${standardPromotion.id}/buy-rules/batch/add`,
{
rules: [
{
@@ -307,7 +307,7 @@ medusaIntegrationTestRunner({
})
const response = await api.post(
`/admin/promotions/${buyGetPromotion.id}/buy-rules`,
`/admin/promotions/${buyGetPromotion.id}/buy-rules/batch/add`,
{
rules: [
{
@@ -343,13 +343,14 @@ medusaIntegrationTestRunner({
})
})
describe("DELETE /admin/promotions/:id/rules", () => {
describe("POST /admin/promotions/:id/rules/batch/remove", () => {
it("should throw error when required params are missing", async () => {
const { response } = await api
.delete(`/admin/promotions/${standardPromotion.id}/rules`, {
...adminHeaders,
data: {},
})
.post(
`/admin/promotions/${standardPromotion.id}/rules/batch/remove`,
{},
adminHeaders
)
.catch((e) => e)
expect(response.status).toEqual(400)
@@ -362,10 +363,11 @@ medusaIntegrationTestRunner({
it("should throw error when promotion does not exist", async () => {
const { response } = await api
.delete(`/admin/promotions/does-not-exist/rules`, {
...adminHeaders,
data: { rule_ids: ["test-rule-id"] },
})
.post(
`/admin/promotions/does-not-exist/rules/batch/remove`,
{ rule_ids: ["test-rule-id"] },
adminHeaders
)
.catch((e) => e)
expect(response.status).toEqual(404)
@@ -376,14 +378,11 @@ medusaIntegrationTestRunner({
})
it("should remove rules from a promotion successfully", async () => {
const response = await api.delete(
`/admin/promotions/${standardPromotion.id}/rules`,
{
...adminHeaders,
data: { rule_ids: [standardPromotion.rules[0].id] },
}
const response = await api.post(
`/admin/promotions/${standardPromotion.id}/rules/batch/remove`,
{ rule_ids: [standardPromotion.rules[0].id] },
adminHeaders
)
expect(response.status).toEqual(200)
expect(response.data).toEqual({
ids: [standardPromotion.rules[0].id],
@@ -400,13 +399,14 @@ medusaIntegrationTestRunner({
})
})
describe("DELETE /admin/promotions/:id/target-rules", () => {
describe("POST /admin/promotions/:id/target-rules/batch/remove", () => {
it("should throw error when required params are missing", async () => {
const { response } = await api
.delete(`/admin/promotions/${standardPromotion.id}/target-rules`, {
...adminHeaders,
data: {},
})
.post(
`/admin/promotions/${standardPromotion.id}/target-rules/batch/remove`,
{},
adminHeaders
)
.catch((e) => e)
expect(response.status).toEqual(400)
@@ -419,10 +419,11 @@ medusaIntegrationTestRunner({
it("should throw error when promotion does not exist", async () => {
const { response } = await api
.delete(`/admin/promotions/does-not-exist/target-rules`, {
...adminHeaders,
data: { rule_ids: ["test-rule-id"] },
})
.post(
`/admin/promotions/does-not-exist/target-rules/batch/remove`,
{ rule_ids: ["test-rule-id"] },
adminHeaders
)
.catch((e) => e)
expect(response.status).toEqual(404)
@@ -434,12 +435,10 @@ medusaIntegrationTestRunner({
it("should remove target rules from a promotion successfully", async () => {
const ruleId = standardPromotion.application_method.target_rules[0].id
const response = await api.delete(
`/admin/promotions/${standardPromotion.id}/target-rules`,
{
...adminHeaders,
data: { rule_ids: [ruleId] },
}
const response = await api.post(
`/admin/promotions/${standardPromotion.id}/target-rules/batch/remove`,
{ rule_ids: [ruleId] },
adminHeaders
)
expect(response.status).toEqual(200)
@@ -458,13 +457,14 @@ medusaIntegrationTestRunner({
})
})
describe("DELETE /admin/promotions/:id/buy-rules", () => {
describe("POST /admin/promotions/:id/buy-rules/batch/remove", () => {
it("should throw error when required params are missing", async () => {
const { response } = await api
.delete(`/admin/promotions/${standardPromotion.id}/buy-rules`, {
...adminHeaders,
data: {},
})
.post(
`/admin/promotions/${standardPromotion.id}/buy-rules/batch/remove`,
{},
adminHeaders
)
.catch((e) => e)
expect(response.status).toEqual(400)
@@ -477,10 +477,11 @@ medusaIntegrationTestRunner({
it("should throw error when promotion does not exist", async () => {
const { response } = await api
.delete(`/admin/promotions/does-not-exist/buy-rules`, {
...adminHeaders,
data: { rule_ids: ["test-rule-id"] },
})
.post(
`/admin/promotions/does-not-exist/buy-rules/batch/remove`,
{ rule_ids: ["test-rule-id"] },
adminHeaders
)
.catch((e) => e)
expect(response.status).toEqual(404)
@@ -508,12 +509,10 @@ medusaIntegrationTestRunner({
})
const ruleId = buyGetPromotion!.application_method!.buy_rules![0].id
const response = await api.delete(
`/admin/promotions/${buyGetPromotion.id}/buy-rules`,
{
...adminHeaders,
data: { rule_ids: [ruleId] },
}
const response = await api.post(
`/admin/promotions/${buyGetPromotion.id}/buy-rules/batch/remove`,
{ rule_ids: [ruleId] },
adminHeaders
)
expect(response.status).toEqual(200)