Functional Tests for Accounting Scripts
=======================================

## Requirements

  - Your `.ssh/id_rsa.pub` should be added to `.ssh/authorized_keys` of the test box prior to running any tests.
  - Your AWS account should have read/write access to `qa-orcdbucket/ows-notitifcations/automation_qa/emails` directory.

## Install Ruby

  _Skip this step in case if you have a ruby 2.3.1 or higher_

```bash
  $ rvm install 2.3.1
  $ rvm use 2.3.1
```
In case if you don't have RVM or any other Ruby Version Manager you can visit https://rvm.io/rvm/install for more details.

## Set Up Test Framework

 1. Clone the repo
```bash
  $ git clone git@github.com:theorchard/accounting-run-atf.git
```

 2. Install all the required libs
 ```bash
    $ cd accounting-run-atf/scripts-verifications
    $ bundle install
 ```

 3. Populate .env file
```bash
    $ cp .env.shadow .env # and update .env
```

4. Export ACCOUNTING_MONTH and ACCOUNTING_YEAR which will be used for testing the scripts
```bash
    $ export ACCOUNTING_MONTH=n # e.g. 5
    $ export ACCOUNTING_YEAR=n # e.g. 2018
```

## Run Tests

 - To run tests all you need is
```bash
    $ rspec # will run all the tests from ./spec/*_spec.rb
```

## Active MQ

  Visit http://192.168.31.89:8161/admin/queues.jsp to see all the queues and get any details related to ActiveMQ

## SNS

  To test SNS emails we use s3 bucket directory `qa-orcdbucket/ows-notitifcations/automation_qa/emails`.
  There is an SES rule set saying that all emails sent to `automation_qa@test.theorchard.io` should be stored in that s3 bucket directory.
  Currently for the tests we use `dev_ad` SNS topic of `us-west-2` region.

## Debug

  In case if a test fails you can check the test stdout, so you should see all the ssh commands and SQL queries where executed when running that test.
  Also you should be able to SSH to that test box to rerun a script manually.
```bash
    $ ssh <devboxusername>@<devboxhost> # see configs/main_config.yml for details
    $ cd <scripts_path> # see configs/main_config.yml for details
    $ php scriptName.php -m n -y n # and check the output/sns/data manually after the script finishes
```

## Additional Notes

  - Currently in `process_summary_queue_spec.rb` test we use `ACCOUNTING_RUN_ENV=test` it allows to save a lot of runtime.
  But for future it would be nice to move that logic to one of the /orchard repo's config file (like accounting.ini etc.).
