-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix sending empty order condition in discount rules (#4717)
* Fix sending empty conditions, write test to cover this case * Add changset Co-authored-by: Paweł Chyła <chyla1988@gmail.com>
- Loading branch information
1 parent
15546c5
commit a98053b
Showing
6 changed files
with
149 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"saleor-dashboard": patch | ||
--- | ||
|
||
Improve condtions filtering in discount rules to prevent sending empty conditions |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import { Condition } from "../Condition"; | ||
import { prepareCataloguePredicate } from "./preparePredicate"; | ||
|
||
describe("prepareCataloguePredicate", () => { | ||
it("should return empty object when conditions are empty", () => { | ||
const conditions: Condition[] = []; | ||
|
||
const result = prepareCataloguePredicate(conditions); | ||
|
||
expect(result).toEqual({}); | ||
}); | ||
|
||
it("should return object with filtered conditions", () => { | ||
const conditions = [ | ||
{ | ||
id: "", | ||
type: "is", | ||
value: null, | ||
}, | ||
{ | ||
id: "product", | ||
type: "is", | ||
value: [], | ||
}, | ||
{ | ||
id: "category", | ||
type: "is", | ||
value: [ | ||
{ label: "1", value: "1" }, | ||
{ label: "2", value: "2" }, | ||
], | ||
}, | ||
{ | ||
id: "collection", | ||
type: "is", | ||
value: [ | ||
{ label: "3", value: "3" }, | ||
{ label: "4", value: "4" }, | ||
], | ||
}, | ||
] as Condition[]; | ||
|
||
const result = prepareCataloguePredicate(conditions); | ||
|
||
expect(result).toEqual({ | ||
OR: [ | ||
{ | ||
categoryPredicate: { | ||
ids: ["1", "2"], | ||
}, | ||
}, | ||
{ | ||
collectionPredicate: { | ||
ids: ["3", "4"], | ||
}, | ||
}, | ||
], | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import { Condition } from "../Condition"; | ||
import { prepareOrderPredicate } from "./preparePredicate"; | ||
|
||
describe("prepareOrderPredicate", () => { | ||
it("should return empty object when conditions are empty", () => { | ||
const conditions: Condition[] = []; | ||
|
||
const result = prepareOrderPredicate(conditions); | ||
|
||
expect(result).toEqual({ | ||
discountedObjectPredicate: {}, | ||
}); | ||
}); | ||
|
||
it("should return object with filtered conditions", () => { | ||
const conditions = [ | ||
{ | ||
id: "", | ||
type: "is", | ||
value: null, | ||
}, | ||
{ | ||
id: "baseTotalPrice", | ||
type: "is", | ||
value: "1", | ||
}, | ||
{ | ||
id: "", | ||
type: "is", | ||
value: null, | ||
}, | ||
{ | ||
id: "baseSubtotalPrice", | ||
type: "range", | ||
value: { | ||
gte: "50", | ||
lte: "100", | ||
}, | ||
}, | ||
] as Condition[]; | ||
|
||
const result = prepareOrderPredicate(conditions); | ||
|
||
expect(result).toEqual({ | ||
discountedObjectPredicate: { | ||
OR: [ | ||
{ | ||
baseTotalPrice: { | ||
eq: "1", | ||
}, | ||
}, | ||
{ | ||
baseSubtotalPrice: { | ||
eq: { | ||
gte: "50", | ||
lte: "100", | ||
}, | ||
}, | ||
}, | ||
], | ||
}, | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters