Skip to content

Commit

Permalink
[api] Add AccessScope resource
Browse files Browse the repository at this point in the history
Fixes: #170
  • Loading branch information
lpinca committed Mar 12, 2018
1 parent caef371 commit ddef800
Show file tree
Hide file tree
Showing 7 changed files with 83 additions and 1 deletion.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,8 @@ shopify.metafield.create({

### Available resources and methods

- accessScope
- `list()`
- apiPermission
- `delete()`
- applicationCharge
Expand Down
9 changes: 8 additions & 1 deletion index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,11 @@ type onCallLimitsFn = (limits: Shopify.ICallLimits) => void;
declare class Shopify {
constructor(config: Shopify.IPublicShopifyConfig | Shopify.IPrivateShopifyConfig);
callLimits: Shopify.ICallLimits;
accessScope: {
list: () => Promise<Shopify.IAccessScope[]>
};
apiPermission: {
delete(): void;
delete: () => Promise<void>;
};
// abandonedCheckouts
applicationCharge: {
Expand Down Expand Up @@ -428,6 +431,10 @@ declare namespace Shopify {
max: number;
}

interface IAccessScope {
handle: string
}

interface ICheckout {
abandoned_checkout_url: string;
applied_discount?: ICheckoutDiscount[];
Expand Down
30 changes: 30 additions & 0 deletions resources/access-scope.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
'use strict';

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

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

this.name = 'access_scopes';
}

/**
* Retrieves a list of access scopes associated to the access token.
*
* @return {Promise} Promise that resolves with the result
* @public
*/
AccessScope.prototype.list = function list() {
const path = `/admin/oauth/${this.name}.json`;
const url = assign({ path }, this.shopify.baseUrl);
return this.shopify.request(url, 'GET', this.name);
};

module.exports = AccessScope;
24 changes: 24 additions & 0 deletions test/access-scope.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
describe('Shopify#accessScope', () => {
'use strict';

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

const fixtures = require('./fixtures/access-scope');
const common = require('./common');

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

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

it('gets a list of access scopes associated to the access token', () => {
const output = fixtures.res.list;

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

return shopify.accessScope.list()
.then(data => expect(data).to.deep.equal(output.access_scopes));
});
});
3 changes: 3 additions & 0 deletions test/fixtures/access-scope/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
'use strict';

exports.res = require('./res');
3 changes: 3 additions & 0 deletions test/fixtures/access-scope/res/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
'use strict';

exports.list = require('./list');
13 changes: 13 additions & 0 deletions test/fixtures/access-scope/res/list.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"access_scopes": [
{
"handle": "read_products"
},
{
"handle": "write_orders"
},
{
"handle": "read_orders"
}
]
}

0 comments on commit ddef800

Please sign in to comment.