Skip to content

Commit

Permalink
feat(2151): helm-release-v12.1.0
Browse files Browse the repository at this point in the history
- Updated dependencies
- Fixes for updated dependencies
- Bump patch version
- Fixed lint issues
- Added dep:check/update scripts, and made update:check/update aliases
- Fixed unit tests
  • Loading branch information
mdebarros committed Jun 8, 2021
1 parent 6798d3b commit 391dacc
Show file tree
Hide file tree
Showing 10 changed files with 4,103 additions and 3,351 deletions.
3 changes: 2 additions & 1 deletion src/.eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,6 @@
],
"no-console": 2,
"no-prototype-builtins": "off"
}
},
"plugins": ["jest"]
}
2 changes: 1 addition & 1 deletion src/lib/validate.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const { Errors } = require('@mojaloop/sdk-standard-components');
// Don't stop at the first error, we'll let the user know what all their errors are. Also, when we
// validate, coerce types to those we're interested in where possible.
const Ajv = require('ajv');
const ajv = new Ajv({ allErrors: true, coerceTypes: true });
const ajv = new Ajv({ allErrors: true, coerceTypes: true, strict: false });

const httpMethods = ['get', 'head', 'post', 'put', 'delete', 'connnect', 'options', 'trace', 'patch'];

Expand Down
6,828 changes: 3,756 additions & 3,072 deletions src/package-lock.json

Large diffs are not rendered by default.

68 changes: 36 additions & 32 deletions src/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@mojaloop/sdk-scheme-adapter",
"version": "11.16.2",
"version": "11.16.3",
"description": "An adapter for connecting to Mojaloop API enabled switches.",
"main": "index.js",
"types": "index.d.ts",
Expand All @@ -19,8 +19,10 @@
"validate:api": "npm run validate:api:in; npm run validate:api:out",
"validate:api:in": "swagger-cli validate ./InboundServer/api.yaml",
"validate:api:out": "swagger-cli validate ./OutboundServer/api.yaml",
"updates:check": "npm-check-updates",
"updates:update": "npm-check-updates -u && npm install",
"updates:check": "npm run dep:check",
"updates:update": "npm run dep:update && npm install",
"dep:check": "npx ncu -e 2",
"dep:update": "npx ncu -u",
"release": "standard-version --releaseCommitMessageFormat 'chore(release): {{currentTag}} [skip ci]'"
},
"author": "Matt Kingston, James Bush, ModusBox Inc.",
Expand All @@ -30,7 +32,8 @@
"Valentin Genev <[email protected]>",
"Shashikant Hirugade <[email protected]>",
"Paweł Marzec <[email protected]>",
"Kevin Leyow <[email protected]"
"Kevin Leyow <[email protected]",
"Miguel de Barros <[email protected]>"
],
"license": "Apache-2.0",
"licenses": [
Expand All @@ -45,44 +48,45 @@
},
"dependencies": {
"@koa/cors": "^3.1.0",
"@mojaloop/sdk-standard-components": "15.0.1",
"ajv": "6.12.6",
"@mojaloop/sdk-standard-components": "15.10.4",
"ajv": "8.6.0",
"axios": "^0.21.1",
"co-body": "^6.1.0",
"dotenv": "^8.2.0",
"env-var": "^7.0.0",
"dotenv": "^10.0.0",
"env-var": "^7.0.1",
"javascript-state-machine": "^3.1.0",
"json-schema-ref-parser": "^6.0.3",
"json-schema-ref-parser": "^9.0.9",
"koa": "^2.13.1",
"koa-body": "^4.2.0",
"koa2-oauth-server": "^1.0.0",
"openapi-jsonschema-parameters": "^1.1.0",
"openapi-jsonschema-parameters": "^9.0.3",
"promise-timeout": "^1.3.0",
"redis": "^3.0.2",
"uuidv4": "^6.2.6",
"ws": "^7.4.2"
"redis": "^3.1.2",
"uuidv4": "^6.2.10",
"ws": "^7.4.6"
},
"devDependencies": {
"@babel/core": "^7.12.10",
"@babel/preset-env": "^7.12.11",
"@mojaloop/api-snippets": "^12.0.5",
"@redocly/openapi-cli": "^1.0.0-beta.31",
"@types/jest": "^26.0.20",
"babel-jest": "^26.6.3",
"eslint": "^7.18.0",
"@babel/core": "^7.14.3",
"@babel/preset-env": "^7.14.4",
"@mojaloop/api-snippets": "^12.4.2",
"@redocly/openapi-cli": "^1.0.0-beta.49",
"@types/jest": "^26.0.23",
"babel-jest": "^27.0.2",
"eslint": "^7.28.0",
"eslint-config-airbnb-base": "^14.2.1",
"eslint-plugin-import": "^2.22.1",
"jest": "^26.6.3",
"jest-junit": "^12.0.0",
"js-yaml": "^3.14.1",
"nock": "^13.0.6",
"npm-audit-resolver": "^2.2.1",
"npm-check-updates": "^11.0.2",
"openapi-response-validator": "^7.2.3",
"openapi-typescript": "^2.4.2",
"redis-mock": "^0.49.0",
"standard-version": "^9.1.1",
"supertest": "^6.1.2",
"eslint-plugin-import": "^2.23.4",
"eslint-plugin-jest": "^24.3.6",
"jest": "^27.0.4",
"jest-junit": "^12.1.0",
"js-yaml": "^4.1.0",
"nock": "^13.1.0",
"npm-audit-resolver": "^2.3.1",
"npm-check-updates": "^11.6.0",
"openapi-response-validator": "^9.0.3",
"openapi-typescript": "^4.0.0",
"redis-mock": "^0.56.3",
"standard-version": "^9.3.0",
"supertest": "^6.1.3",
"swagger-cli": "^4.0.4"
}
}
6 changes: 3 additions & 3 deletions src/test/__mocks__/redis.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ const redisMock = require('redis-mock');

// redis-mock currently ignores callback argument, the following class fix this
class RedisClient extends redisMock.RedisClient {
constructor() {
super();
constructor(options, stream, redisMock) {
super(options, stream, redisMock);
}

_executeCallback(...args) {
Expand Down Expand Up @@ -45,5 +45,5 @@ class RedisClient extends redisMock.RedisClient {


module.exports = {
createClient: () => new RedisClient(),
createClient: (options = {host: 'localhost', port: 6380}, stream, redisMock) => new RedisClient(options, stream, redisMock),
};
9 changes: 7 additions & 2 deletions src/test/unit/api/transfers/transfers.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,15 @@ describe('Outbound Transfers API', () => {
serversInfo.reqOutbound.post('/transfers').
send(postTransfersBadBody).
expect(400, {
message: '.body.to.idType should be equal to one of the allowed values',
message: 'must be equal to one of the allowed values',
statusCode: 400,
}).
end(done);
end((err) => {
if (err) {
return done(err);
}
return done();
});
});

test('should return success response', () => {
Expand Down
135 changes: 73 additions & 62 deletions src/test/unit/lib/model/AuthorizationsModel.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ describe('AuthorizationsModel', () => {

describe('onRequestAction', () => {

it('should implement happy flow', async (done) => {
it('should implement happy flow', async () => {
const transactionRequestId = uuid();
const fspId = uuid();
// our code takes care only about 'transactionRequestId' property
Expand All @@ -143,35 +143,37 @@ describe('AuthorizationsModel', () => {
model.run = jest.fn(() => Promise.resolve());

const message = { ...authorizationsResponse };

// manually invoke transition handler
model.onRequestAction(model.fsm, { transactionRequestId, fspId, authorization })
.then(() => {
// subscribe should be called only once
expect(cache.subscribe).toBeCalledTimes(1);

// subscribe should be done to proper notificationChannel
expect(cache.subscribe.mock.calls[0][0]).toEqual(channel);

// check invocation of request.getParties
expect(MojaloopRequests.__postAuthorizations).toBeCalledWith(authorization, fspId);

// check that this.context.data is updated
expect(model.context.data).toEqual({
authorizations: { ...message },
currentState: 'start'
//current state will be updated by onAfterTransition which isn't called
//when manual invocation of transition handler happens

});
// handler should be called only once
expect(handler).toBeCalledTimes(1);

// handler should unsubscribe from notification channel
expect(cache.unsubscribe).toBeCalledTimes(1);
expect(cache.unsubscribe).toBeCalledWith(channel, subId);
done();
});

const onRequestActionPromise = new Promise((resolve, reject) => {
// manually invoke transition handler
model.onRequestAction(model.fsm, { transactionRequestId, fspId, authorization })
.then(() => {
// subscribe should be called only once
expect(cache.subscribe).toBeCalledTimes(1);

// subscribe should be done to proper notificationChannel
expect(cache.subscribe.mock.calls[0][0]).toEqual(channel);

// check invocation of request.getParties
expect(MojaloopRequests.__postAuthorizations).toBeCalledWith(authorization, fspId);

// check that this.context.data is updated
expect(model.context.data).toEqual({
authorizations: { ...message },
currentState: 'start'
//current state will be updated by onAfterTransition which isn't called
//when manual invocation of transition handler happens

});
// handler should be called only once
expect(handler).toBeCalledTimes(1);

// handler should unsubscribe from notification channel
expect(cache.unsubscribe).toBeCalledTimes(1);
expect(cache.unsubscribe).toBeCalledWith(channel, subId);
resolve();
}).catch((err) => { reject(err); } );
});

// ensure handler wasn't called before publishing the message
expect(handler).not.toBeCalled();
Expand All @@ -183,9 +185,11 @@ describe('AuthorizationsModel', () => {
const df = deferredJob(cache, channel);
setImmediate(() => df.trigger(message));

// wait for onRequestAction
await onRequestActionPromise;
});

it('should handle timeouts', async (done) => {
it('should handle timeouts', async () => {
const transactionRequestId = uuid();
const fspId = uuid();
// our code takes care only about 'transactionRequestId' property
Expand All @@ -199,26 +203,29 @@ describe('AuthorizationsModel', () => {

const message = { ...authorizationsResponse };

// manually invoke transition handler
model.onRequestAction(model.fsm, { transactionRequestId, fspId, authorization })
.catch((err) => {
// subscribe should be called only once
expect(err instanceof pt.TimeoutError).toBeTruthy();
const onRequestActionPromise = new Promise((resolve, reject) => {
// manually invoke transition handler
model.onRequestAction(model.fsm, { transactionRequestId, fspId, authorization })
.then(() => reject())
.catch((err) => {
// subscribe should be called only once
expect(err instanceof pt.TimeoutError).toBeTruthy();

// subscribe should be done to proper notificationChannel
expect(cache.subscribe.mock.calls[0][0]).toEqual(channel);
// subscribe should be done to proper notificationChannel
expect(cache.subscribe.mock.calls[0][0]).toEqual(channel);

// check invocation of request.getParties
expect(MojaloopRequests.__postAuthorizations).toBeCalledWith(authorization, fspId);
// check invocation of request.getParties
expect(MojaloopRequests.__postAuthorizations).toBeCalledWith(authorization, fspId);

// handler should be called only once
expect(handler).toBeCalledTimes(0);
// handler should be called only once
expect(handler).toBeCalledTimes(0);

// handler should unsubscribe from notification channel
expect(cache.unsubscribe).toBeCalledTimes(1);
expect(cache.unsubscribe).toBeCalledWith(channel, subId);
done();
});
// handler should unsubscribe from notification channel
expect(cache.unsubscribe).toBeCalledTimes(1);
expect(cache.unsubscribe).toBeCalledWith(channel, subId);
resolve();
});
});

// ensure handler wasn't called before publishing the message
expect(handler).not.toBeCalled();
Expand All @@ -235,9 +242,11 @@ describe('AuthorizationsModel', () => {
(modelConfig.requestProcessingTimeoutSeconds + 1) * 1000
);

// wait for onRequestAction
await onRequestActionPromise;
});

it('should unsubscribe from cache in case when error happens in workflow run', async (done) => {
it('should unsubscribe from cache in case when error happens in workflow run', async () => {
const transactionRequestId = uuid();
const fspId = uuid();
// our code takes care only about 'transactionRequestId' property
Expand All @@ -246,21 +255,22 @@ describe('AuthorizationsModel', () => {
const model = await Model.create(data, cacheKey, modelConfig);
const { cache } = model.context;

// invoke transition handler
model.onRequestAction(model.fsm, { transactionRequestId, fspId, authorization }).catch((err) => {
expect(err.message).toEqual('Unexpected token u in JSON at position 0');
expect(cache.unsubscribe).toBeCalledTimes(1);
expect(cache.unsubscribe).toBeCalledWith(channel, subId);
done();
});

// fire publication to channel with invalid message
// should throw the exception from JSON.parse
const df = deferredJob(cache, channel);
setImmediate(() => df.trigger(undefined));

try {
await model.onRequestAction(model.fsm, { transactionRequestId, fspId, authorization });
throw new Error('this point should not be reached');
} catch(err) {
expect(err.message).toEqual('Unexpected token u in JSON at position 0');
expect(cache.unsubscribe).toBeCalledTimes(1);
expect(cache.unsubscribe).toBeCalledWith(channel, subId);
}
});

it('should unsubscribe from cache in case when error happens Mojaloop requests', async (done) => {
it('should unsubscribe from cache in case when error happens Mojaloop requests', async () => {
// simulate error
MojaloopRequests.__postAuthorizations = jest.fn(() => Promise.reject('postAuthorizations failed'));
const transactionRequestId = uuid();
Expand All @@ -282,7 +292,6 @@ describe('AuthorizationsModel', () => {
// handler should unsubscribe from notification channel
expect(cache.unsubscribe).toBeCalledTimes(1);
expect(cache.unsubscribe).toBeCalledWith(channel, subId);
done();
}
});

Expand Down Expand Up @@ -347,7 +356,7 @@ describe('AuthorizationsModel', () => {
expect(model.context.logger.log).toBeCalledWith('State machine in errored state');
});

it('handling errors', async (done) => {
it('handling errors', async () => {
const transactionRequestId = uuid();
const fspId = uuid();
// our code takes care only about 'transactionRequestId' property
Expand All @@ -359,15 +368,17 @@ describe('AuthorizationsModel', () => {

model.context.data.currentState = 'start';

model.run({ transactionRequestId, fspId, authorization }).catch((err) => {
try {
await model.run({ transactionRequestId, fspId, authorization });
} catch (err) {
expect(model.context.data.currentState).toEqual('errored');
expect(err.requestActionState).toEqual({
...data,
currentState: 'ERROR_OCCURRED',
});
done();
});
}
});

it('should handle errors', async () => {
const transactionRequestId = uuid();
const fspId = uuid();
Expand Down
Loading

0 comments on commit 391dacc

Please sign in to comment.