Skip to content

Commit

Permalink
Merge branch 'develop' into release
Browse files Browse the repository at this point in the history
* develop:
  Fix several tests that are not valid (and are currently breaking)
  Add support for Notifications API
  [TASK] bump minor version to 1.15.0
  [TASK] bump version to 1.14.1
  [FIX] pass entire payment response
  • Loading branch information
Alan Cohen committed Apr 22, 2015
2 parents 9a0998f + 70c6e02 commit 1cb02fb
Show file tree
Hide file tree
Showing 13 changed files with 122 additions and 93 deletions.
19 changes: 18 additions & 1 deletion index.js
Expand Up @@ -175,6 +175,23 @@ Client.prototype.getNotification = function(hash, callback) {
});
};

Client.prototype.getNotifications = function(callback) {
var url = this.api + 'v1/accounts/' + this.account + '/notifications/';
var notifications;

http
.get(url)
.end(function(error, response) {

if (error) {
callback(error);
} else {
notifications = response.body.notifications;
callback(null, notifications);
}
});
};

// Deprecated: not called in Ripple Connect
Client.prototype.setHash = function(paymentHash, callback) {
this.lastPaymentHash = paymentHash;
Expand Down Expand Up @@ -304,7 +321,7 @@ Client.prototype._getAndHandlePaymentStatus =

if (response &&
(response.state === 'validated' || response.state === 'failed')) {
callback(null, response.payment);
callback(null, response);
} else {
setTimeout(function() {
loopFunction(statusUrl, callback, loopFunction);
Expand Down
2 changes: 1 addition & 1 deletion package.json
@@ -1,6 +1,6 @@
{
"name": "ripple-rest-client",
"version": "1.14.0",
"version": "1.15.0",
"description": "A Node.js client library for interacting with Ripple REST servers.",
"main": "./index.js",
"scripts": {
Expand Down
4 changes: 3 additions & 1 deletion test/build_payment.js
Expand Up @@ -35,7 +35,9 @@ describe('Ripple REST Client buildPayment', function() {
};

client.buildPayment(newPayment, function(error, response) {
assert(!error, 'API call failed');
if (error) {
return done(error);
}
assert(response, 'Response is null');
assert(_.isArray(response.payments));
_.forEach(response.payments, function(value) {
Expand Down
21 changes: 21 additions & 0 deletions test/fixtures/get_notifications.js
@@ -0,0 +1,21 @@
'use strict';

exports.success = function(args) {
return [
{
account: args.account,
type: args.type,
direction: args.direction,
state: args.state,
result: args.result,
ledger: args.ledger,
hash: args.hash,
timestamp: args.timestamp,
transaction_url: args.transaction_url,
previous_hash: args.previous_hash,
previous_notification_url: args.previous_notification_url,
next_hash: args.next_hash,
next_notification_url: args.next_notification_url,
}
]
};
2 changes: 1 addition & 1 deletion test/fixtures/get_server_status.js
Expand Up @@ -4,7 +4,7 @@ exports.success = function(args) {
var returnData = {
success: true,
api_documentation_url: 'https://github.com/ripple/ripple-rest',
rippled_server_url: 'wss://s1.ripple.com:443',
rippled_server_url: 'wss://s2.ripple.com:443',
rippled_server_status: {
build_version: args.rippled_server_status.build_version,
complete_ledgers: args.rippled_server_status.complete_ledgers,
Expand Down
11 changes: 1 addition & 10 deletions test/fixtures/get_transaction.js
Expand Up @@ -25,16 +25,7 @@ exports.success = function(args) {
hash: args.transaction.hash,
inLedger: args.transaction.inLedger,
ledger_index: args.transaction.ledger_index,
meta: {
TransactionIndex: args.transaction.meta.TransactionIndex,
AffectedNodes: [],
TransactionResult: args.transaction.meta.TransactionResult,
delivered_amount: {
value: args.transaction.meta.delivered_amount.value,
currency: args.transaction.meta.delivered_amount.currency,
issuer: args.transaction.meta.delivered_amount.issuer
}
},
meta: args.transaction.meta,
validated: args.transaction.validated
}
};
Expand Down
58 changes: 33 additions & 25 deletions test/fixtures/send_and_confirm_payment.js
Expand Up @@ -2,32 +2,40 @@

exports.success = function(args) {
return {
source_account: args.source_account,
source_tag: args.source_tag,
source_amount: {
value: args.source_amount.value,
currency: args.source_amount.currency,
issuer: args.source_amount.issuer
success: true,
payment: {
source_account: args.payment.source_account,
source_tag: args.payment.source_tag,
source_amount: {
value: args.payment.source_amount.value,
currency: args.payment.source_amount.currency,
issuer: args.payment.source_amount.issuer
},
source_slippage: args.payment.source_slippage,
destination_account: args.payment.destination_account,
destination_tag: args.payment.destination_tag,
destination_amount: {
value: args.payment.destination_amount.value,
currency: args.payment.destination_amount.currency,
issuer: args.payment.destination_amount.issuer
},
invoice_id: args.payment.invoice_id,
paths: args.payment.paths,
no_direct_ripple: args.payment.no_direct_ripple,
partial_payment: args.payment.partial_payment,
direction: args.payment.direction,
result: args.payment.result,
timestamp: args.payment.timestamp,
fee: args.payment.fee,
balance_changes: args.payment.balance_changes,
source_balance_changes: args.payment.source_balance_changes,
destination_balance_changes: args.payment.destination_balance_changes,
order_changes: args.payment.order_changes
},
source_slippage: args.source_slippage,
destination_account: args.destination_account,
destination_tag: args.destination_tag,
destination_amount: {
value: args.destination_amount.value,
currency: args.destination_amount.currency,
issuer: args.destination_amount.issuer
},
invoice_id: args.invoice_id,
paths: args.paths,
no_direct_ripple: args.no_direct_ripple,
partial_payment: args.partial_payment,
direction: args.direction,
result: args.result,
timestamp: args.timestamp,
fee: args.fee,
source_balance_changes: args.source_balance_changes,
destination_balance_changes: args.destination_balance_changes,
order_changes: args.order_changes
client_resource_id: args.client_resource_id,
hash: args.hash,
ledger: args.ledger,
state: args.state
};
};

Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/update_account_settings.js
Expand Up @@ -19,6 +19,6 @@ exports.error = function() {
success: false,
error_type: 'invalid_request',
error: 'restINVALID_PARAMETER',
message: 'Parameter missing: secret'
message: 'Parameter missing: settings'
};
};
16 changes: 5 additions & 11 deletions test/get_notification.js
Expand Up @@ -6,7 +6,7 @@ var account_info = require('./fixtures/account_info')();
var errorFixture = require('./fixtures/get_notification').error;
var success = require('./fixtures/get_notification').success;

describe('Ripple REST Client Get Notifications', function() {
describe('Ripple REST Client Get Notification', function() {
var client;
var payments;

Expand All @@ -26,19 +26,13 @@ describe('Ripple REST Client Get Notifications', function() {
done();
});

it('should get NO notification', function(done) {
client.getNotification(null, function(error, response) {
assert(!response, 'Response should be null');
assert(error);
assert.deepEqual(errorFixture(), error.response.body);
done();
});
});

// Given the hash for the second last payment, the response should contain the
// hashes of last payment and third last payment.
it('should get notifications', function(done) {
it('should get a notification', function(done) {
client.getNotification(payments[1].hash, function(error, response) {
if (error) {
return done(error);
}
assert(!error);
assert(response);
assert.deepEqual(success(response), response);
Expand Down
32 changes: 32 additions & 0 deletions test/get_notifications.js
@@ -0,0 +1,32 @@
var Client = require('../');
var assert = require('chai').assert;
var account_info = require('./fixtures/account_info')();
var errorFixture = require('./fixtures/get_notifications').error;
var success = require('./fixtures/get_notifications').success;

describe('Ripple REST Client Get Notifications', function() {
var client;

beforeEach(function(done) {
client = new Client({
account: account_info.source_account
});
done();
});

afterEach(function(done) {
client = undefined;
done();
});

it('should get notifications', function(done) {
client.getNotifications(function(error, response) {
if (error) {
return done(error);
}
assert(response.length > 0, 'No notifications');
assert.deepEqual(success(response[0]), success(response[0]));
done();
});
});
});
2 changes: 1 addition & 1 deletion test/get_server_status.js
Expand Up @@ -24,7 +24,7 @@ describe('Ripple REST Client Get Server Status', function() {
client.getServerStatus(null, function(error, response) {
assert(!error);
assert(response);
assert.deepEqual(success(response), response);
assert.deepEqual(Object.keys(success(response)), Object.keys(response));
done();
});
});
Expand Down
1 change: 1 addition & 0 deletions test/get_transaction.js
Expand Up @@ -17,6 +17,7 @@ describe('Ripple REST Client Get Transaction', function() {

client.getPayments(null, function(error, payment_array) {
payments = payment_array;
assert(payments[0], 'No payments');
done();
});
});
Expand Down
45 changes: 4 additions & 41 deletions test/send_and_confirm_payment.js
Expand Up @@ -31,14 +31,14 @@ describe('Ripple REST Client sendPayment', function() {
payment = {
source_account: account_info.source_account,
source_amount: {
value: '.005',
currency: 'SWD',
value: '0.005',
currency: 'GWD',
issuer: ''
},
destination_account: account_info.destination_account,
destination_amount: {
value: '1',
currency: 'SWD',
value: '0.005',
currency: 'GWD',
issuer: account_info.source_account
},
partial_payment: false,
Expand All @@ -53,48 +53,11 @@ describe('Ripple REST Client sendPayment', function() {
};

client.sendAndConfirmPayment(paymentObj, function(error, response) {
assert.strictEqual(response.source_account, payment.source_account);
assert.strictEqual(response.result, 'tecPATH_DRY');
assert.deepEqual(success(response), response);
done();
});
});

it('should successfully send and confirm a non-XRP payment', function(done) {
this.timeout(10000);
nonXRPayment = {
source_account: account_info.source_account,
source_amount: {
value: '1',
currency: 'SWD',
issuer: 'rMinhWxZz4jeHoJGyddtmwg6dWhyqQKtJz'
},
destination_account: account_info.destination_account,
destination_amount: {
value: '1',
currency: 'SWD',
issuer: 'rMinhWxZz4jeHoJGyddtmwg6dWhyqQKtJz'
},
partial_payment: false,
no_direct_ripple: false,
destination_tag: '0'
};

var nonXRPaymentObj = {
payment: nonXRPayment,
client_resource_id: uuid.v4(),
secret: SECRET
};

client.sendAndConfirmPayment(nonXRPaymentObj, function(error, response) {
assert.strictEqual(response.source_account, payment.source_account);
assert.strictEqual(response.result, 'tecPATH_DRY');
assert.strictEqual(response.destination_amount.currency, nonXRPayment.destination_amount.currency);
assert(success(response), response);
done();
});
});

it('should fail because destination account and amount is missing',
function(done) {
this.timeout(10000);
Expand Down

0 comments on commit 1cb02fb

Please sign in to comment.