# Running Abacus cucumber test suites against a docker stack

If you're a developer or automation engineer and you want to run the
Royalties cucumber tests against a local instance of the application
running via Docker Compose, this is for you.

## Requirements

1. QA/Prod AWS EC Pull access for the resources listed
   in our [docker-compose.yaml](./docker-compose.yaml):

2. A user and password for read access to the QA *art_relations* database

3. `docker` and `docker-compose`

4. AbacusProfile user

## Setup

### Prepare your environment

1. Create your .env file

    ```bash
    cp .env.shadow .env
    ```

2. Set the following variables in .env, replacing
    the qa art_relations credentials with your own.

    ```sh
    COMPOSE_FILE=docker_compose/royalties/docker-compose.yaml
    MYSQL_DB_HOST=127.0.0.1
    MYSQL_DB_USER=royalties
    MYSQL_DB_PASS=1234
    MYSQL_DB_NAME=royalty_accounting
    MYSQL_DB_PORT=6007
    QA_MYSQL_USER={QA art_relations user}
    QA_MYSQL_PASSWORD={QA art_relations password}
    ```

3. Generate credentials for the Orchard's QA/Prod AWS account

    Use one of the **AWS session generation scripts** to load the
    credentials and token into your session. For example,
    [generate.sh](https://github.com/theorchard/collab/blob/master/jfidlow/aws_mfa_session/generate.sh)

## Dockerized Test Stack

You can start and stop the the test stack via `make` commands and get
insight into what's happening in the containers with `docker-compose`

```bash
# Authenticate with VAPI and start up the full test stack
make local_stack

# To stop the local stack
make docker_down

# See the names, statuses, ports, etc of the running containers
docker-compose ps

# View the logs from containers, optionally specifying a service name
docker-compose logs [service]

```

After running `make local_stack`, you should be able to view the app at:
[http://localhost:6005](http://localhost:6005)

## Linting & Testing

You can use `SUITE_NAME=` to specify the test suite name to run against the test stack.

For example:

```bash
# Lint the project
make lint

# run all scenarios tagged with 'frontend_royalties' against
# the test stack you brought up with `make local_stack`
make test_local SUITE_NAME=frontend_royalties

# Run the full E2E job routine, fetching tokens, bringing the test
# stack up, and running the specified test suite.
make e2e_job SUITE_NAME=ows_royalties
```

To run specific suites, tags, scenarios, etc. you can modify the long form of the
commands found in the [Makefile](../../Makefile)

```bash
cucumber \
    features/standalone \
    -p require_features \
    CUCUMBER_PROFILE=default \
    DOMAIN_PROFILE=developer \
    --tags 'not @wip' \
    --tags 'not @royalties_qa_smoke' \
    --tags @frontend_royalties # or any SUITE_NAME \
    --strict \
    --format pretty \
    --expand
        # add a `--name` param like below to specify scenarios by name,
        # replacing ^Add adjustments$` with your scenario name.
    --name '^Add adjustments$'
```

## THINGS TO DOCUMENT

> Please feel free to contribute to these sections

- Enabling the auth0 workflow in E2E tests
- Adding a new service to the stack
- How to swap out the ECR containers running in the test
  stack with local development versions of the same services
  to test e2e changes locally.
