diff --git a/src/endpoints/catalog.js b/src/endpoints/catalog.js index d348e42..40c9b2c 100644 --- a/src/endpoints/catalog.js +++ b/src/endpoints/catalog.js @@ -128,8 +128,13 @@ class Hierarchies extends ShopperCatalogQuery { } All({ token = null, additionalHeaders = null } = {}) { + const { limit, offset } = this + return this.request.send( - `catalog/${this.endpoint}`, + buildURL(`catalog/${this.endpoint}`, { + limit, + offset + }), 'GET', undefined, token, @@ -157,8 +162,13 @@ class Hierarchies extends ShopperCatalogQuery { token = null, additionalHeaders = null }) { + const { limit, offset } = this + return this.request.send( - `catalog/${this.endpoint}/${hierarchyId}/children`, + buildURL(`catalog/${this.endpoint}/${hierarchyId}/children`, { + limit, + offset + }), 'GET', undefined, token, @@ -174,8 +184,13 @@ class Hierarchies extends ShopperCatalogQuery { token = null, additionalHeaders = null } = {}) { + const { limit, offset } = this + return this.request.send( - `catalog/${this.endpoint}/${hierarchyId}/nodes`, + buildURL(`catalog/${this.endpoint}/${hierarchyId}/nodes`, { + limit, + offset + }), 'GET', undefined, token, diff --git a/src/endpoints/catalogs.js b/src/endpoints/catalogs.js index e12be3e..c5d1138 100644 --- a/src/endpoints/catalogs.js +++ b/src/endpoints/catalogs.js @@ -12,8 +12,12 @@ class Nodes extends CRUDExtend { } All({ token = null }) { + const { limit, offset } = this return this.request.send( - `catalogs/${this.endpoint}`, + buildURL(`catalogs/${this.endpoint}`, { + limit, + offset + }), 'GET', undefined, token diff --git a/src/endpoints/nodes.js b/src/endpoints/nodes.js index 5c1d689..101233a 100644 --- a/src/endpoints/nodes.js +++ b/src/endpoints/nodes.js @@ -10,10 +10,13 @@ class NodesEndpoint { this.endpoint = 'nodes' } - // TODO: API - currently not working! (can get from hierarchy relationships) All({ hierarchyId, token = null }) { + const { limit, offset } = this return this.request.send( - `hierarchies/${hierarchyId}/${this.endpoint}`, + buildURL(`hierarchies/${hierarchyId}/${this.endpoint}`, { + limit, + offset + }), 'GET', undefined, token diff --git a/src/types/nodes.d.ts b/src/types/nodes.d.ts index 048a850..3d8496c 100644 --- a/src/types/nodes.d.ts +++ b/src/types/nodes.d.ts @@ -84,7 +84,6 @@ export interface NodesEndpoint { token?: string }): Promise> - // TODO: API - currently not working! (can get from hierarchy relationships) All(options: { hierarchyId: string token?: string diff --git a/test/tests.ts b/test/tests.ts index 7192e73..c4b6ae6 100644 --- a/test/tests.ts +++ b/test/tests.ts @@ -6,8 +6,11 @@ require('./unit/customer-addresses') require('./unit/account-addresses') require('./unit/brands') require('./unit/cart') +require('./unit/catalog') +require('./unit/catalogs') require('./unit/categories') require('./unit/collections') +require('./unit/nodes') require('./unit/currencies') require('./unit/customers') require('./unit/fields') diff --git a/test/unit/catalog.ts b/test/unit/catalog.ts new file mode 100644 index 0000000..6fc9198 --- /dev/null +++ b/test/unit/catalog.ts @@ -0,0 +1,88 @@ +import { assert } from 'chai' +import nock from 'nock' +import { gateway as ElasticPathGateway } from '../../src' + +const apiUrl = 'https://euwest.api.elasticpath.com' + +describe('ElasticPath ShopperCatalog hierarchies pagination', () => { + it('should pass page[limit] and page[offset] to Hierarchies.All', () => { + const ElasticPath = ElasticPathGateway({ + client_id: 'XXX' + }) + + nock(apiUrl, { + reqheaders: { + Authorization: 'Bearer a550d8cbd4a4627013452359ab69694cd446615a' + } + }) + .get('/catalog/hierarchies') + .query({ + page: { + limit: 10, + offset: 20 + } + }) + .reply(200, { data: [] }) + + return ElasticPath.ShopperCatalog.Hierarchies.Limit(10) + .Offset(20) + .All() + .then(response => { + assert.exists(response.data) + }) + }) + + it('should pass page[limit] and page[offset] to GetHierarchyChildren', () => { + const ElasticPath = ElasticPathGateway({ + client_id: 'XXX' + }) + + nock(apiUrl, { + reqheaders: { + Authorization: 'Bearer a550d8cbd4a4627013452359ab69694cd446615a' + } + }) + .get('/catalog/hierarchies/hierarchy-1/children') + .query({ + page: { + limit: 5, + offset: 15 + } + }) + .reply(200, { data: [] }) + + return ElasticPath.ShopperCatalog.Hierarchies.Limit(5) + .Offset(15) + .GetHierarchyChildren({ hierarchyId: 'hierarchy-1' }) + .then(response => { + assert.exists(response.data) + }) + }) + + it('should pass page[limit] and page[offset] to GetHierarchyNodes', () => { + const ElasticPath = ElasticPathGateway({ + client_id: 'XXX' + }) + + nock(apiUrl, { + reqheaders: { + Authorization: 'Bearer a550d8cbd4a4627013452359ab69694cd446615a' + } + }) + .get('/catalog/hierarchies/hierarchy-1/nodes') + .query({ + page: { + limit: 7, + offset: 21 + } + }) + .reply(200, { data: [] }) + + return ElasticPath.ShopperCatalog.Hierarchies.Limit(7) + .Offset(21) + .GetHierarchyNodes({ hierarchyId: 'hierarchy-1' }) + .then(response => { + assert.exists(response.data) + }) + }) +}) diff --git a/test/unit/catalogs.ts b/test/unit/catalogs.ts new file mode 100644 index 0000000..877e089 --- /dev/null +++ b/test/unit/catalogs.ts @@ -0,0 +1,76 @@ +import { assert } from 'chai' +import nock from 'nock' +import { gateway as ElasticPathGateway } from '../../src' + +const apiUrl = 'https://euwest.api.elasticpath.com/pcm' + +describe('ElasticPath catalogs pagination', () => { + it('should pass page[limit] and page[offset] to Catalogs.Nodes.All', () => { + const ElasticPath = ElasticPathGateway({ + client_id: 'XXX' + }) + + nock(apiUrl, { + reqheaders: { + Authorization: 'Bearer a550d8cbd4a4627013452359ab69694cd446615a' + } + }) + .get('/catalogs/nodes') + .query({ + page: { + limit: 10, + offset: 20 + } + }) + .reply(200, { data: [] }) + + return ElasticPath.Catalogs.Nodes.Limit(10) + .Offset(20) + .All({}) + .then(response => { + assert.exists(response.data) + }) + }) +}) + +describe('ElasticPath catalogs Releases.All URL shape', () => { + it('should request catalogs/{catalogId}/releases (not catalogs/releases/{catalogId})', () => { + const ElasticPath = ElasticPathGateway({ + client_id: 'XXX' + }) + + nock(apiUrl, { + reqheaders: { + Authorization: 'Bearer a550d8cbd4a4627013452359ab69694cd446615a' + } + }) + .get('/catalogs/catalog-1/releases') + .reply(200, { data: [] }) + + return ElasticPath.Catalogs.Releases.All({ + catalogId: 'catalog-1' + }).then(response => { + assert.exists(response.data) + }) + }) + + it('should request catalogs/{catalogId}/releases via Catalogs.GetCatalogReleases', () => { + const ElasticPath = ElasticPathGateway({ + client_id: 'XXX' + }) + + nock(apiUrl, { + reqheaders: { + Authorization: 'Bearer a550d8cbd4a4627013452359ab69694cd446615a' + } + }) + .get('/catalogs/catalog-1/releases') + .reply(200, { data: [] }) + + return ElasticPath.Catalogs.GetCatalogReleases('catalog-1').then( + response => { + assert.exists(response.data) + } + ) + }) +}) diff --git a/test/unit/nodes.ts b/test/unit/nodes.ts new file mode 100644 index 0000000..2e72902 --- /dev/null +++ b/test/unit/nodes.ts @@ -0,0 +1,34 @@ +import { assert } from 'chai' +import nock from 'nock' +import { gateway as ElasticPathGateway } from '../../src' + +const apiUrl = 'https://euwest.api.elasticpath.com/pcm' + +describe('ElasticPath hierarchy nodes pagination', () => { + it('should pass page[limit] and page[offset] to All', () => { + const ElasticPath = ElasticPathGateway({ + client_id: 'XXX' + }) + + nock(apiUrl, { + reqheaders: { + Authorization: 'Bearer a550d8cbd4a4627013452359ab69694cd446615a' + } + }) + .get('/hierarchies/hierarchy-1/nodes') + .query({ + page: { + limit: 10, + offset: 20 + } + }) + .reply(200, { data: [] }) + + return ElasticPath.Hierarchies.Nodes.Limit(10) + .Offset(20) + .All({ hierarchyId: 'hierarchy-1' }) + .then(response => { + assert.exists(response.data) + }) + }) +})