-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: update resources to schema v5.4.0
- Loading branch information
Showing
12 changed files
with
2,824 additions
and
1,081 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 */ | ||
|
||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.