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

Commit

Permalink
feat: Add order items method (#85)
Browse files Browse the repository at this point in the history
* feat: Adding Items method for Orders class

* test: Tests passing

* build: Rollup
  • Loading branch information
ynnoj authored May 22, 2017
1 parent c0385bd commit 1dfffc8
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 2 deletions.
2 changes: 1 addition & 1 deletion dist/moltin.cjs.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/moltin.cjs.js.map

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions src/endpoints/orders.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ class OrdersEndpoint extends BaseExtend {
this.endpoint = 'orders';
}

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

Payment(id, body) {
return this.request.send(`${this.endpoint}/${id}/payments`, 'POST', body);
}
Expand Down
12 changes: 12 additions & 0 deletions test/factories.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,3 +149,15 @@ exports.ordersArray = [{
type: 'order',
status: 'cancelled',
}];

exports.orderItemsArray = [{
id: 'item-1',
type: 'order_item',
quantity: 2,
product_id: 'product-1',
}, {
id: 'item-2',
type: 'order_item',
quantity: 1,
product_id: 'product-2',
}];
19 changes: 19 additions & 0 deletions test/unit/orders.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const assert = require('chai').assert;
const nock = require('nock');
const moltin = require('../../dist/moltin.cjs.js');
const orders = require('../factories').ordersArray;
const orderItems = require('../factories').orderItemsArray;

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

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

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

return Moltin.Orders.Items(orders[0].id)
.then((response) => {
assert.propertyVal(response, 'id', 'item-1');
assert.propertyVal(response, 'product_id', 'product-1');
});
});

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

0 comments on commit 1dfffc8

Please sign in to comment.