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

Commit

Permalink
Merge pull request #135 from derom/fix-get-request-with-query
Browse files Browse the repository at this point in the history
Fix get request with query
  • Loading branch information
thecodepixi authored Mar 24, 2021
2 parents 7b05bd0 + 0b6d71c commit 241e988
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 7 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ and adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
- Improved documentation for GraphQL and Rest Clients. [#123](https://github.com/Shopify/shopify-node-api/pull/123)
- Made Docs directory more browseable in GitHub. [#136](https://github.com/Shopify/shopify-node-api/pull/136)
- Make sure `CustomSessionStorage` converts the `expires` field from a string to `Date`. [#132](https://github.com/Shopify/shopify-node-api/pull/132)
- Made `limit` optional for get-requests with query [#135](https://github.com/Shopify/shopify-node-api/pull/135)

## [1.1.0] - 2021-03-02

Expand Down
6 changes: 0 additions & 6 deletions src/clients/rest/page_info/types.ts

This file was deleted.

3 changes: 2 additions & 1 deletion src/clients/rest/rest_client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {RestRequestReturn, PageInfo} from './types';

class RestClient extends HttpClient {
private static LINK_HEADER_REGEXP = /<([^<]+)>; rel="([^"]+)"/;
private static DEFAULT_LIMIT = '50';

public constructor(domain: string, readonly accessToken?: string) {
super(domain);
Expand All @@ -32,7 +33,7 @@ class RestClient extends HttpClient {
const link = ret.headers.get('link');
if (params.query && link !== undefined) {
const pageInfo: PageInfo = {
limit: params.query.limit.toString(),
limit: params.query.limit ? params.query.limit.toString() : RestClient.DEFAULT_LIMIT,
};

if (link) {
Expand Down
15 changes: 15 additions & 0 deletions src/clients/rest/test/rest_client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,21 @@ describe('REST client', () => {
assertHttpRequest({method: 'GET', domain, path: '/admin/api/unstable/products.json'});
});

it('can make GET request with path in query', async () => {
const client = new RestClient(domain, 'dummy-token');

fetchMock.mockResponseOnce(JSON.stringify(successResponse));
const getRequest = {
path: 'products',
query: {
path: 'some_path',
},
};

await expect(client.get(getRequest)).resolves.toEqual(buildExpectedResponse(successResponse));
assertHttpRequest({method: 'GET', domain, path: '/admin/api/unstable/products.json?path=some_path'});
});

it('can make POST request with JSON data', async () => {
const client = new RestClient(domain, 'dummy-token');

Expand Down

0 comments on commit 241e988

Please sign in to comment.