Skip to content

Commit

Permalink
update resources to new url structure
Browse files Browse the repository at this point in the history
  • Loading branch information
dolcalmi committed Nov 14, 2019
1 parent c20268f commit 8b44290
Show file tree
Hide file tree
Showing 12 changed files with 63 additions and 36 deletions.
1 change: 1 addition & 0 deletions lib/NequiResource.js
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,7 @@ NequiResource.prototype = {
service: self._nequi.getApiField('service') || 'execute-api',
body: requestData
};

var auth = self._nequi.getApiField('auth');
var securityToken = self._nequi.getApiField('securityToken');
options = aws4.sign(reqParams, {accessKeyId: auth.accessKey, secretAccessKey: auth.secretKey});
Expand Down
20 changes: 13 additions & 7 deletions lib/nequi.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
'use strict';

Nequi.DEFAULT_HOST = 'a7zgalw2j0.execute-api.us-east-1.amazonaws.com';
Nequi.DEFAULT_HOST_QA = 'api.sandbox.nequi.com';
Nequi.DEFAULT_HOST_PROD = 'api.nequi.com';
Nequi.DEFAULT_PORT = '443';
Nequi.DEFAULT_BASE_PATH = '/qa/';
Nequi.DEFAULT_BASE_PATH = '/';
Nequi.DEFAULT_API_VERSION = null;
Nequi.DEFAULT_CLIENT_ID = 'nequi-node';
Nequi.DEFAULT_SECURITY_TOKEN = '';
Expand All @@ -18,7 +19,8 @@ var resources = {
DispersionPayments: require('./resources/DispersionPayments'),
PushPayments: require('./resources/PushPayments'),
QrPayments: require('./resources/QrPayments'),
SubscriptionPayments: require('./resources/SubscriptionPayments')
SubscriptionPayments: require('./resources/SubscriptionPayments'),
Reports: require('./resources/Reports')
};

Nequi.NequiResource = require('./NequiResource');
Expand All @@ -44,7 +46,7 @@ function Nequi(accessKey, secretKey, apiKey) {
accessKey: accessKey,
secretKey: secretKey
},
host: Nequi.DEFAULT_HOST,
host: Nequi.DEFAULT_HOST_QA,
port: Nequi.DEFAULT_PORT,
basePath: Nequi.DEFAULT_BASE_PATH,
version: Nequi.DEFAULT_API_VERSION,
Expand All @@ -65,12 +67,16 @@ Nequi.prototype = {
},

setHost: function(host) {
this._setApiField('host', host || Nequi.DEFAULT_HOST);
this._setApiField('host', host || Nequi.DEFAULT_HOST_QA);
},

setEnvironment: function(env) {
var e = env === 'prod' ? 'prod' : 'qa';
this._setApiField('basePath', '/' + e + '/');
var e = env === 'prod' ? Nequi.DEFAULT_HOST_PROD : Nequi.DEFAULT_HOST_QA;
this._setApiField('host', e);
},

setBasePath: function(path) {
this._setApiField('basePath', path || Nequi.DEFAULT_BASE_PATH);
},

setClientId: function(clientId) {
Expand Down
2 changes: 1 addition & 1 deletion lib/resources/DispersionPayments.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ var nequiMethod = NequiResource.method;

module.exports = NequiResource.extend({

path: '',
path: '/qa/',
overrideHost: '3ptobiurt0.execute-api.us-east-1.amazonaws.com',

create: nequiMethod({
Expand Down
2 changes: 1 addition & 1 deletion lib/resources/PushPayments.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ var nequiMethod = NequiResource.method;

module.exports = NequiResource.extend({

path: '',
path: 'payments/v1/',

create: nequiMethod({
method: 'POST',
Expand Down
2 changes: 1 addition & 1 deletion lib/resources/QrPayments.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ var nequiMethod = NequiResource.method;

module.exports = NequiResource.extend({

path: '',
path: 'payments/v1/',

create: nequiMethod({
method: 'POST',
Expand Down
20 changes: 20 additions & 0 deletions lib/resources/Reports.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
'use strict';

var NequiResource = require('../NequiResource');
var nequiMethod = NequiResource.method;

module.exports = NequiResource.extend({

path: 'partners/v1/',

get: nequiMethod({
method: 'POST',
path: '-services-reportsservice-getreports',
channel: 'MF-001',
service: {
name: 'ReportsService',
operation: 'getReports'
}
}),

});
3 changes: 1 addition & 2 deletions lib/resources/SubscriptionPayments.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ var nequiMethod = NequiResource.method;

module.exports = NequiResource.extend({

path: '',
overrideHost: 'tte1048ge4.execute-api.us-east-1.amazonaws.com',
path: 'subscriptions/v1/',

subscribe: nequiMethod({
method: 'POST',
Expand Down
2 changes: 1 addition & 1 deletion test/NequiResource.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ describe('NequiResource', function() {
it('Generates a path', function() {
nequi.pushPayments.create({});
var path = nequi.pushPayments.createResourcePathWithSymbols('{id}');
expect(path).to.equal('/{id}');
expect(path).to.equal('/payments/v1/{id}');
});
});

Expand Down
22 changes: 10 additions & 12 deletions test/nequi.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ var nequi = require('../lib/nequi')(
testUtils.getUserNequiSecretKey()
);

var DEFAULT_HOST = 'a7zgalw2j0.execute-api.us-east-1.amazonaws.com';
var DEFAULT_BASE_PATH = '/qa/';
var DEFAULT_HOST = 'api.sandbox.nequi.com';
var DEFAULT_BASE_PATH = '/';
var DEFAULT_SECURITY_TOKEN = '';
var DEFAULT_CLIENT_ID = 'nequi-node';
var PAYMENT_DETAILS = {
Expand All @@ -31,6 +31,10 @@ describe('Nequi Module', function() {
nequi.setHost('custom.nequi.co');
expect(nequi.getApiField('host')).to.equal('custom.nequi.co');
});
it('Should allow me to set host with environment', function() {
nequi.setEnvironment('prod');
expect(nequi.getApiField('host')).to.equal('api.nequi.com');
});
it('Should allow me to set null or empty, to reset to the default', function() {
nequi.setHost(null);
expect(nequi.getApiField('host')).to.equal(DEFAULT_HOST);
Expand All @@ -43,20 +47,14 @@ describe('Nequi Module', function() {
it('Should define a default equal to DEFAULT_BASE_PATH', function() {
expect(nequi.getApiField('basePath')).to.equal(DEFAULT_BASE_PATH);
});
it('Should allow me to set prod', function() {
nequi.setEnvironment('prod');
it('Should allow me to set basePath', function() {
nequi.setBasePath('/prod/');
expect(nequi.getApiField('basePath')).to.equal('/prod/');
});
it('Should be DEFAULT_BASE_PATH if base path is not prod', function() {
nequi.setEnvironment('qa');
expect(nequi.getApiField('basePath')).to.equal(DEFAULT_BASE_PATH);
nequi.setEnvironment('staging');
expect(nequi.getApiField('basePath')).to.equal(DEFAULT_BASE_PATH);
});
it('Should allow me to set null or empty, to reset to the default', function() {
nequi.setEnvironment(null);
nequi.setBasePath(null);
expect(nequi.getApiField('basePath')).to.equal(DEFAULT_BASE_PATH);
nequi.setEnvironment('');
nequi.setBasePath('');
expect(nequi.getApiField('basePath')).to.equal(DEFAULT_BASE_PATH);
});
});
Expand Down
7 changes: 4 additions & 3 deletions test/resources/PushPayments.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

var nequi = require('../testUtils').getSpyableNequi();
var expect = require('chai').expect;
var DEFAULT_PATH = 'payments/v1/';

describe('PushPayments Resource', function() {

Expand All @@ -15,7 +16,7 @@ describe('PushPayments Resource', function() {

expect(nequi.LAST_REQUEST).to.deep.equal({
method: 'POST',
path: '-services-paymentservice-unregisteredpayment',
path: DEFAULT_PATH + '-services-paymentservice-unregisteredpayment',
data: {
channel: 'PNP04-C001',
service: {
Expand Down Expand Up @@ -43,7 +44,7 @@ describe('PushPayments Resource', function() {

expect(nequi.LAST_REQUEST).to.deep.equal({
method: 'POST',
path: '-services-paymentservice-getstatuspayment',
path: DEFAULT_PATH + '-services-paymentservice-getstatuspayment',
data: {
channel: 'PNP04-C001',
service: {
Expand Down Expand Up @@ -73,7 +74,7 @@ describe('PushPayments Resource', function() {

expect(nequi.LAST_REQUEST).to.deep.equal({
method: 'POST',
path: '-services-reverseservices-reversetransaction',
path: DEFAULT_PATH + '-services-reverseservices-reversetransaction',
data: {
channel: 'PNP04-C001',
service: {
Expand Down
7 changes: 4 additions & 3 deletions test/resources/QrPayments.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

var nequi = require('../testUtils').getSpyableNequi();
var expect = require('chai').expect;
var DEFAULT_PATH = 'payments/v1/';

describe('QrPayments Resource', function() {

Expand All @@ -14,7 +15,7 @@ describe('QrPayments Resource', function() {

expect(nequi.LAST_REQUEST).to.deep.equal({
method: 'POST',
path: '-services-paymentservice-generatecodeqr',
path: DEFAULT_PATH + '-services-paymentservice-generatecodeqr',
data: {
channel: 'PQR03-C001',
service: {
Expand All @@ -41,7 +42,7 @@ describe('QrPayments Resource', function() {

expect(nequi.LAST_REQUEST).to.deep.equal({
method: 'POST',
path: '-services-paymentservice-getstatuspayment',
path: DEFAULT_PATH + '-services-paymentservice-getstatuspayment',
data: {
channel: 'PQR03-C001',
service: {
Expand Down Expand Up @@ -71,7 +72,7 @@ describe('QrPayments Resource', function() {

expect(nequi.LAST_REQUEST).to.deep.equal({
method: 'POST',
path: '-services-reverseservices-reversetransaction',
path: DEFAULT_PATH + '-services-reverseservices-reversetransaction',
data: {
channel: 'PQR03-C001',
service: {
Expand Down
11 changes: 6 additions & 5 deletions test/resources/SubscriptionPayments.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

var nequi = require('../testUtils').getSpyableNequi();
var expect = require('chai').expect;
var DEFAULT_PATH = 'subscriptions/v1/';

describe('SubscriptionPayments Resource', function() {

Expand All @@ -15,7 +16,7 @@ describe('SubscriptionPayments Resource', function() {

expect(nequi.LAST_REQUEST).to.deep.equal({
method: 'POST',
path: '-services-subscriptionpaymentservice-newsubscription',
path: DEFAULT_PATH + '-services-subscriptionpaymentservice-newsubscription',
data: {
channel: 'PDA05-C001',
service: {
Expand Down Expand Up @@ -45,7 +46,7 @@ describe('SubscriptionPayments Resource', function() {

expect(nequi.LAST_REQUEST).to.deep.equal({
method: 'POST',
path: '-services-subscriptionpaymentservice-getsubscription',
path: DEFAULT_PATH + '-services-subscriptionpaymentservice-getsubscription',
data: {
channel: 'PDA05-C001',
service: {
Expand Down Expand Up @@ -76,7 +77,7 @@ describe('SubscriptionPayments Resource', function() {

expect(nequi.LAST_REQUEST).to.deep.equal({
method: 'POST',
path: '-services-subscriptionpaymentservice-automaticpayment',
path: DEFAULT_PATH + '-services-subscriptionpaymentservice-automaticpayment',
data: {
channel: 'PDA05-C001',
service: {
Expand Down Expand Up @@ -105,7 +106,7 @@ describe('SubscriptionPayments Resource', function() {

expect(nequi.LAST_REQUEST).to.deep.equal({
method: 'POST',
path: '-services-subscriptionpaymentservice-getstatuspayment',
path: DEFAULT_PATH + '-services-subscriptionpaymentservice-getstatuspayment',
data: {
channel: 'PDA05-C001',
service: {
Expand Down Expand Up @@ -135,7 +136,7 @@ describe('SubscriptionPayments Resource', function() {

expect(nequi.LAST_REQUEST).to.deep.equal({
method: 'POST',
path: '-services-reverseservices-reversetransaction',
path: DEFAULT_PATH + '-services-reverseservices-reversetransaction',
data: {
channel: 'PDA05-C001',
service: {
Expand Down

0 comments on commit 8b44290

Please sign in to comment.