-
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
9 changed files
with
1,402 additions
and
244 deletions.
There are no files selected for viewing
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,176 @@ | ||
/** | ||
* ©2024 Commerce Layer Inc. | ||
* Source code generated automatically by SDK codegen | ||
**/ | ||
|
||
import { CommerceLayerClient } from '../../src' | ||
import { isEqual } from 'lodash' | ||
// 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: { links: CommonData.paramsFields } } | ||
const resData = attributes | ||
|
||
const intId = cl.addRequestInterceptor((config) => { | ||
expect(config.method).toBe('post') | ||
checkCommon(config, resourceType) | ||
checkCommonData(config, resourceType, attributes) | ||
expect(cl[resourceType].isLink(config.data.data)).toBeTruthy() | ||
return interceptRequest() | ||
}) | ||
|
||
await cl[resourceType].create(resData, params, CommonData.options) | ||
.catch(handleError) | ||
.finally(() => cl.removeInterceptor('request', intId)) | ||
|
||
}) | ||
/* spec.create.stop */ | ||
|
||
|
||
/* spec.retrieve.start */ | ||
it(resourceType + '.retrieve', async () => { | ||
|
||
const id = TestData.id | ||
const params = { fields: { links: CommonData.paramsFields } } | ||
|
||
const intId = cl.addRequestInterceptor((config) => { | ||
expect(config.method).toBe('get') | ||
checkCommon(config, resourceType, id, currentAccessToken) | ||
checkCommonParams(config, params) | ||
return interceptRequest() | ||
}) | ||
|
||
await cl[resourceType].retrieve(id, params, CommonData.options) | ||
.catch(handleError) | ||
.finally(() => cl.removeInterceptor('request', intId)) | ||
|
||
}) | ||
/* spec.retrieve.stop */ | ||
|
||
|
||
/* spec.update.start */ | ||
it(resourceType + '.update', async () => { | ||
|
||
const attributes = { reference_origin: TestData.reference_origin, metadata: TestData.metadata } | ||
const params = { fields: { links: CommonData.paramsFields } } | ||
const resData = { id: TestData.id, ...attributes} | ||
|
||
const intId = cl.addRequestInterceptor((config) => { | ||
expect(config.method).toBe('patch') | ||
checkCommon(config, resourceType, resData.id, currentAccessToken) | ||
checkCommonData(config, resourceType, attributes, resData.id) | ||
return interceptRequest() | ||
}) | ||
|
||
await cl[resourceType].update(resData, params, CommonData.options) | ||
.catch(handleError) | ||
.finally(() => cl.removeInterceptor('request', intId)) | ||
|
||
}) | ||
/* spec.update.stop */ | ||
|
||
|
||
/* spec.delete.start */ | ||
it(resourceType + '.delete', async () => { | ||
|
||
const id = TestData.id | ||
|
||
const intId = cl.addRequestInterceptor((config) => { | ||
expect(config.method).toBe('delete') | ||
checkCommon(config, resourceType, id, currentAccessToken) | ||
return interceptRequest() | ||
}) | ||
|
||
await cl[resourceType].delete(id, CommonData.options) | ||
.catch(handleError) | ||
.finally(() => cl.removeInterceptor('request', intId)) | ||
|
||
}) | ||
/* spec.delete.stop */ | ||
|
||
|
||
/* spec.list.start */ | ||
it(resourceType + '.list', async () => { | ||
|
||
const params = CommonData.paramsList | ||
|
||
const intId = cl.addRequestInterceptor((config) => { | ||
expect(config.method).toBe('get') | ||
checkCommon(config, resourceType) | ||
checkCommonParamsList(config, params) | ||
return interceptRequest() | ||
}) | ||
|
||
await cl[resourceType].list(params, CommonData.options) | ||
.catch(handleError) | ||
.finally(() => cl.removeInterceptor('request', intId)) | ||
|
||
}) | ||
/* spec.list.stop */ | ||
|
||
|
||
/* spec.type.start */ | ||
it(resourceType + '.type', async () => { | ||
|
||
const resource = { id: TestData.id, type: resourceType } | ||
expect(cl[resourceType].isLink(resource)).toBeTruthy() | ||
|
||
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})) | ||
|
||
const type = cl[resourceType].type() | ||
expect(type).toBe(resourceType) | ||
|
||
}) | ||
/* spec.type.stop */ | ||
|
||
|
||
|
||
it(resourceType + '.events', async () => { | ||
|
||
const id = TestData.id | ||
const params = { fields: { events: CommonData.paramsFields } } | ||
|
||
const intId = cl.addRequestInterceptor((config) => { | ||
expect(config.method).toBe('get') | ||
checkCommon(config, resourceType, id, currentAccessToken, 'events') | ||
checkCommonParams(config, params) | ||
return interceptRequest() | ||
}) | ||
|
||
await cl[resourceType].events(id, params, CommonData.options) | ||
.catch(handleError) | ||
.finally(() => cl.removeInterceptor('request', intId)) | ||
|
||
}) | ||
|
||
}) |
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
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
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
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
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,116 @@ | ||
import { ApiResource, Resource, ResourceCreate, ResourceUpdate, ResourcesConfig, ResourceId, ResourceRel, ListResponse } from '../resource' | ||
import type { QueryParamsList, QueryParamsRetrieve } from '../query' | ||
|
||
import type { Order } from './orders' | ||
import type { SkuList } from './sku_lists' | ||
import type { Event } from './events' | ||
|
||
|
||
type LinkRel = ResourceRel & { type: typeof Links.TYPE } | ||
type OrderRel = ResourceRel & { type: 'orders' } | ||
type SkuListRel = ResourceRel & { type: 'sku_lists' } | ||
|
||
|
||
interface Link extends Resource { | ||
|
||
name?: string | ||
client_id?: string | ||
scope?: string | ||
starts_at?: string | ||
expires_at?: string | ||
active?: boolean | ||
status?: string | ||
domain?: string | ||
url?: string | ||
disabled_at?: string | ||
|
||
item?: Order | SkuList | ||
events?: Event[] | ||
|
||
} | ||
|
||
|
||
interface LinkCreate extends ResourceCreate { | ||
|
||
name: string | ||
client_id: string | ||
scope: string | ||
starts_at: string | ||
expires_at: string | ||
domain?: string | ||
_disable?: boolean | ||
_enable?: boolean | ||
|
||
item: OrderRel | SkuListRel | ||
|
||
} | ||
|
||
|
||
interface LinkUpdate extends ResourceUpdate { | ||
|
||
name?: string | ||
client_id?: string | ||
scope?: string | ||
starts_at?: string | ||
expires_at?: string | ||
domain?: string | ||
_disable?: boolean | ||
_enable?: boolean | ||
|
||
item?: OrderRel | SkuListRel | ||
|
||
} | ||
|
||
|
||
class Links extends ApiResource { | ||
|
||
static readonly TYPE: 'links' = 'links' as const | ||
// static readonly PATH = 'links' | ||
|
||
async list(params?: QueryParamsList, options?: ResourcesConfig): Promise<ListResponse<Link>> { | ||
return this.resources.list<Link>({ type: Links.TYPE }, params, options) | ||
} | ||
|
||
async create(resource: LinkCreate, params?: QueryParamsRetrieve, options?: ResourcesConfig): Promise<Link> { | ||
return this.resources.create<LinkCreate, Link>({ ...resource, type: Links.TYPE }, params, options) | ||
} | ||
|
||
async retrieve(id: string, params?: QueryParamsRetrieve, options?: ResourcesConfig): Promise<Link> { | ||
return this.resources.retrieve<Link>({ type: Links.TYPE, id }, params, options) | ||
} | ||
|
||
async update(resource: LinkUpdate, params?: QueryParamsRetrieve, options?: ResourcesConfig): Promise<Link> { | ||
return this.resources.update<LinkUpdate, Link>({ ...resource, type: Links.TYPE }, params, options) | ||
} | ||
|
||
async delete(id: string, options?: ResourcesConfig): Promise<void> { | ||
await this.resources.delete({ type: Links.TYPE, id }, options) | ||
} | ||
|
||
async events(linkId: string | Link, params?: QueryParamsList, options?: ResourcesConfig): Promise<ListResponse<Event>> { | ||
const _linkId = (linkId as Link).id || linkId as string | ||
return this.resources.fetch<Event>({ type: 'events' }, `links/${_linkId}/events`, params, options) as unknown as ListResponse<Event> | ||
} | ||
|
||
|
||
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types, @typescript-eslint/no-explicit-any | ||
isLink(resource: any): resource is Link { | ||
return resource.type && (resource.type === Links.TYPE) | ||
} | ||
|
||
|
||
relationship(id: string | ResourceId | null): LinkRel { | ||
return ((id === null) || (typeof id === 'string')) ? { id, type: Links.TYPE } : { id: id.id, type: Links.TYPE } | ||
} | ||
|
||
|
||
type(): string { | ||
return Links.TYPE | ||
} | ||
|
||
} | ||
|
||
|
||
export default Links | ||
|
||
export { Link, LinkCreate, LinkUpdate } |
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.