Skip to content

Commit

Permalink
fix(api-request-builder): resetting customerId and cartId params
Browse files Browse the repository at this point in the history
  • Loading branch information
jimmythomson committed Sep 28, 2020
1 parent b6e6bb7 commit c4cd32f
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 2 deletions.
5 changes: 4 additions & 1 deletion packages/api-request-builder/src/default-params.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,11 @@ export function setDefaultParams() {

this.params.key = null

if (this.features.includes(features.queryOne))
if (this.features.includes(features.queryOne)) {
this.params.id = getDefaultQueryParams().id
this.params.customerId = null
this.params.cartId = null
}

if (this.features.includes(features.query)) {
this.params.pagination = getDefaultQueryParams().pagination
Expand Down
26 changes: 25 additions & 1 deletion packages/api-request-builder/test/create-request-builder.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ describe('createRequestBuilder', () => {
)
})

test('calling build resets all params', () => {
test('calling build resets all params after querying byKey', () => {
const requestBuilder = createRequestBuilder({
projectKey: 'foo',
})
Expand All @@ -77,4 +77,28 @@ describe('createRequestBuilder', () => {
.build()
expect(nextRequest).toEqual('/foo/categories?where=bar')
})

test('calling build resets all params after querying byCustomerId', () => {
const requestBuilder = createRequestBuilder({
projectKey: 'foo',
})
requestBuilder.carts.byCustomerId('1234').build()
const nextRequest = requestBuilder.carts
.parse({ where: ['cartState="Active"'] })
.build()
expect(nextRequest).toEqual('/foo/carts?where=cartState%3D%22Active%22')
})

test('calling build resets all params after querying byCartId', () => {
const requestBuilder = createRequestBuilder({
projectKey: 'foo',
})
requestBuilder.orders.byCartId('1234').build()
const nextRequest = requestBuilder.orders
.parse({ where: ['orderNumber="testOrderNum"'] })
.build()
expect(nextRequest).toEqual(
'/foo/orders?where=orderNumber%3D%22testOrderNum%22'
)
})
})
6 changes: 6 additions & 0 deletions packages/api-request-builder/test/default-params.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ describe('defaultParams', () => {
expect(params).toEqual({
id: null,
key: null,
customerId: null,
cartId: null,
expand: [],
pagination: {
page: null,
Expand All @@ -34,6 +36,8 @@ describe('defaultParams', () => {
expect(params).toEqual({
id: null,
key: null,
customerId: null,
cartId: null,
expand: [],
pagination: {
page: null,
Expand All @@ -60,6 +64,8 @@ describe('defaultParams', () => {
expect(params).toEqual({
id: null,
key: null,
customerId: null,
cartId: null,
expand: [],
pagination: {
page: null,
Expand Down

0 comments on commit c4cd32f

Please sign in to comment.