Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/656 add integration tests #100

Merged
Merged
Show file tree
Hide file tree
Changes from 18 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
7b45b51
Replace ava with jest for unit testing,
lewisdaly Sep 26, 2019
90eab56
Merge branch 'master' of github.com:mojaloop/account-lookup-service i…
lewisdaly Oct 2, 2019
7199d99
Finish fixing code coverage, fix final missing tests
lewisdaly Oct 2, 2019
1196aab
Remove commented code
lewisdaly Oct 3, 2019
58f3478
bump package version to 8.2.0
lewisdaly Oct 3, 2019
af9d57f
Adding docker-compose config for integration tests
lewisdaly Oct 3, 2019
2d8e4ef
Implement basic integration tests and integration test runner,
lewisdaly Oct 3, 2019
b9e8602
working on better integration runner for testing live api
lewisdaly Oct 7, 2019
4d2bc29
Working on integration runner
lewisdaly Oct 7, 2019
ec6656f
improving test usage env vars
lewisdaly Oct 7, 2019
e01971e
Upgrade everything but @hapi/boom
lewisdaly Oct 7, 2019
f3a862a
Upgrade everything but @hapi/boom
lewisdaly Oct 7, 2019
c27dbbc
work on integration runner
lewisdaly Oct 7, 2019
4ef81c2
Merge branch 'master' of github.com:mojaloop/account-lookup-service i…
lewisdaly Oct 7, 2019
8b0761b
Resolve package.json conflicts, update to latest version
lewisdaly Oct 7, 2019
daa6e0d
Updating readme for integration and local runner
lewisdaly Oct 8, 2019
1cd7ed4
working on test runner and readme
lewisdaly Oct 8, 2019
22b15ba
resolve package-lock.json merge conflicts
lewisdaly Oct 8, 2019
55b58d7
Bump package version to try and fix failing ci tests
lewisdaly Oct 8, 2019
0b9c9b6
Merge branch 'feature/656-add-integration-tests' of github.com:vessel…
lewisdaly Oct 8, 2019
37ee6c5
testing circleci 2.1 changes
lewisdaly Oct 8, 2019
08a2a25
cleaning up circleci config
lewisdaly Oct 8, 2019
eab3dae
testing refactor of working_directory
lewisdaly Oct 8, 2019
ffc1d57
clean up yaml templating
lewisdaly Oct 8, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 26 additions & 24 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# CircleCI v2 Config
version: 2
version: 2.1

defaults_working_directory: &defaults_working_directory
working_directory: /home/circleci/project
Expand Down Expand Up @@ -241,20 +241,19 @@ jobs:
fi

test-integration:
machine: true
machine:
image: ubuntu-1604:201903-01
<<: *defaults_working_directory
steps:
- checkout
- run:
<<: *defaults_environment
- restore_cache:
key: dependency-cache-{{ checksum "package.json" }}
- run:
name: Create dir for test results
command: mkdir -p ./test/results
- run:
name: Execute integration tests
command: npm -s run test:integration
command: RESULTS_DIR="./test/results" npm -s run test:integration
no_output_timeout: 25m
- store_artifacts:
path: ./test/results
Expand Down Expand Up @@ -380,7 +379,8 @@ jobs:
prefix: licenses

build-snapshot:
machine: true
machine:
image: ubuntu-1604:201903-01
<<: *defaults_working_directory
steps:
- checkout
Expand All @@ -404,7 +404,8 @@ jobs:
<<: *defaults_slack_announcement

build-hotfix:
machine: true
machine:
image: ubuntu-1604:201903-01
# <<: *default_env
steps:
- checkout
Expand All @@ -424,7 +425,8 @@ jobs:
<<: *defaults_slack_announcement

build:
machine: true
machine:
image: ubuntu-1604:201903-01
# <<: *default_env
steps:
- checkout
Expand Down Expand Up @@ -562,17 +564,17 @@ workflows:
ignore:
- /feature*/
- /bugfix*/
# - test-integration:
# context: org-global
# requires:
# - setup
# filters:
# tags:
# only: /.*/
# branches:
# ignore:
# - /feature*/
# - /bugfix*/
- test-integration:
context: org-global
requires:
- setup
filters:
tags:
only: /.*/
branches:
ignore:
- /feature*/
- /bugfix*/
- vulnerability-check:
context: org-global
requires:
Expand All @@ -599,9 +601,9 @@ workflows:
context: org-global
requires:
- setup
# - test-unit
# - test-coverage
# - test-integration
- test-unit
- test-coverage
- test-integration
# - test-functional
# - test-spec
filters:
Expand All @@ -626,7 +628,7 @@ workflows:
- setup
- test-unit
- test-coverage
# - test-integration
- test-integration
# - test-functional
# - test-spec
- vulnerability-check
Expand All @@ -643,7 +645,7 @@ workflows:
- setup
- test-unit
- test-coverage
# - test-integration
- test-integration
# - test-functional
# - test-spec
- vulnerability-check
Expand Down
13 changes: 9 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM node:10.15.3-alpine
FROM node:10.15.3-alpine AS builder

WORKDIR /opt/account-lookup-service

Expand All @@ -8,15 +8,20 @@ RUN apk add --no-cache -t build-dependencies git make gcc g++ python libtool aut
&& npm install -g node-gyp

COPY package.json package-lock.json* /opt/account-lookup-service/
RUN npm install --production

RUN apk del build-dependencies
RUN npm install

COPY config /opt/account-lookup-service/config
COPY migrations /opt/account-lookup-service/migrations
COPY seeds /opt/account-lookup-service/seeds
COPY src /opt/account-lookup-service/src

FROM node:10.15.3-alpine

WORKDIR /opt/account-lookup-service

COPY --from=builder /opt/account-lookup-service .
RUN npm prune --production

EXPOSE 4002
EXPOSE 4001
CMD ["npm", "run", "start"]
119 changes: 93 additions & 26 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,58 +1,124 @@
# Account Lookup Server
# Account Lookup Service
[![Git Commit](https://img.shields.io/github/last-commit/mojaloop/account-lookup-service.svg?style=flat)](https://github.com/mojaloop/account-lookup-service/commits/master)
[![Git Releases](https://img.shields.io/github/release/mojaloop/account-lookup-service.svg?style=flat)](https://github.com/mojaloop/account-lookup-service/releases)
[![Docker pulls](https://img.shields.io/docker/pulls/mojaloop/account-lookup-service.svg?style=flat)](https://hub.docker.com/r/mojaloop/account-lookup-service)
[![CircleCI](https://circleci.com/gh/mojaloop/account-lookup-service.svg?style=svg)](https://circleci.com/gh/mojaloop/account-lookup-service)



## Documentation
[Documentation](http://mojaloop.io/documentation/mojaloop-technical-overview/account-lookup-service/) \
[API Swagger](http://mojaloop.io/documentation/api/#als-oracle-api) \
[Admin Swagger](http://mojaloop.io/documentation/api/#als-oracle-api) <!--This currently points to API but will be updated when Admin documentation is created-->


## Database initialisation
To populate the database with tables and seeded valued, ensure that the correct database URI is in the default.json and then run the following command
```bash
npm run migrate
```

### Note
If you're running ALS with `npm start` or `node src/index.js ...` locally (i.e outside of docker as described below) and running mysql within docker with `docker-compose up -d mysql`, you would need to change port `3306` to `3307` for `DATABASE_URL` in `config/default.json`. This is not necessary if you're running ALS with `docker-compose up`, in which case, both the API and mysql are running within docker. Otherwise, you can simply run this service locally with `docker-compose up -d`.


You can start the database easily within docker, using docker-compose:
```bash
docker-compose up mysql-als
```


To populate the database with tables and seeded valued, ensure that the correct database URI is in the `default.json` file, or set the `ALS_DATABASE_URI` accordingly, and run the following command:

```bash
npm run migrate
```

## Start API
To run the API and/or Admin servers run the following commands
##### Both

### Both Admin + API
```bash
NPM: npm start
#NPM:
npm start

CLI: node src/index.js server
#CLI:
node src/index.js server
```
##### API

### API
```bash
NPM: npm run start:api
#NPM:
npm run start:api

CLI: node src/index.js server --api
#CLI:
node src/index.js server --api
```
##### Admin

### Admin
```bash
NPM: npm run start:admin
#NPM:
npm run start:admin

CLI: node src/index.js server --admin
#CLI:
node src/index.js server --admin
```

## Tests

##### Unit Testing
### Unit Testing

Running unit tests
```bash
npm run test:unit
```

Running the test:
### Code Coverage
```bash
NPM: npm run test
npm run test:coverage-check
```

### Integration tests

CLI: ava test/unit/**/**.test.js
The integration tests use `docker-compose` to spin up a test environment for running the integration tests.
The tests are executed inside a standalone `account-lookup-service-int` container, defined in `docker-compose.integration.yml`.

Run the tests in a standalone mode with:
```bash
npm run test:integration
```

By default, the test results will be available in `/tmp/junit.xml`. See below to configure the output directory and file name of the test results.


#### Running integration tests repetitively

In order to debug and fix broken integration tests, you may want to run the tests without tearing down the environment every time. To do this, you can set `TEST_MODE` to `wait`, which sets up the integration runner to start the docker containers, run the migrations, and then wait for you to log into the `account-lookup-service-int` container and run the tests yourself.

>*Note: The docker-compose.integration.yml file mounts the `./src` and `./test` directories inside the docker-container, so you can re-run your tests repeatedly without removing and rebuilding your containers each time.*

For example:

```bash
export TEST_MODE=wait
npm run test:integration
# containers will now be ready and waiting for the tests

# log into the `account-lookup-service-int` container
docker exec -it als_account-lookup-service-int sh

# now run the integration tests
npm run test:int

```

You can then stop and remove the containers with the following commands:
```bash
docker-compose -f docker-compose.yml -f docker-compose.integration.yml stop
docker-compose -f docker-compose.yml -f docker-compose.integration.yml rm -f
```

#### Environment Variables:

| Environment variable | Description | Example values | Default Value |
| ------------------------- | ----------- | -------------- | ------------- |
| `TEST_MODE` | The mode that `integration-runner.sh` uses. See `./test/integration-runner.sh` for more information. | `default`, `wait`, `rm` | `default` |
| `JEST_JUNIT_OUTPUT_DIR` | The output directory (inside the docker container) for the jest runner | `/tmp`, `/opt/account-lookup-service/test/results` | `/tmp` |
| `JEST_JUNIT_OUTPUT_NAME` | The filename (inside the docker container) for the jest runner | `junit.xml` | `junit.xml` |
| `RESULTS_DIR` | The output directory (on the host machine) that the test results is copied to | `/tmp` | `/tmp` |


## Auditing Dependencies

We use `npm-audit-resolver` along with `npm audit` to check dependencies for vulnerabilities, and keep track of resolved dependencies with an `audit-resolv.json` file.
Expand All @@ -67,7 +133,8 @@ You can then check to see if the CI will pass based on the current dependencies
npm run audit:check
```

And commit the changed `audit-resolv.json` to ensure that CircleCI will build correctly.
And commit the changed `audit-resolve.json` to ensure that CircleCI will build correctly.

## Additional Notes:

## Note:
#### For all put parties callbacks FSPIOP-Destination header is considered to be mandatory.
- For all put parties callbacks `FSPIOP-Destination` header is considered to be mandatory.
23 changes: 23 additions & 0 deletions docker-compose.integration.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
version: "3.7"

services:
account-lookup-service-int:
build:
context: .
target: builder
container_name: als_account-lookup-service-int
networks:
- als-mojaloop-net
command:
- sh
- -c
- "tail -f /dev/null"
depends_on:
- mysql-als
- central-ledger
volumes:
- ./src:/opt/account-lookup-service/src
- ./test:/opt/account-lookup-service/test
- ./package.json:/opt/account-lookup-service/package.json
- ./test/integration-config.json:/opt/account-lookup-service/config/default.json
- ./docker/wait-for:/opt/wait-for
Loading