Skip to content
Merged
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
21 changes: 18 additions & 3 deletions src/endpoints/catalog.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand Down
6 changes: 5 additions & 1 deletion src/endpoints/catalogs.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 5 additions & 2 deletions src/endpoints/nodes.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion src/types/nodes.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ export interface NodesEndpoint {
token?: string
}): Promise<Resource<Node>>

// TODO: API - currently not working! (can get from hierarchy relationships)
All(options: {
hierarchyId: string
token?: string
Expand Down
3 changes: 3 additions & 0 deletions test/tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
88 changes: 88 additions & 0 deletions test/unit/catalog.ts
Original file line number Diff line number Diff line change
@@ -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)
})
})
})
76 changes: 76 additions & 0 deletions test/unit/catalogs.ts
Original file line number Diff line number Diff line change
@@ -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)
}
)
})
})
34 changes: 34 additions & 0 deletions test/unit/nodes.ts
Original file line number Diff line number Diff line change
@@ -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)
})
})
})
Loading