Skip to content
This repository has been archived by the owner on Jul 24, 2024. It is now read-only.

Commit

Permalink
feat: Add method to GET all transactions on an order (#111)
Browse files Browse the repository at this point in the history
  • Loading branch information
ynnoj authored Sep 12, 2017
1 parent 80be7a3 commit d088111
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 1 deletion.
5 changes: 5 additions & 0 deletions src/endpoints/orders.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ class OrdersEndpoint extends BaseExtend {
Payment(id, body) {
return this.request.send(`${this.endpoint}/${id}/payments`, 'POST', body);
}

Transactions(id) {
return this.request.send(`${this.endpoint}/${id}/transactions`, 'GET');
}

}

export default OrdersEndpoint;
37 changes: 37 additions & 0 deletions test/factories.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,3 +161,40 @@ export const orderItemsArray = [{
quantity: 1,
product_id: 'product-2',
}];

export const orderTransactionsArray = [{
id: 'transaction-1',
type: 'transaction',
reference: 'ch_1AzkYiFnpfya5sMz8gVp6Ds6',
gateway: 'stripe',
amount: 159800,
currency: 'NOK',
'transaction-type': 'purchase',
status: 'complete',
relationships: {
order: {
data: {
type: 'order',
id: 'c5530906-7b68-42ee-99c3-68cfebdcd749',
},
},
},
},
{
id: 'transaction-2',
type: 'transaction',
reference: 'ch_1AzkYiFnpfya5sMz8gVp6Ds6',
gateway: 'stripe',
amount: 159800,
currency: 'NOK',
'transaction-type': 'purchase',
status: 'complete',
relationships: {
order: {
data: {
type: 'order',
id: 'c5530906-7b68-42ee-99c3-68cfebdcd749',
},
},
},
}];
20 changes: 19 additions & 1 deletion test/unit/orders.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { assert } from 'chai';
import nock from 'nock';
import { gateway as MoltinGateway } from '../../src/moltin';
import { ordersArray as orders, orderItemsArray as orderItems } from '../factories';
import { ordersArray as orders, orderItemsArray as orderItems, orderTransactionsArray as orderTransactions } from '../factories';

const apiUrl = 'https://api.moltin.com/v2';

Expand Down Expand Up @@ -64,6 +64,24 @@ describe('Moltin orders', () => {
});
});

it('should return an array of transactions from an order', () => {
// Intercept the API request
nock(apiUrl, {
reqHeaders: {
Authorization: 'a550d8cbd4a4627013452359ab69694cd446615a',
'Content-Type': 'application/json',
},
})
.get('/orders/order-1/transactions')
.reply(200, orderTransactions[0]);

return Moltin.Orders.Transactions(orders[0].id)
.then((response) => {
assert.propertyVal(response, 'id', 'transaction-1');
assert.nestedPropertyVal(response, 'relationships.order.data.id', 'c5530906-7b68-42ee-99c3-68cfebdcd749');
});
});

it('should complete a payment for an order', () => {
// Intercept the API request
nock(apiUrl, {
Expand Down

0 comments on commit d088111

Please sign in to comment.