# ows-vectororder

This micro-service provides the backend for the Direct Delivery search and
Vector order creation. There are different endpoint categories that handle:

- Direct Delivery V2 search requests
- encoding order CRUD operations
- eligibility checks for encoding order jobs
- possible input field values for order search and creation forms

## Getting Started

Ensure you have standard docker and AWS support set up locally.

### Permissions

Access to the `vector` application family is necessary to connect to the
dd-search elasticsearch instances.

### Configuration

Copy .env.shadow to .env and add the appropriate environment variables for your environment.

`cp .env.shadow .env`

Set the configurations. Note that the following are the minimum required environment variables to run this application locally.

```bash
Environment=[dev,test,qa]
```

### Running Locally

Run service inside a dev container. Before spinning up the container, you first need to:

1. Ensure you have [ECR access](https://www.notion.so/AWS-Access-f841b9dd815d4443a80e96a86c92cd2f#7a6624c58c6642abaecd804e5f25c820) set up.
2. Enable AWS access to the dev or prod account with [awsume](https://www.notion.so/AWS-Access-f841b9dd815d4443a80e96a86c92cd2f#beaec95488ad4473899a26a2b8cf603f).

Then, spin up the dev container:

```sh
docker compose up --build --remove-orphans dev
```

This will spin up a dev container, install/copy all required dependencies and app code inside the dev container, and start the application.

You can access the application at:

```
localhost:{{PORT}}
```

Sanity check that the container is up and running by hitting the healthcheck endpoint:

```
localhost:{{PORT}}/{{healthcheck-endpoint}}
```

Test away!

__⚠️ Note:__ Ensure you are on the VPN.

When you are done testing out your _amazing_ code, make sure to stop any running containers:

```bash
docker compose down --remove-orphans
```

### Testing


To run tests within a Docker container, you first must ensure steps 1 and 2 from `1️⃣ Option 1` in `Running Locally` are complete, and ensure you are on the VPN.

To run unit tests and linting, run:

```bash
docker compose run --build --rm unit-lint
```

Once you are finished unit testing, you can stop the test container with:

```bash
docker compose down --remove-orphans
```

### Updating Snapshots

Some unit tests use [syrupy](https://github.com/syrupy-project/syrupy) for snapshot assertions. When you intentionally change behaviour that affects snapshot output, regenerate them with `--snapshot-update`.

To update all unit test snapshots:

```bash
docker compose run --rm --build update-snapshots
```

Review the diff in the generated `.ambr` files before committing — they live alongside the test files and should be committed with your changes.

### Integration Testing

To run integration tests inside a container, run:

```bash
docker compose run --build --rm integration
```

You can stop the integration test container by running:

```bash
docker compose down --remove-orphans
```

### Running Signed Elasticsearch Requests

Connection to the AWS managed ES domains is handled with signed requests
proxied through the `aws-es-proxy` docker compose service. Bringing the
main `dev` container up will also bring that container up and automatically
proxy requests through it. You can also view the kibana UI by navigating to
[http://localhost:5001/_plugin/kibana](http://localhost:5001/_plugin/kibana) in your
browser.

### Format Code

To format code to conform to styleguide, run:

```bash
docker compose run --build --rm format
```

### Update lockfile

To update the lockfile, run:

```bash
docker compose run --build -rm update-lockfile
```

### Clean up
You can clean up the containers by running:

```bash
docker compose down --remove-orphans
```
