mnmajd / tech-assessment

Lucky Cart Technical Assessment

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Lucky Cart – Technical Assessment

In this assessment, you have to calculate cart eligibility to a campaign. To do so, you have to compare profile conditions with cart data.

How to do the assessment

  1. Read this entire documentation
  2. Clone this repository
  3. Open src/eligibility.service.js file and edit isEligible(cart, profile) method.
  4. Run npm start ./cart-test.json ./profile-test.json to check results
  5. 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.

Carts

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
    }
  ]
}

Profiles

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 when total == 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.

⚠️ Conditions are typeless! { 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"
    }
  }
}

Examples

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
}

About

Lucky Cart Technical Assessment


Languages

Language:JavaScript 100.0%