Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -445,6 +445,12 @@ shopify.metafield.create({
- `create(params)`
- `delete(id)`
- `list()`
- taxService
- `create(params)`
- `delete(id)`
- `get(id)`
- `list()`
- `update(id, params)`
- theme
- `create(params)`
- `delete(id)`
Expand Down
36 changes: 36 additions & 0 deletions resources/tax-service.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
'use strict';

const assign = require('lodash/assign');
const omit = require('lodash/omit');

const base = require('../mixins/base');

/**
* Creates a TaxService instance.
*
* @param {Shopify} shopify Reference to the Shopify instance
* @constructor
* @public
*/
function TaxService(shopify) {
this.shopify = shopify;

this.name = 'tax_services';
this.key = 'tax_service';
}

assign(TaxService.prototype, omit(base, ['count', 'delete']));

/**
* Destroys a tax service.
*
* @param {Number} Tax service ID
* @return {Promise} Promise that resolves with the result
* @public
*/
TaxService.prototype.delete = function remove(id) {
const url = this.buildUrl(id);
return this.shopify.request(url, 'DELETE', this.key);
};

module.exports = TaxService;
4 changes: 4 additions & 0 deletions test/fixtures/tax-service/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
'use strict';

exports.req = require('./req');
exports.res = require('./res');
6 changes: 6 additions & 0 deletions test/fixtures/tax-service/req/create.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"tax_service": {
"name": "My Tax Service",
"url": "https://tax.myservice.com"
}
}
4 changes: 4 additions & 0 deletions test/fixtures/tax-service/req/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
'use strict';

exports.create = require('./create');
exports.update = require('./update');
8 changes: 8 additions & 0 deletions test/fixtures/tax-service/req/update.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"tax_service": {
"id": 760126902,
"name": "Some new name",
"url": "https://tax-api.avalara.com",
"active": true
}
}
8 changes: 8 additions & 0 deletions test/fixtures/tax-service/res/create.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"tax_service": {
"id": 883755539,
"name": "My Tax Service",
"url": "https://tax.myservice.com",
"active": false
}
}
8 changes: 8 additions & 0 deletions test/fixtures/tax-service/res/delete.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"tax_service": {
"id": 760126902,
"name": "Avalara",
"url": "https://tax-api.avalara.com",
"active": false
}
}
8 changes: 8 additions & 0 deletions test/fixtures/tax-service/res/get.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"tax_service": {
"id": 760126902,
"name": "Avalara",
"url": "https://tax-api.avalara.com",
"active": true
}
}
7 changes: 7 additions & 0 deletions test/fixtures/tax-service/res/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
'use strict';

exports.create = require('./create');
exports.delete = require('./delete');
exports.update = require('./update');
exports.list = require('./list');
exports.get = require('./get');
10 changes: 10 additions & 0 deletions test/fixtures/tax-service/res/list.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"tax_services": [
{
"id": 760126902,
"name": "Avalara",
"url": "https://tax-api.avalara.com",
"active": true
}
]
}
8 changes: 8 additions & 0 deletions test/fixtures/tax-service/res/update.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"tax_service": {
"id": 760126902,
"name": "Some new name",
"url": "https://tax-api.avalara.com",
"active": true
}
}
70 changes: 70 additions & 0 deletions test/tax-service.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
describe('Shopify#taxService', () => {
'use strict';

const expect = require('chai').expect;

const fixtures = require('./fixtures/tax-service');
const common = require('./common');

const shopify = common.shopify;
const scope = common.scope;

afterEach(() => expect(scope.isDone()).to.be.true);

it('creates a tax service', () => {
const input = fixtures.req.create;
const output = fixtures.res.create;

scope
.post('/admin/tax_services.json', input)
.reply(201, output);

return shopify.taxService.create(input.tax_service)
.then(data => expect(data).to.deep.equal(output.tax_service));
});

it('updates a tax service', () => {
const input = fixtures.req.update;
const output = fixtures.res.update;

scope
.put('/admin/tax_services/760126902.json', input)
.reply(200, output);

return shopify.taxService.update(760126902, input.tax_service)
.then(data => expect(data).to.deep.equal(output.tax_service));
});

it('gets a list of all tax services', () => {
const output = fixtures.res.list;

scope
.get('/admin/tax_services.json')
.reply(200, output);

return shopify.taxService.list()
.then(data => expect(data).to.deep.equal(output.tax_services));
});

it('gets a single tax service by its ID', () => {
const output = fixtures.res.get;

scope
.get('/admin/tax_services/760126902.json')
.reply(200, output);

return shopify.taxService.get(760126902)
.then(data => expect(data).to.deep.equal(output.tax_service));
});

it('deletes a tax service', () => {
const output = fixtures.res.delete;

scope
.delete('/admin/tax_services/760126902.json')
.reply(200, output);

return shopify.taxService.delete(760126902)
.then(data => expect(data).to.deep.equal(output.tax_service));
});
});