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/507 635 Integration Tests #64

Merged
merged 16 commits into from
Feb 20, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
42 changes: 28 additions & 14 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,18 @@ defaults_deploy_install_or_upgrade_helm_chart: &defaults_deploy_install_or_upgra
helm upgrade $K8_RELEASE_NAME --repo=$K8_HELM_REPO --version $K8_HELM_CHART_VERSION --reuse-values $HELM_VALUE_SET_VALUES -f $CIRCLE_WORKING_DIRECTORY/$AWS_S3_DIR_DEVOPS_DEPLOYMENT_CONFIG_HELM/$HELM_VALUE_FILENAME $K8_HELM_CHART_NAME
fi

defaults_Environment: &defaults_environment
name: Set default environment
command: |
echo "Current CACHE_VERSION: ${CACHE_VERSION}"
if [ -z "${CACHE_VERSION}" ];
then
echo 'export CACHE_VERSION="v0"' >> $BASH_ENV
source $BASH_ENV
fi
echo "Using CACHE_VERSION: ${CACHE_VERSION}"
echo "${CACHE_VERSION}" > CACHE_VERSION.txt

jobs:
setup:
<<: *defaults_working_directory
Expand Down Expand Up @@ -210,8 +222,10 @@ jobs:
<<: *defaults_working_directory
steps:
- checkout
- run:
<<: *defaults_environment
- restore_cache:
key: dependency-cache-{{ checksum "package.json" }}
key: dependency-cache-{{ checksum "CACHE_VERSION.txt" }}-{{ checksum "package.json" }}
- run:
name: Create dir for test results
command: mkdir -p ./test/results
Expand Down Expand Up @@ -434,17 +448,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*/
# - test-functional:
# context: org-global
# requires:
Expand Down Expand Up @@ -473,7 +487,7 @@ workflows:
- setup
- test-unit
- test-coverage
# - test-integration
- test-integration
# - test-functional
# - test-spec
filters:
Expand All @@ -498,7 +512,7 @@ workflows:
- setup
- test-unit
- test-coverage
# - test-integration
- test-integration
# - test-functional
# - test-spec
filters:
Expand Down
8 changes: 7 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 9 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "central-settlement",
"description": "Central settlements hosted by a scheme to record and make settlements.",
"version": "5.1.1",
"version": "5.2.0",
"license": "Apache-2.0",
"private": true,
"author": "Valentin Genev <vgenev@gmail.com>, Georgi Georgiev <georgi.georgiev@modusbox.com>",
Expand All @@ -23,8 +23,8 @@
"@mojaloop/central-services-database": "3.1.0-snapshot",
"@mojaloop/central-services-error-handling": "0.5.1",
ggrg marked this conversation as resolved.
Show resolved Hide resolved
"@mojaloop/central-services-shared": "4.1.0-snapshot",
"@mojaloop/forensic-logging-client": "0.5.1",
"@mojaloop/central-services-stream": "4.1.0-snapshot",
"@mojaloop/forensic-logging-client": "0.5.1",
"boom": "7.2.0",
"hapi": "17.6.0",
"hapi-openapi": "1.2.0",
Expand All @@ -35,16 +35,17 @@
},
"devDependencies": {
"eslint": "5.6.1",
"faucet": "0.0.1",
"istanbul": "1.1.0-alpha.1",
"node-fetch": "^2.3.0",
"pre-commit": "1.2.2",
"proxyquire": "2.1.0",
"rewire": "^4.0.1",
"sinon": "6.3.5",
"swagmock": "1.0.0",
"tap-xunit": "1.4.0",
"tape": "4.6.2",
"tapes": "4.1.0",
"pre-commit": "1.2.2",
"faucet": "0.0.1",
"rewire": "^4.0.1"
"tapes": "4.1.0"
},
"scripts": {
"start": "node src/server.js",
Expand All @@ -55,6 +56,8 @@
"lint": "eslint .",
"test:coverage-check": "npm run test:coverage && istanbul check-coverage",
"test:coverage": "istanbul cover tape -- 'test/unit/**/*.js'",
"test:int": "tape 'test/integration/**/*.test.js'",
"test:integration": "sh ./test/integration-runner.sh ./test/integration-runner.env",
"regenerate": "yo swaggerize:test --framework hapi --apiPath './src/interface/swagger.json'"
},
"generator-swaggerize": {
Expand Down
13 changes: 11 additions & 2 deletions src/models/settlement/settlement.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const Db = require('../index')

const create = async (settlement, enums = {}) => {
try {
return await Db.settlement.insert({
return Db.settlement.insert({
reason: settlement.reason,
createdDate: settlement.createdDate
})
Expand All @@ -39,6 +39,15 @@ const create = async (settlement, enums = {}) => {
}
}

const getById = async (id) => {
try {
return Db.settlement.findOne({ settlementId: id })
} catch (err) {
throw err
}
}

module.exports = {
create
create,
getById
}
20 changes: 19 additions & 1 deletion src/models/settlement/settlementParticipantCurrency.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
* Gates Foundation
- Name Surname <name.surname@gatesfoundation.com>

* Georgi Georgiev <georgi.georgiev@modusbox.com>
* Valentin Genev <valentin.genev@modusbox.com>
* Deon Botha <deon.botha@modusbox.com>
--------------
Expand All @@ -42,6 +43,23 @@ const getAccountInSettlement = async ({ settlementId, accountId }, enums = {}) =
}
}

const getBySettlementAndAccount = async (settlementId, accountId) => {
try {
let result = await Db.settlementParticipantCurrency.query(builder => {
return builder
.innerJoin('settlementParticipantCurrencyStateChange AS spcsc', 'spcsc.settlementParticipantCurrencyStateChangeId', 'settlementParticipantCurrency.currentStateChangeId')
.select('settlementParticipantCurrency.*', 'spcsc.settlementStateId', 'spcsc.reason', 'spcsc.externalReference')
.where({ settlementId })
.andWhere('participantCurrencyId', accountId)
.first()
})
return result
} catch (err) {
throw err
}
}

module.exports = {
getAccountInSettlement
getAccountInSettlement,
getBySettlementAndAccount
}
44 changes: 44 additions & 0 deletions src/models/settlement/settlementStateChange.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*****
License
--------------
Copyright © 2017 Bill & Melinda Gates Foundation
The Mojaloop files are made available by the Bill & Melinda Gates Foundation under the Apache License, Version 2.0 (the "License") and you may not use these files except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, the Mojaloop files are distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Contributors
--------------
This is the official list of the Mojaloop project contributors for this file.
Names of the original copyright holders (individuals or organizations)
should be listed with a '*' in the first column. People who have
contributed from an organization can be listed under the organization
that actually holds the copyright for their contributions (see the
Gates Foundation organization for an example). Those individuals should have
their names indented and be marked with a '-'. Email address can be added
optionally within square brackets <email>.
* Gates Foundation
- Name Surname <name.surname@gatesfoundation.com>

* Georgi Georgiev <georgi.georgiev@modusbox.com>
--------------
******/

'use strict'

const Db = require('../index')

const getBySettlementId = async (id) => {
try {
const knex = await Db.getKnex()
return knex('settlementStateChange')
.where('settlementId', id)
.orderBy('settlementStateChangeId', 'desc')
.select('*')
.first()
} catch (err) {
throw err
}
}

module.exports = {
getBySettlementId
}
3 changes: 2 additions & 1 deletion src/models/settlement/settlementTransferParticipant.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@
Gates Foundation organization for an example). Those individuals should have
their names indented and be marked with a '-'. Email address can be added
optionally within square brackets <email>.

* Gates Foundation
- Name Surname <name.surname@gatesfoundation.com>

* Georgi Georgiev <georgi.georgiev@modusbox.com>
* Valentin Genev <valentin.genev@modusbox.com>
* Deon Botha <deon.botha@modusbox.com>
Expand Down
2 changes: 2 additions & 0 deletions src/models/settlementWindow/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
their names indented and be marked with a '-'. Email address can be added
optionally within square brackets <email>.
* Gates Foundation
- Name Surname <name.surname@gatesfoundation.com>

* Georgi Georgiev <georgi.georgiev@modusbox.com>
* Valentin Genev <valentin.genev@modusbox.com>
* Deon Botha <deon.botha@modusbox.com>
Expand Down
19 changes: 17 additions & 2 deletions src/models/settlementWindow/settlementWindowStateChange.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
* Gates Foundation
- Name Surname <name.surname@gatesfoundation.com>

* Georgi Georgiev <georgi.georgiev@modusbox.com>
* Valentin Genev <valentin.genev@modusbox.com>
* Deon Botha <deon.botha@modusbox.com>
--------------
Expand All @@ -29,7 +30,7 @@ const Db = require('../index')

const create = async ({ settlementWindowId, state, reason }, enums = {}) => {
try {
return await Db.settlementWindowStateChange.insert({
return Db.settlementWindowStateChange.insert({
settlementWindowId,
settlementWindowStateId: enums[state.toUpperCase()],
reason
Expand All @@ -39,6 +40,20 @@ const create = async ({ settlementWindowId, state, reason }, enums = {}) => {
}
}

const getBySettlementWindowId = async (id) => {
try {
const knex = await Db.getKnex()
return knex('settlementWindowStateChange')
.where('settlementWindowId', id)
.orderBy('settlementWindowStateChangeId', 'desc')
.select('*')
.first()
} catch (err) {
throw err
}
}

module.exports = {
create
create,
getBySettlementWindowId
}
25 changes: 25 additions & 0 deletions test-integration.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
FROM mhart/alpine-node:8.9.4
USER root

WORKDIR /opt/central-settlement
COPY config /opt/central-settlement/config
COPY src /opt/central-settlement/src
COPY test /opt/central-settlement/test
COPY package.json /opt/central-settlement
COPY README.md /opt/central-settlement

# overwrite default.json with integration environment specific config
RUN cp -f /opt/central-settlement/test/integration-config-centralsettlement.json /opt/central-settlement/config/default.json

RUN apk add --no-cache -t build-dependencies git make gcc g++ python libtool autoconf automake \
&& cd $(npm root -g)/npm \
&& npm config set unsafe-perm true

RUN npm install

RUN npm install -g tape tap-xunit

RUN apk del build-dependencies

EXPOSE 3007
CMD node src/server.js
Loading