# 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:

```sh
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](https://git-scm.com/book/en/v2/Getting-Started-Installing-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`:

```sh
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:

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

This should create new directory called [`kasko-quote-example`](https://github.com/kasko/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:

```sh
cd kasko-quote-example
```

and then run:

```sh
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:

```sh
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:

```sh
npm run start
```

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

![server started](https://1976828758-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fxa5zP0ggbUWVqZL79DQK%2Fuploads%2Fgit-blob-3bf22bc8b682f370780dc8c65751518687ae31b9%2Fkasko-quote-example-server.png?alt=media)

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:

![server errored](https://1976828758-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fxa5zP0ggbUWVqZL79DQK%2Fuploads%2Fgit-blob-7fd070604e569b2c371aa51c45e0bbefaa596956%2Fkasko-quote-example-error.png?alt=media)

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.

![Postman screenshot](https://1976828758-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fxa5zP0ggbUWVqZL79DQK%2Fuploads%2Fgit-blob-6ab23e5ae2d09d7016816cc6c0f03c85f726771d%2Fpostman-quote.png?alt=media)

* 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](https://www.json.org/json-en.html)) that will be sent to quote.

Example JSON input:

```json
{
  "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.
