feat(utils,types): added item/shipping adjustments for order/items/shipping_methods (#6050)

what:

- adds compute actions for the following cases:
  - items => each & across
  - shipping_method => each & across
  - order
- adds a remove compute actions when code is no longer present in adjustments array

RESOLVES CORE-1625
RESOLVES CORE-1626
RESOLVES CORE-1627
RESOLVES CORE-1628
RESOLVES CORE-1585
This commit is contained in:
Riqwan Thamir
2024-01-12 13:00:06 +00:00
committed by GitHub
parent 192bc336cc
commit b782d3bcb7
24 changed files with 2638 additions and 81 deletions
@@ -99,63 +99,6 @@ describe("Promotion Service", () => {
)
})
it("should create a promotion with order application method with rules successfully", async () => {
const [createdPromotion] = await service.create([
{
code: "PROMOTION_TEST",
type: PromotionType.STANDARD,
application_method: {
type: "fixed",
target_type: "order",
value: "100",
target_rules: [
{
attribute: "product_id",
operator: "eq",
values: ["prod_tshirt"],
},
],
},
},
])
const [promotion] = await service.list(
{
id: [createdPromotion.id],
},
{
relations: [
"application_method",
"application_method.target_rules.values",
],
}
)
expect(promotion).toEqual(
expect.objectContaining({
code: "PROMOTION_TEST",
is_automatic: false,
type: "standard",
application_method: expect.objectContaining({
type: "fixed",
target_type: "order",
value: 100,
target_rules: [
expect.objectContaining({
attribute: "product_id",
operator: "eq",
values: expect.arrayContaining([
expect.objectContaining({
value: "prod_tshirt",
}),
]),
}),
],
}),
})
)
})
it("should throw error when creating an item application method without allocation", async () => {
const error = await service
.create([
@@ -164,7 +107,7 @@ describe("Promotion Service", () => {
type: PromotionType.STANDARD,
application_method: {
type: "fixed",
target_type: "item",
target_type: "items",
value: "100",
},
},
@@ -172,7 +115,7 @@ describe("Promotion Service", () => {
.catch((e) => e)
expect(error.message).toContain(
"application_method.allocation should be either 'across OR each' when application_method.target_type is either 'shipping OR item'"
"application_method.allocation should be either 'across OR each' when application_method.target_type is either 'shipping_methods OR items'"
)
})
@@ -185,7 +128,7 @@ describe("Promotion Service", () => {
application_method: {
type: "fixed",
allocation: "each",
target_type: "shipping",
target_type: "shipping_methods",
value: "100",
},
},
@@ -197,6 +140,33 @@ describe("Promotion Service", () => {
)
})
it("should throw error when creating an order application method with rules", async () => {
const error = await service
.create([
{
code: "PROMOTION_TEST",
type: PromotionType.STANDARD,
application_method: {
type: "fixed",
target_type: "order",
value: "100",
target_rules: [
{
attribute: "product_id",
operator: "eq",
values: ["prod_tshirt"],
},
],
},
},
])
.catch((e) => e)
expect(error.message).toContain(
"Target rules for application method with target type (order) is not allowed"
)
})
it("should create a promotion with rules successfully", async () => {
const [createdPromotion] = await service.create([
{
@@ -390,7 +360,7 @@ describe("Promotion Service", () => {
type: PromotionType.STANDARD,
application_method: {
type: "fixed",
target_type: "item",
target_type: "items",
allocation: "across",
value: "100",
},
@@ -424,7 +394,7 @@ describe("Promotion Service", () => {
type: PromotionType.STANDARD,
application_method: {
type: "fixed",
target_type: "item",
target_type: "items",
allocation: "each",
value: "100",
max_quantity: 500,
@@ -483,7 +453,7 @@ describe("Promotion Service", () => {
.catch((e) => e)
expect(error.message).toContain(
`application_method.target_type should be one of order, shipping, item`
`application_method.target_type should be one of order, shipping_methods, items`
)
error = await service
@@ -604,7 +574,7 @@ describe("Promotion Service", () => {
type: PromotionType.STANDARD,
application_method: {
type: "fixed",
target_type: "item",
target_type: "items",
allocation: "each",
value: "100",
max_quantity: 500,
@@ -676,7 +646,7 @@ describe("Promotion Service", () => {
type: PromotionType.STANDARD,
application_method: {
type: "fixed",
target_type: "item",
target_type: "items",
allocation: "each",
value: "100",
max_quantity: 500,
@@ -760,7 +730,7 @@ describe("Promotion Service", () => {
],
application_method: {
type: "fixed",
target_type: "item",
target_type: "items",
allocation: "each",
value: "100",
max_quantity: 500,
@@ -821,7 +791,7 @@ describe("Promotion Service", () => {
type: PromotionType.STANDARD,
application_method: {
type: "fixed",
target_type: "item",
target_type: "items",
allocation: "each",
value: "100",
max_quantity: 500,