Skip to content

peyman-mashhadi/peyman-mashhadi-cognigy-challenge

Repository files navigation

LinkedIn

Table of Contents
  1. About The Project
  2. Getting Started
  3. Endpoints
  4. Running Postman tests
  5. Contact

About The Project

It's a Node.JS based application that uses the following technologies:

  • Typescript: v4.5.5
  • Docker: v20.10.8
  • Docker Compose: v2.0.0
  • Node.JS: latest
  • TSLint: v6.1.3
  • Mongoose: v6.2.2
  • Express: v4.17.3
  • AJV: v8.10.0

It containerized project packages on top of a public NodeJS Docker-base-image. Docker copmose file uses the official MongoDB docker image.

(back to top)

Built With

(back to top)

Getting Started

Instructions on setting up the project locally. To get a local copy up and running follow these steps.

Running the project

  1. Clone the repo
    git clone https://github.com/peyman-mashhadi/peyman-mashhadi-cognigy-challenge.git
  2. Install NPM packages
    npm install
  3. Run the server
    npm run start
  4. Local server will be run on:
     http://localhost:4000
    
  5. Set x-api-key from the value provided in .env into your HTTP requestr headers

Running the tests

To run the tests:

npm run test
  • Jest preset is used to run MongoDB memory server

npm-run-test-result

(back to top)

Endpoints

  1. Create a Car sample:
    curl --location --request POST 'localhost:4000/car' \
    --header 'x-api-key: cognigy' \
    --header 'Content-Type: application/json' \
    --data-raw '{
        "brand": "BMW",
        "model": "Series 7 750i xDrive",
        "registrationYear": 2021,
        "price": 23300,
        "seats": 4,
        "color": "black",
        "imgUrl": "https://i.ebayimg.com/00/s/MTIwMFgxNjAw/z/KJ4AAOSwQ0Zh7npP/$_86.jpg"
    }'
    
  2. Update a Car sample:
    curl --location --request PUT 'localhost:4000/car/6212b45c1b6a0de8182140bf' \
    --header 'x-api-key: cognigy' \
    --header 'Content-Type: application/json' \
    --data-raw '{
        "price": 45000
    }'
    
  3. Find a Car Sample:
    curl --location --request GET 'localhost:4000/car/6212b45c1b6a0de8182140bf' \
    --header 'x-api-key: cognigy'
    
  4. Get Cars metadata:
    curl --location --request GET 'localhost:4000/car' \
    --header 'x-api-key: cognigy'
    
  5. Remove a Car:
    curl --location --request DELETE 'localhost:4000/car/6212b45c1b6a0de8182140bf' \
    --header 'x-api-key: cognigy'
    
  6. Bulk insert Cars Sample:
    curl --location --request POST 'localhost:4000/cars' \
    --header 'x-api-key: cognigy' \
    --header 'Content-Type: application/json' \
    --data-raw '[
      {
        "brand": "BMW",
        "model": "320i Sedan Advantage LED",
        "registrationYear": 2012,
        "price": 31000,
        "seats": 4,
        "color": "red",
        "imgUrl":
          "https://i.ebayimg.com/00/s/MTIwMFgxNjAw/z/7xoAAOSwmvBhof98/$_86.jpg"
      },
      {
        "brand": "BMW",
        "model": "420xi Gran Coupe Steptronic",
        "registrationYear": 2021,
        "price": 21000,
        "seats": 4,
        "color": "black",
        "imgUrl":
          "https://i.ebayimg.com/00/s/MTA2NlgxNjAw/z/w4cAAOSw0~JiDOly/$_86.jpg"
      },
      {
        "brand": "BMW",
        "model": "Series 7 750i xDrive",
        "registrationYear": 2021,
        "price": 23300,
        "seats": 4,
        "color": "black",
        "imgUrl":
          "https://i.ebayimg.com/00/s/MTIwMFgxNjAw/z/KJ4AAOSwQ0Zh7npP/$_86.jpg"
      },
      {
        "brand": "AUDI",
        "model": "A3 1.4TGi G-TRON S-LiNE",
        "registrationYear": 2020,
        "price": 50000,
        "seats": 4,
        "color": "black",
        "imgUrl":
          "https://i.ebayimg.com/00/s/MTIwMFgxNjAw/z/XcEAAOSwNDpiBTYm/$_57.jpg"
      },
      {
        "brand": "AUDI",
        "model": "TT RS Coupé S tr 40",
        "registrationYear": 2017,
        "price": 33400,
        "seats": 4,
        "color": "blue",
        "imgUrl":
          "https://i.ebayimg.com/00/s/NzY4WDEwMjQ=/z/aE0AAOSwD5phpKqN/$_86.jpg"
      },
      {
        "brand": "AUDI",
        "model": "A4 2.0 TDI",
        "registrationYear": 2012,
        "price": 44430,
        "seats": 4,
        "color": "white",
        "imgUrl":
          "https://i.ebayimg.com/00/s/ODAwWDExOTk=/z/xPMAAOSwVBdhpznl/$_57.jpg"
      },
      {
        "brand": "VOLKSWAGEN",
        "model": "Golf VI Match*1.4 16V",
        "registrationYear": 2017,
        "price": 41000,
        "seats": 4,
        "color": "grey",
        "imgUrl":
          "https://i.ebayimg.com/00/s/MTIwMFgxNjAw/z/rk8AAOSwIlVh~PJj/$_27.jpg"
      },
      {
        "brand": "VOLKSWAGEN",
        "model": "Golf Variant VII Cup BMT",
        "registrationYear": 2020,
        "price": 24000,
        "seats": 4,
        "color": "black",
        "imgUrl":
          "https://i.ebayimg.com/00/s/MTA4MFgxNDQw/z/vMkAAOSwBuhh8JWf/$_27.jpg"
      }
    ]'
    

(back to top)

Running Postman tests

To run end2end tests using Postman, you can import the test collection into your postman:

  • postman-tests/cognigy.postman_collection.json

The test results would be like:

postman-test-results

Contact

Peyman Mashhadi - [email protected]

(back to top)

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages