Skip to content

Commit

Permalink
feat: update resources to schema v5.4.0
Browse files Browse the repository at this point in the history
  • Loading branch information
pviti committed Jun 6, 2024
1 parent 91f7a2a commit aaf9f61
Show file tree
Hide file tree
Showing 12 changed files with 2,824 additions and 1,081 deletions.
1,319 changes: 1,077 additions & 242 deletions gen/openapi.json

Large diffs are not rendered by default.

323 changes: 310 additions & 13 deletions gen/resources.json

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,15 @@
"node": ">=20"
},
"devDependencies": {
"@babel/preset-env": "^7.24.6",
"@babel/preset-typescript": "^7.24.6",
"@babel/preset-env": "^7.24.7",
"@babel/preset-typescript": "^7.24.7",
"@commercelayer/eslint-config-ts": "1.4.5",
"@commercelayer/js-auth": "^6.2.2",
"@semantic-release/changelog": "^6.0.3",
"@semantic-release/git": "^10.0.1",
"@types/debug": "^4.1.12",
"@types/jest": "^29.5.12",
"@types/node": "^20.14.1",
"@types/node": "^20.14.2",
"dotenv": "^16.4.5",
"eslint": "^8.57.0",
"jest": "^29.7.0",
Expand All @@ -49,7 +49,7 @@
"lodash.isequal": "^4.5.0",
"semantic-release": "^23.1.1",
"tsup": "^8.1.0",
"tsx": "^4.11.2",
"tsx": "^4.12.0",
"typescript": "^5.4.5"
},
"repository": "github:commercelayer/commercelayer-sdk",
Expand Down
1,694 changes: 880 additions & 814 deletions pnpm-lock.yaml

Large diffs are not rendered by default.

281 changes: 281 additions & 0 deletions specs/resources/links.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,281 @@
/**
* ©2024 Commerce Layer Inc.
* Source code generated automatically by SDK codegen
**/

import { CommerceLayerClient, Link } from '../../src'
import isEqual from 'lodash.isequal'
// eslint-disable-next-line @typescript-eslint/no-unused-vars
import { getClient, TestData, CommonData, handleError, interceptRequest, checkCommon, checkCommonData, checkCommonParamsList, checkCommonParams, currentAccessToken, randomValue } from '../../test/common'



let cl: CommerceLayerClient


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


describe('Links resource', () => {

const resourceType = 'links'


/* spec.create.start */
it(resourceType + '.create', async () => {

const createAttributes = {
name: randomValue('string', 'name'),
client_id: randomValue('string', 'client_id'),
scope: randomValue('string', 'scope'),
starts_at: randomValue('string', 'starts_at'),
expires_at: randomValue('string', 'expires_at'),
item: cl.orders.relationship(TestData.id),
}

const attributes = { ...createAttributes, reference: TestData.reference }
const params = { fields: { [resourceType]: CommonData.paramsFields } }
const resData = attributes

cl.addRequestInterceptor((request) => {
const data = JSON.parse(String(request.options.body))
expect(request.options.method).toBe('POST')
checkCommon(request, resourceType)
checkCommonData(data, resourceType, attributes)
expect(cl[resourceType].isLink(data.data)).toBeTruthy()
return interceptRequest()
})

await cl[resourceType].create(resData, params, CommonData.options)
.then((res: Link) => expect(res).not.toBeNull())
.catch(handleError)
.finally(() => cl.removeInterceptor('request'))

})
/* spec.create.stop */


/* spec.retrieve.start */
it(resourceType + '.retrieve', async () => {

const id = TestData.id
const params = { fields: {[resourceType]: CommonData.paramsFields } }

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

await cl[resourceType].retrieve(id, params, CommonData.options)
.then((res: Link) => expect(res).not.toBeNull())
.catch(handleError)
.finally(() => cl.removeInterceptor('request'))

})
/* spec.retrieve.stop */


/* spec.update.start */
it(resourceType + '.update', async () => {

const attributes = { reference_origin: TestData.reference_origin, metadata: TestData.metadata }
const params = { fields: { [resourceType]: CommonData.paramsFields } }
const resData = { id: TestData.id, ...attributes}

cl.addRequestInterceptor((request) => {
const data = JSON.parse(String(request.options.body))
expect(request.options.method).toBe('PATCH')
checkCommon(request, resourceType, resData.id, currentAccessToken)
checkCommonData(data, resourceType, attributes, resData.id)
return interceptRequest()
})

await cl[resourceType].update(resData, params, CommonData.options)
.then((res: Link) => expect(res).not.toBeNull())
.catch(handleError)
.finally(() => cl.removeInterceptor('request'))

})
/* spec.update.stop */


/* spec.delete.start */
it(resourceType + '.delete', async () => {

const id = TestData.id

cl.addRequestInterceptor((request) => {
expect(request.options.method).toBe('DELETE')
checkCommon(request, resourceType, id, currentAccessToken)
return interceptRequest()
})

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

})
/* spec.delete.stop */


/* spec.list.start */
it(resourceType + '.list', async () => {

const params = CommonData.paramsList

cl.addRequestInterceptor((request) => {
expect(request.options.method).toBe('GET')
checkCommon(request, resourceType)
checkCommonParamsList(request, params)
return interceptRequest()
})

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

})
/* spec.list.stop */


/* spec.type.start */
it(resourceType + '.type', async () => {

const resource = { id: TestData.id, type: resourceType }
expect(cl[resourceType].isLink(resource)).toBeTruthy()

const type = cl[resourceType].type()
expect(type).toBe(resourceType)

})
/* spec.type.stop */


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

const relId = cl[resourceType].relationship(TestData.id)
expect(isEqual(relId, { id: TestData.id, type: resourceType}))

const relResId = cl[resourceType].relationship({ id: TestData.id, type: resourceType })
expect(isEqual(relResId, { id: TestData.id, type: resourceType}))

})
/* spec.relationship.stop */


/* spec.parse.start */
/*
it(resourceType + '.parse', async () => {
const reference = 'myReferenceId'
const payload = `
{
"data": {
"id": "AbcdEfgHiL",
"meta": {
"mode": "test",
"organization_id": "myOrgId"
},
"type": "${resourceType}",
"links": {
"self": "https://sdk-test-org.commercelayer.io/api/${resourceType}/AbcdEfgHiL"
},
"attributes": {
"metadata": {},
"reference": "${reference}",
"created_at": "2023-10-01T05:53:29.296Z",
"updated_at": "2023-10-10T08:52:13.251Z"
}
}
}
`
const res = cl[resourceType].parse(payload) as Link
expect(res.type).toBe(resourceType)
expect(res.reference).toBe(reference)
})
*/
/* spec.parse.stop */



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

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

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

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

})
/* relationship.events stop */



/* trigger._disable start */
it(resourceType + '._disable', async () => {

let triggerAttr = '_disable'
if (!triggerAttr.startsWith('_')) triggerAttr = `_${triggerAttr}`

const triggerValue = true
const attributes = { [triggerAttr]: triggerValue }
const id = TestData.id

const intId = cl.addRequestInterceptor((request) => {
const data = JSON.parse(String(request.options.body))
expect(request.options.method).toBe('PATCH')
checkCommon(request, resourceType, id, currentAccessToken)
checkCommonData(data, resourceType, attributes, id)
return interceptRequest()
})

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

})
/* trigger._disable stop */


/* trigger._enable start */
it(resourceType + '._enable', async () => {

let triggerAttr = '_enable'
if (!triggerAttr.startsWith('_')) triggerAttr = `_${triggerAttr}`

const triggerValue = true
const attributes = { [triggerAttr]: triggerValue }
const id = TestData.id

const intId = cl.addRequestInterceptor((request) => {
const data = JSON.parse(String(request.options.body))
expect(request.options.method).toBe('PATCH')
checkCommon(request, resourceType, id, currentAccessToken)
checkCommonData(data, resourceType, attributes, id)
return interceptRequest()
})

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

})
/* trigger._enable stop */

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


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

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

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

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

})
/* relationship.attachments stop */


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

Expand Down
Loading

0 comments on commit aaf9f61

Please sign in to comment.