Skip to content

Commit

Permalink
Milestone/v6.25.0 (#345)
Browse files Browse the repository at this point in the history
Add request in error object passed to interceptors
Update resources to OpenAPI schema v7.4.0
  • Loading branch information
pviti authored Nov 6, 2024
2 parents 56101c6 + 1d8d4ab commit 21c6919
Show file tree
Hide file tree
Showing 21 changed files with 3,320 additions and 772 deletions.
2,755 changes: 2,174 additions & 581 deletions gen/openapi.json

Large diffs are not rendered by default.

282 changes: 273 additions & 9 deletions gen/resources.json

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,12 @@
"@babel/preset-env": "^7.26.0",
"@babel/preset-typescript": "^7.26.0",
"@commercelayer/eslint-config-ts": "1.4.5",
"@commercelayer/js-auth": "^6.6.4",
"@commercelayer/js-auth": "^6.7.0",
"@semantic-release/changelog": "^6.0.3",
"@semantic-release/git": "^10.0.1",
"@types/debug": "^4.1.12",
"@types/jest": "^29.5.14",
"@types/node": "^22.8.4",
"@types/node": "^22.9.0",
"dotenv": "^16.4.5",
"eslint": "^8.57.1",
"jest": "^29.7.0",
Expand Down
349 changes: 175 additions & 174 deletions pnpm-lock.yaml

Large diffs are not rendered by default.

28 changes: 27 additions & 1 deletion specs/error.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

import { CommerceLayerClient } from '../src'
import { CommerceLayerClient, ErrorObj } from '../src'
import { ErrorType } from '../src/error'
import { getClient } from '../test/common'

Expand All @@ -9,6 +9,8 @@ let cl: CommerceLayerClient

beforeAll(async () => { cl = await getClient({}) })

afterAll(() => { cl.removeInterceptors() })


describe('SDK:error suite', () => {

Expand Down Expand Up @@ -40,4 +42,28 @@ describe('SDK:error suite', () => {
}
})


it('ErrorInterceptor.response', async () => {

cl = await getClient({})

let interceptor = false

cl.addResponseInterceptor(undefined, (error: ErrorObj): ErrorObj => {
expect(error).toBeDefined()
expect(error.request).toBeDefined()
expect(error.request?.method).toBe('POST')
interceptor = true
return error
})

try {
await cl.customers.create({ email: '' })
} catch (error) {
expect(error.type).toBe(ErrorType.RESPONSE)
expect(interceptor).toBeTruthy()
}

})

})
21 changes: 21 additions & 0 deletions specs/resources/markets.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,27 @@ describe('Markets resource', () => {
/* relationship.geocoder stop */


/* relationship.stores start */
it(resourceType + '.stores', async () => {

const id = TestData.id
const params = { fields: { stores: CommonData.paramsFields } }

const intId = cl.addRequestInterceptor((request) => {
expect(request.options.method).toBe('GET')
checkCommon(request, resourceType, id, currentAccessToken, 'stores')
checkCommonParams(request, params)
return interceptRequest()
})

await cl[resourceType].stores(id, params, CommonData.options)
.catch(handleError)
.finally(() => cl.removeInterceptor('request'))

})
/* relationship.stores stop */


/* relationship.price_list_schedulers start */
it(resourceType + '.price_list_schedulers', async () => {

Expand Down
22 changes: 22 additions & 0 deletions specs/resources/orders.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ describe('Orders resource', () => {
customer: cl.customers.relationship(TestData.id),
shipping_address: cl.addresses.relationship(TestData.id),
billing_address: cl.addresses.relationship(TestData.id),
store: cl.stores.relationship(TestData.id),
payment_method: cl.payment_methods.relationship(TestData.id),
payment_source: cl.adyen_payments.relationship(TestData.id),
tags: [ cl.tags.relationship(TestData.id) ],
Expand Down Expand Up @@ -290,6 +291,27 @@ describe('Orders resource', () => {
/* relationship.billing_address stop */


/* relationship.store start */
it(resourceType + '.store', async () => {

const id = TestData.id
const params = { fields: { stores: CommonData.paramsFields } }

const intId = cl.addRequestInterceptor((request) => {
expect(request.options.method).toBe('GET')
checkCommon(request, resourceType, id, currentAccessToken, 'store')
checkCommonParams(request, params)
return interceptRequest()
})

await cl[resourceType].store(id, params, CommonData.options)
.catch(handleError)
.finally(() => cl.removeInterceptor('request'))

})
/* relationship.store stop */


/* relationship.available_payment_methods start */
it(resourceType + '.available_payment_methods', async () => {

Expand Down
22 changes: 22 additions & 0 deletions specs/resources/payment_methods.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ describe('PaymentMethods resource', () => {
price_amount_cents: randomValue('integer', 'price_amount_cents'),
market: cl.markets.relationship(TestData.id),
payment_gateway: cl.payment_gateways.relationship(TestData.id),
store: cl.stores.relationship(TestData.id),
}

const attributes = { ...createAttributes, reference: TestData.reference }
Expand Down Expand Up @@ -245,6 +246,27 @@ describe('PaymentMethods resource', () => {
/* relationship.payment_gateway stop */


/* relationship.store start */
it(resourceType + '.store', async () => {

const id = TestData.id
const params = { fields: { stores: CommonData.paramsFields } }

const intId = cl.addRequestInterceptor((request) => {
expect(request.options.method).toBe('GET')
checkCommon(request, resourceType, id, currentAccessToken, 'store')
checkCommonParams(request, params)
return interceptRequest()
})

await cl[resourceType].store(id, params, CommonData.options)
.catch(handleError)
.finally(() => cl.removeInterceptor('request'))

})
/* relationship.store stop */


/* relationship.attachments start */
it(resourceType + '.attachments', async () => {

Expand Down
21 changes: 21 additions & 0 deletions specs/resources/stock_locations.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,27 @@ describe('StockLocations resource', () => {
/* relationship.stock_transfers stop */


/* relationship.stores start */
it(resourceType + '.stores', async () => {

const id = TestData.id
const params = { fields: { stores: CommonData.paramsFields } }

const intId = cl.addRequestInterceptor((request) => {
expect(request.options.method).toBe('GET')
checkCommon(request, resourceType, id, currentAccessToken, 'stores')
checkCommonParams(request, params)
return interceptRequest()
})

await cl[resourceType].stores(id, params, CommonData.options)
.catch(handleError)
.finally(() => cl.removeInterceptor('request'))

})
/* relationship.stores stop */


/* relationship.attachments start */
it(resourceType + '.attachments', async () => {

Expand Down
Loading

0 comments on commit 21c6919

Please sign in to comment.