Local pricing logic

Preparations

Install git

Git will be used to download example quote code we'll need.

There are multiple ways to install git. But for MAC the easiest one is to install Xcode that comes with git. To do that, just open Terminal application and type (or copy/pase) following command and hit enter key:

git --version

It will prompt you to install Xcode if you don't have it already.

More ways to install are described at getting started with git guide.

Install node

node can be installed with installer that can be downloaded at https://nodejs.org/en/download

To make sure that node is installed, type following command in Terminal:

node --version

It should show something like v14.15.4 (depending on the version you downloaded).

Install Postman

Postman is application that can be used to trigger API requests. In this case we will trigger requests to our local quote server.

Application can be downloaded and installed from https://www.postman.com/downloads

Setting up local environment

Once required software is installed, we can now setup kasko-quote-example.

Clone repository from github

We'll need to download kasko-quote-example code. We can do this via git.

Just type in following command in Terminal and hit enter key:

git clone https://github.com/kasko/kasko-quote-example.git

This should create new directory called kasko-quote-example with some of required files in it.

Install required modules

Now that we have source code cloned, we need to install required modules.

Let's navigate into that directory by running this command:

cd kasko-quote-example

and then run:

npm install

Now everything should be ready.

Updating xlsx files

Everything should now be set for you to update xlsx file.

To open current folder in Finder type following command in Terminal and hit enter key:

open .

This will open Finder in directory where kasko-quote-example was created.

Excel file is located in kasko-quote-example/excel/ folder. The name of the file should stay as is. In case you really need to change the name of the file, open kasko-quote-example/src/index.ts file in text editor, rename file in path in 4. line and save that file.

Running local quote server

Starting

To run local quote server type this command in Terminal from kasko-quote-example directory:

npm run start

This will run local server and should show something similar to this in Terminal:

This means server is up and running.

If for some reason server crashes, just run start command again.

NOTE: You don't have to restart server whenever you change xlsx file in Excel, it will automatically be reloaded.

If you encounter error that looks similar to this:

It means server crashed because it couldn't find /excel/kasko-demo.xlsx file. Make sure file is there and start server again.

Stopping

To stop server that is running, simply close Terminal or hit control+c in Terminal where server is already running.

Testing input/output data

Here we gonna use postman to send and receive data to and from local quote server.

Start up Postman application.

  • Set request address (blue) to http://localhost:3001/quotes;

  • Set up 4 fields marked as green to be the same as in screenshot above;

Red square marks "input" data (as JSON) that will be sent to quote.

Example JSON input:

{
  "data": {
    "duration": "P1Y",
    "partner_coverage": false,
    "main_module": "second"
  }
}

Every input field that should go into xlsx calculator goes under "data" object.

And response is displayed below red square when Send button is pressed. Whenever you change input data and want to see the response, click Send button in upper right corner.

Changing config options

If you want to test with custom tax or other config options that goes into xlsx calculator, you can edit these fields by opening /config.json file in kasko-quote-example and changing options.

Last updated