feat(types,utils): added promotion create with rules and application target rules (#5957)
* feat(types,utils): added promotion create with rules * chore: add rules to promotion and application method * chore: use common code for rule and values * chore: address pr reviews * chore: fix test
This commit is contained in:
@@ -0,0 +1,61 @@
|
||||
import { isPresent } from "../is-present"
|
||||
|
||||
describe("isPresent", function () {
|
||||
it("should return true or false for different types of data", function () {
|
||||
const expectations = [
|
||||
{
|
||||
input: null,
|
||||
output: false,
|
||||
},
|
||||
{
|
||||
input: undefined,
|
||||
output: false,
|
||||
},
|
||||
{
|
||||
input: "Testing",
|
||||
output: true,
|
||||
},
|
||||
{
|
||||
input: "",
|
||||
output: false,
|
||||
},
|
||||
{
|
||||
input: {},
|
||||
output: false,
|
||||
},
|
||||
{
|
||||
input: { test: 1 },
|
||||
output: true,
|
||||
},
|
||||
{
|
||||
input: [],
|
||||
output: false,
|
||||
},
|
||||
{
|
||||
input: [{ test: 1 }],
|
||||
output: true,
|
||||
},
|
||||
{
|
||||
input: new Map([["test", "test"]]),
|
||||
output: true,
|
||||
},
|
||||
{
|
||||
input: new Map([]),
|
||||
output: false,
|
||||
},
|
||||
|
||||
{
|
||||
input: new Set(["test"]),
|
||||
output: true,
|
||||
},
|
||||
{
|
||||
input: new Set([]),
|
||||
output: false,
|
||||
},
|
||||
]
|
||||
|
||||
expectations.forEach((expectation) => {
|
||||
expect(isPresent(expectation.input)).toEqual(expectation.output)
|
||||
})
|
||||
})
|
||||
})
|
||||
@@ -8,14 +8,15 @@ export * from "./deep-equal-obj"
|
||||
export * from "./errors"
|
||||
export * from "./generate-entity-id"
|
||||
export * from "./get-config-file"
|
||||
export * from "./get-iso-string-from-date"
|
||||
export * from "./group-by"
|
||||
export * from "./handle-postgres-database-error"
|
||||
export * from "./is-date"
|
||||
export * from "./is-defined"
|
||||
export * from "./is-email"
|
||||
export * from "./is-object"
|
||||
export * from "./is-present"
|
||||
export * from "./is-string"
|
||||
export * from "./get-iso-string-from-date"
|
||||
export * from "./lower-case-first"
|
||||
export * from "./map-object-to"
|
||||
export * from "./medusa-container"
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
import { isDefined } from "./is-defined"
|
||||
import { isObject } from "./is-object"
|
||||
import { isString } from "./is-string"
|
||||
|
||||
export function isPresent(value: any): boolean {
|
||||
if (!isDefined(value) || value === null) {
|
||||
return false
|
||||
}
|
||||
|
||||
if (isString(value) || Array.isArray(value)) {
|
||||
return value.length > 0
|
||||
}
|
||||
|
||||
if (value instanceof Map || value instanceof Set) {
|
||||
return value.size > 0
|
||||
}
|
||||
|
||||
if (isObject(value)) {
|
||||
return Object.keys(value).length > 0
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
Reference in New Issue
Block a user