Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: align taxonomy update methods with standard [NONE] #2478

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 0 additions & 20 deletions lib/adapters/REST/endpoints/concept-scheme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,26 +91,6 @@ export const patch: RestEndpoint<'ConceptScheme', 'patch'> = (
}

export const update: RestEndpoint<'ConceptScheme', 'update'> = (
http: AxiosInstance,
params: UpdateConceptSchemeParams,
data: OpPatch[],
headers?: RawAxiosRequestHeaders
) => {
return raw.patch<ConceptSchemeProps>(
http,
`${basePath(params.organizationId)}/${params.conceptSchemeId}`,
data,
{
headers: {
'X-Contentful-Version': params.version,
'Content-Type': 'application/json-patch+json',
...headers,
},
}
)
}

export const updatePut: RestEndpoint<'ConceptScheme', 'updatePut'> = (
http: AxiosInstance,
params: UpdateConceptSchemeParams,
data: CreateConceptSchemeProps,
Expand Down
20 changes: 0 additions & 20 deletions lib/adapters/REST/endpoints/concept.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,26 +55,6 @@ export const patch: RestEndpoint<'Concept', 'patch'> = (
}

export const update: RestEndpoint<'Concept', 'update'> = (
http: AxiosInstance,
params: UpdateConceptParams,
data: OpPatch[],
headers?: RawAxiosRequestHeaders
) => {
return raw.patch<ConceptProps>(
http,
`${basePath(params.organizationId)}/${params.conceptId}`,
data,
{
headers: {
'X-Contentful-Version': params.version,
'Content-Type': 'application/json-patch+json',
...headers,
},
}
)
}

export const updatePut: RestEndpoint<'Concept', 'updatePut'> = (
http: AxiosInstance,
params: UpdateConceptParams,
data: CreateConceptProps,
Expand Down
12 changes: 0 additions & 12 deletions lib/common-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,6 @@ type MRInternal<UA extends boolean> = {
(opts: MROpts<'Concept', 'createWithId', UA>): MRReturn<'Concept', 'createWithId'>
(opts: MROpts<'Concept', 'patch', UA>): MRReturn<'Concept', 'patch'>
(opts: MROpts<'Concept', 'update', UA>): MRReturn<'Concept', 'update'>
(opts: MROpts<'Concept', 'updatePut', UA>): MRReturn<'Concept', 'updatePut'>
(opts: MROpts<'Concept', 'delete', UA>): MRReturn<'Concept', 'delete'>

(opts: MROpts<'ConceptScheme', 'get', UA>): MRReturn<'ConceptScheme', 'get'>
Expand All @@ -473,7 +472,6 @@ type MRInternal<UA extends boolean> = {
(opts: MROpts<'ConceptScheme', 'createWithId', UA>): MRReturn<'ConceptScheme', 'createWithId'>
(opts: MROpts<'ConceptScheme', 'patch', UA>): MRReturn<'ConceptScheme', 'patch'>
(opts: MROpts<'ConceptScheme', 'update', UA>): MRReturn<'ConceptScheme', 'update'>
(opts: MROpts<'ConceptScheme', 'updatePut', UA>): MRReturn<'ConceptScheme', 'updatePut'>
(opts: MROpts<'ConceptScheme', 'delete', UA>): MRReturn<'ConceptScheme', 'delete'>

(opts: MROpts<'ContentType', 'get', UA>): MRReturn<'ContentType', 'get'>
Expand Down Expand Up @@ -1211,11 +1209,6 @@ export type MRActions = {
return: ConceptProps
}
update: {
params: UpdateConceptParams
payload: OpPatch[]
return: ConceptProps
}
updatePut: {
params: UpdateConceptParams
payload: CreateConceptProps
return: ConceptProps
Expand Down Expand Up @@ -1262,11 +1255,6 @@ export type MRActions = {
return: ConceptSchemeProps
}
update: {
params: UpdateConceptSchemeParams
payload: OpPatch[]
return: ConceptSchemeProps
}
updatePut: {
params: UpdateConceptSchemeParams
payload: CreateConceptSchemeProps
return: ConceptSchemeProps
Expand Down
27 changes: 3 additions & 24 deletions lib/plain/entities/concept-scheme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,48 +46,27 @@ export type ConceptSchemePlainClientAPI = {
payload: CreateConceptSchemeProps
): Promise<ConceptSchemeProps>

/**
* Update Concept Scheme
* @returns the updated Concept Scheme
* @throws if the request fails
* @see {@link https://www.contentful.com/developers/docs/references/content-management-api/#/reference/taxonomy/concept-scheme}
* @deprecated The behavior of this method as a PATCH is being deprecated, and will be replaced with a PUT in the next major version. Use the `patch` method instead.
* @example
* ```javascript
* const updatedConcept = await client.conceptScheme.update({
* organizationId: '<organization_id>',
* conceptSchemeId: '<concept_scheme_id>',
* version: 1,
* }, conceptSchemePatch);
* ```
*/
update(
params: SetOptional<UpdateConceptSchemeParams, 'organizationId'>,
payload: OpPatch[]
): Promise<ConceptSchemeProps>

/**
* Update Concept Scheme with PUT
* @returns the updated Concept Scheme
* @throws if the request fails
* @see {@link https://www.contentful.com/developers/docs/references/content-management-api/#/reference/taxonomy/concept-scheme}
* @deprecated In the next major version, this method will be replaced with the standard `update` method which will be updated to use PUT instead of PATCH.
* @example
* ```javascript
* const updatedConcept = await client.conceptScheme.update({
* organizationId: '<organization_id>',
* conceptSchemeId: '<concept_scheme_id>',
* version: 1,
* }, CreateConceptSchemeProps);
* }, conceptSchemeProps);
* ```
*/
updatePut(
update(
params: SetOptional<UpdateConceptSchemeParams, 'organizationId'>,
payload: CreateConceptSchemeProps
): Promise<ConceptSchemeProps>

/**
* Update Concept Scheme
* Update Concept Scheme with PATCH
* @returns the updated Concept Scheme
* @throws if the request fails
* @see {@link https://www.contentful.com/developers/docs/references/content-management-api/#/reference/taxonomy/concept-scheme}
Expand Down
27 changes: 3 additions & 24 deletions lib/plain/entities/concept.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,47 +48,26 @@ export type ConceptPlainClientAPI = {
): Promise<ConceptProps>

/**
* Update Concept
* Update Concept with PUT
* @returns the updated Concept
* @throws if the request fails
* @see {@link https://www.contentful.com/developers/docs/references/content-management-api/#/reference/taxonomy/concept}
* @deprecated The behavior of this method as a PATCH is being deprecated, and will be replaced with a PUT in the next major version. Use the `patch` method instead.
* @example
* ```javascript
* const updatedConcept = await client.concept.update({
* organizationId: '<organization_id>',
* conceptId: '<concept_id>',
* version: 1,
* }, patch);
* }, conceptProps);
* ```
*/
update(
params: SetOptional<UpdateConceptParams, 'organizationId'>,
payload: OpPatch[]
): Promise<ConceptProps>

/**
* Update Concept with PUT
* @returns the updated Concept
* @throws if the request fails
* @see {@link https://www.contentful.com/developers/docs/references/content-management-api/#/reference/taxonomy/concept}
* @deprecated In the next major version, this method will be replaced with the standard `update` method which will be updated to use PUT instead of PATCH.
* @example
* ```javascript
* const updatedConcept = await client.concept.updatePut({
* organizationId: '<organization_id>',
* conceptId: '<concept_id>',
* version: 1,
* }, patch);
* ```
*/
updatePut(
params: SetOptional<UpdateConceptParams, 'organizationId'>,
payload: CreateConceptProps
): Promise<ConceptProps>

/**
* Update Concept
* Update Concept with PATCH
* @returns the updated Concept
* @throws if the request fails
* @see {@link https://www.contentful.com/developers/docs/references/content-management-api/#/reference/taxonomy/concept}
Expand Down
2 changes: 0 additions & 2 deletions lib/plain/plain-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,6 @@ export const createPlainClient = (
delete: wrap(wrapParams, 'Concept', 'delete'),
patch: wrap(wrapParams, 'Concept', 'patch'),
update: wrap(wrapParams, 'Concept', 'update'),
updatePut: wrap(wrapParams, 'Concept', 'updatePut'),
getMany: wrap(wrapParams, 'Concept', 'getMany'),
getDescendants: wrap(wrapParams, 'Concept', 'getDescendants'),
getAncestors: wrap(wrapParams, 'Concept', 'getAncestors'),
Expand All @@ -126,7 +125,6 @@ export const createPlainClient = (
createWithId: wrap(wrapParams, 'ConceptScheme', 'createWithId'),
patch: wrap(wrapParams, 'ConceptScheme', 'patch'),
update: wrap(wrapParams, 'ConceptScheme', 'update'),
updatePut: wrap(wrapParams, 'ConceptScheme', 'updatePut'),
},
function: {
getMany: wrap(wrapParams, 'Function', 'getMany'),
Expand Down
64 changes: 2 additions & 62 deletions test/integration/taxonomy-integration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,36 +126,6 @@ describe('Taxonomy Integration', () => {
expect(result.scopeNote['en-US']).toEqual('Scope Note')
})

it('creates and updates a concept', async () => {
const concept: CreateConceptProps = {
prefLabel: {
'en-US': 'Test Concept',
},
}
const result = await client.concept.create({}, concept)
isConceptProps(result)
expect(result.prefLabel['en-US']).toBe('Test Concept')
expect(result.uri).toBeNull()
conceptsToDelete.push(result)

const updatedConcept = await client.concept.update(
{
version: result.sys.version,
conceptId: result.sys.id,
},
[
{
path: '/uri',
op: 'replace',
value: 'https://example.com/concept',
},
]
)

isConceptProps(updatedConcept)
expect(updatedConcept.uri).toBe('https://example.com/concept')
})

it('create and update a concept - patch', async () => {
const concept: CreateConceptProps = {
prefLabel: {
Expand Down Expand Up @@ -198,7 +168,7 @@ describe('Taxonomy Integration', () => {
expect(result.uri).to.null
conceptsToDelete.push(result)

const updatedConcept = await client.concept.updatePut(
const updatedConcept = await client.concept.update(
{
version: result.sys.version,
conceptId: result.sys.id,
Expand Down Expand Up @@ -406,36 +376,6 @@ describe('Taxonomy Integration', () => {
expect(result.definition['en-US']).toBe('Definition')
})

it('creates and updates a concept scheme', async () => {
const conceptScheme: CreateConceptSchemeProps = {
prefLabel: {
'en-US': 'Test ConceptScheme',
},
}
const result = await client.conceptScheme.create({}, conceptScheme)
isConceptSchemeProps(result)
expect(result.prefLabel['en-US']).toBe('Test ConceptScheme')
expect(result.uri).toBeNull()
conceptSchemesToDelete.push(result)

const updatedConceptScheme = await client.conceptScheme.update(
{
version: result.sys.version,
conceptSchemeId: result.sys.id,
},
[
{
path: '/uri',
op: 'replace',
value: 'https://example.com/updatedConceptScheme',
},
]
)

isConceptSchemeProps(updatedConceptScheme)
expect(updatedConceptScheme.uri).toBe('https://example.com/updatedConceptScheme')
})

it('create and update a conceptScheme - patch', async () => {
const conceptScheme: CreateConceptSchemeProps = {
prefLabel: {
Expand Down Expand Up @@ -478,7 +418,7 @@ describe('Taxonomy Integration', () => {
expect(result.uri).to.null
conceptSchemesToDelete.push(result)

const updatedConceptScheme = await client.conceptScheme.updatePut(
const updatedConceptScheme = await client.conceptScheme.update(
{
version: result.sys.version,
conceptSchemeId: result.sys.id,
Expand Down
23 changes: 1 addition & 22 deletions test/unit/adapters/REST/endpoints/concept-scheme.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,34 +119,13 @@ describe('ConceptScheme', () => {
})

test('update', async () => {
const { httpMock, adapterMock, entityMock } = setup(Promise.resolve({}))
httpMock.patch.mockReturnValue(Promise.resolve({ data: entityMock }))

return adapterMock
.makeRequest({
entityType: 'ConceptScheme',
action: 'update',
userAgent: 'mocked',
params: {
organizationId: 'organization-id',
conceptSchemeId: 'concept-scheme-id',
},
})
.then(() => {
expect(httpMock.patch.mock.calls[0][0]).to.eql(
'/organizations/organization-id/taxonomy/concept-schemes/concept-scheme-id'
)
})
})

test('updatePut', async () => {
const { httpMock, adapterMock, entityMock } = setup(Promise.resolve({}))
httpMock.put.mockReturnValue(Promise.resolve({ data: entityMock }))

return adapterMock
.makeRequest({
entityType: 'ConceptScheme',
action: 'updatePut',
action: 'update',
params: {
organizationId: 'organization-id',
conceptSchemeId: 'concept-scheme-id',
Expand Down
23 changes: 1 addition & 22 deletions test/unit/adapters/REST/endpoints/concept.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,33 +171,12 @@ describe('Concept', () => {
test('update', async () => {
const { httpMock, adapterMock, entityMock } = setup(Promise.resolve({}))

httpMock.patch.mockReturnValue(Promise.resolve({ data: entityMock }))

return adapterMock
.makeRequest({
entityType: 'Concept',
action: 'update',
userAgent: 'mocked',
params: {
organizationId: 'organization-id',
conceptId: 'concept-id',
},
})
.then(() => {
expect(httpMock.patch.mock.calls[0][0]).to.eql(
'/organizations/organization-id/taxonomy/concepts/concept-id'
)
})
})
test('updatePut', async () => {
const { httpMock, adapterMock, entityMock } = setup(Promise.resolve({}))

httpMock.put.mockReturnValue(Promise.resolve({ data: entityMock }))

return adapterMock
.makeRequest({
entityType: 'Concept',
action: 'updatePut',
action: 'update',
params: {
organizationId: 'organization-id',
conceptId: 'concept-id',
Expand Down