In this assessment, you have to calculate cart eligibility to a campaign. To do so, you have to compare profile conditions with cart data.
- Read this entire documentation
- Clone this repository
- Open src/eligibility.service.js file and edit
isEligible(cart, profile)
method. - Run
npm start ./cart-test.json ./profile-test.json
to check results - You can edit cart-test.json or profile-test.json for more tests.
You are free to use internet (Google, StackOverflow, ...), to ask question or do whatever you want to pass this assessment.
💡 Advice: be lean. Develop one condition at a time.
A cart represent an online transaction. It has many parameters such as cartId
, shopperId
, products
, ...
Cart example:
{
"cartId": "cart-id",
"shopperId": "shopper-id",
"date": "2021-10-06T18:35:42.000Z",
"totalAti": 99.80,
"promoCode": "voucher-42",
"products": [
{
"productId": "5449000054227",
"quantity": 20,
"unitPriceAti": 2.5,
"totalPriceAti": 50
},
{
"productId": "3099873045369",
"quantity": 2,
"unitPriceAti": 24.90,
"totalPriceAti": 49.80
}
]
}
Profile are a list of key-conditions values (eg: {key1: condition1, key2: condition2}
). If all the conditions are fulfilled then the cart is eligible.
To validate a condition, you have to compare the condition the value of the same key in the cart. If there is some "." in the key, compare to the value of the sub-object (eg: { "products.productId": condition }
in profile means to check { products: [{ productId: value }] }
in cart).
Available conditions:
- Basic condition (eg:
total: 20
) matches whentotal == 20
; gt
,lt
,gte
,lte
matches respectively when cart value is greater, lower, greater or equal, lower or equal;in
(followed by an array) matches when cart value is in the following array;and
(follower by at least two conditions) matches when every following conditions match;or
(follower by at least two conditions) matches when at least one of the following conditions matches.
{ total: 20 }
matches { total: "20" }
and { total: 20.0 }
.
Profile example:
{
"shopperId": "shopper-id",
"totalAti": {
"gt": 50
},
"products.productId": {
"in": ["5449000054227"]
},
"date": {
"and": {
"gt": "2021-01-01T00:00:00.000Z",
"lt": "2021-12-31T23:59:59.000Z"
}
}
}
Profile:
{
"shopperId": "eligible-shopper-id",
"totalAti": {
"gt": 50
}
}
Eligible cart:
{
"cartId": "eligible-cart-id",
"shopperId": "eligible-shopper-id",
"totalAti": 100
}
Not eligible cart:
{
"cartId": "not-eligible-cart-id",
"shopperId": "not-eligible-shopper-id",
"totalAti": 25
}