feat(pricing,types,utils): Move calculate pricing query to a repository + rule type validation (#5294)
This commit is contained in:
@@ -0,0 +1,17 @@
|
||||
import { getInvalidRuleAttributes } from ".."
|
||||
|
||||
describe("getInvalidRuleAttributes", function () {
|
||||
it("should return list of rule attributes that matches reserved keywords", function () {
|
||||
let result = getInvalidRuleAttributes(["shouldnotmatch"])
|
||||
expect(result).toEqual([])
|
||||
|
||||
result = getInvalidRuleAttributes(["currency_code", "shouldnotmatch"])
|
||||
expect(result).toEqual(["currency_code"])
|
||||
|
||||
result = getInvalidRuleAttributes(["currency_code", "price_list_id"])
|
||||
expect(result).toEqual(["currency_code", "price_list_id"])
|
||||
|
||||
result = getInvalidRuleAttributes(["shouldnotmatch", "quantity"])
|
||||
expect(result).toEqual(["quantity"])
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,28 @@
|
||||
import { validateRuleAttributes } from ".."
|
||||
|
||||
describe("validateRuleAttributes", function () {
|
||||
it("should return void if there are no validation errors", function () {
|
||||
let result = validateRuleAttributes(["shouldpasswithouterrors"])
|
||||
|
||||
expect(result).toEqual(undefined)
|
||||
})
|
||||
|
||||
it("should throw an error if one of the array strings matches a reserved keyword", function () {
|
||||
let error
|
||||
|
||||
try {
|
||||
validateRuleAttributes([
|
||||
"currency_code",
|
||||
"shouldnotbepresent",
|
||||
"quantity",
|
||||
"price_list_id",
|
||||
])
|
||||
} catch (e) {
|
||||
error = e
|
||||
}
|
||||
|
||||
expect(error.message).toEqual(
|
||||
"Can't create rule_attribute with reserved keywords [quantity, currency_code, price_list_id] - quantity, currency_code, price_list_id"
|
||||
)
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user