Skip to content

Commit

Permalink
Merge pull request #92 from uniquelyparticular/develop
Browse files Browse the repository at this point in the history
Merge develop > master
  • Loading branch information
agrohs authored Feb 13, 2020
2 parents 5fc8017 + c636db0 commit 295524e
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 49 deletions.
97 changes: 51 additions & 46 deletions src/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,52 +1,57 @@
import { expect } from 'chai'
import fetch from 'fetch-everywhere'
import { createClient } from './index'

import { expect } from 'chai';
import fetch from 'fetch-everywhere';
import { createClient } from './index';

describe('Shopify index', () => {
it('fetch can be overridden', () => {
const shopify = new createClient({
store_name: 'XXX',
client_key: 'XXX',
client_pass: 'XXX',
fetch: fetch
})
expect(shopify.fetch).to.be.an.instanceof(Function)
})
it('fetch can be overridden', () => {
const shopify = new createClient({
store_name: 'XXX',
client_key: 'XXX',
client_pass: 'XXX',
fetch: fetch
});
expect(shopify.fetch).to.be.an.instanceof(Function);
});

it('get products', () => {
const shopify = new createClient({
store_name: 'XXX',
client_key: 'XXX',
client_pass: 'XXX',
fetch: fetch
})
it('get products', () => {
const shopify = new createClient({
store_name: 'XXX',
client_key: 'XXX',
client_pass: 'XXX',
fetch: fetch
});

return shopify
.get('admin/products.json')
.then(results => {
expect(results).to.not.be.null
})
.catch(error => {
expect(error).to.deep.equal({ statusCode: 404, body: { message: 'Not Found' } })
})
})
return shopify
.get('admin/products.json')
.then(results => {
expect(results).to.not.be.null;
})
.catch(error => {
expect(error).to.deep.equal({
statusCode: 404,
body: { message: 'Not Found', errors: 'Not Found' }
});
});
});

it('get products with custom fetch', () => {
const shopify = new createClient({
store_name: 'XXX',
client_key: 'XXX',
client_pass: 'XXX',
fetch: fetch
})
it('get products with custom fetch', () => {
const shopify = new createClient({
store_name: 'XXX',
client_key: 'XXX',
client_pass: 'XXX',
fetch: fetch
});

return shopify
.get('admin/products.json')
.then(results => {
expect(results).to.not.be.null
})
.catch(error => {
expect(error).to.deep.equal({ statusCode: 404, body: { message: 'Not Found' } })
})
})
})
return shopify
.get('admin/products.json')
.then(results => {
expect(results).to.not.be.null;
})
.catch(error => {
expect(error).to.deep.equal({
statusCode: 404,
body: { message: 'Not Found', errors: 'Not Found' }
});
});
});
});
7 changes: 4 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,16 +84,17 @@ export class createClient {

if (response.status === 204) return response.text();

const json = await response.json();

if (response.status >= 400)
throw {
statusCode: response.status,
body: {
message: response.statusText
message: response.statusText,
...json
}
};

const json = await response.json();

if (!response.ok) {
throw {
statusCode: response.status,
Expand Down

0 comments on commit 295524e

Please sign in to comment.