Skip to content

Commit

Permalink
docs: PlainClient docs - comment [EXT-4926] (#2183)
Browse files Browse the repository at this point in the history
* docs: PlainClient docs - comment [EXT-4926]

* fixing codeclimate

* fixing build
  • Loading branch information
david-shibley-contentful authored Feb 21, 2024
1 parent 9c8603f commit 3f3de67
Show file tree
Hide file tree
Showing 5 changed files with 168 additions and 65 deletions.
2 changes: 1 addition & 1 deletion lib/entities/comment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ export type GetCommentParentEntityParams = GetSpaceEnvironmentParams &
export type GetManyCommentsParams = (GetEntryParams | GetCommentParentEntityParams) & {
status?: CommentStatus
}
export type CreateCommentParams = (GetEntryParams | GetCommentParentEntityParams) & {
export type CreateCommentParams = GetCommentParentEntityParams & {
parentCommentId?: string
}
export type UpdateCommentParams = GetCommentParams
Expand Down
49 changes: 2 additions & 47 deletions lib/plain/common-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { OpPatch } from 'json-patch'
import {
CollectionProp,
GetAppDefinitionParams,
GetCommentParams,
GetContentTypeParams,
GetOrganizationMembershipParams,
GetOrganizationParams,
Expand Down Expand Up @@ -35,19 +34,6 @@ import {
AssetProps,
CreateAssetProps,
} from '../entities/asset'
import {
CreateCommentParams,
CreateCommentProps,
DeleteCommentParams,
CommentProps,
UpdateCommentParams,
UpdateCommentProps,
GetManyCommentsParams,
RichTextBodyFormat,
RichTextCommentProps,
RichTextCommentBodyPayload,
PlainTextBodyFormat,
} from '../entities/comment'
import { ContentTypeProps, CreateContentTypeProps } from '../entities/content-type'
import { CreateEntryProps, EntryProps, EntryReferenceProps } from '../entities/entry'
import { CreateEnvironmentProps, EnvironmentProps } from '../entities/environment'
Expand Down Expand Up @@ -154,6 +140,7 @@ import { UploadPlainClientAPI } from './entities/upload'
import { TaskPlainClientAPI } from './entities/task'
import { OrganizationPlainClientAPI } from './entities/organization'
import { LocalePlainClientAPI } from './entities/locale'
import { CommentPlainClientAPI } from './entities/comment'

export type PlainClientAPI = {
raw: {
Expand Down Expand Up @@ -319,39 +306,7 @@ export type PlainClientAPI = {
payload: BulkActionValidatePayload
): Promise<BulkActionProps<BulkActionValidatePayload>>
}
comment: {
get(params: OptionalDefaults<GetCommentParams> & PlainTextBodyFormat): Promise<CommentProps>
get(
params: OptionalDefaults<GetCommentParams> & RichTextBodyFormat
): Promise<RichTextCommentProps>
getMany(
params: OptionalDefaults<GetManyCommentsParams & PlainTextBodyFormat & QueryParams>
): Promise<CollectionProp<CommentProps>>
getMany(
params: OptionalDefaults<GetManyCommentsParams & QueryParams & RichTextBodyFormat>
): Promise<CollectionProp<RichTextCommentProps>>
create(
params: OptionalDefaults<CreateCommentParams>,
rawData: CreateCommentProps,
headers?: RawAxiosRequestHeaders
): Promise<CommentProps>
create(
params: OptionalDefaults<CreateCommentParams>,
rawData: RichTextCommentBodyPayload,
headers?: RawAxiosRequestHeaders
): Promise<RichTextCommentProps>
update(
params: OptionalDefaults<UpdateCommentParams>,
rawData: UpdateCommentProps,
headers?: RawAxiosRequestHeaders
): Promise<CommentProps>
update(
params: OptionalDefaults<UpdateCommentParams>,
rawData: Omit<UpdateCommentProps, 'body'> & RichTextCommentBodyPayload,
headers?: RawAxiosRequestHeaders
): Promise<RichTextCommentProps>
delete(params: OptionalDefaults<DeleteCommentParams>): Promise<void>
}
comment: CommentPlainClientAPI
contentType: {
get(params: OptionalDefaults<GetContentTypeParams & QueryParams>): Promise<ContentTypeProps>
getMany(
Expand Down
7 changes: 2 additions & 5 deletions lib/plain/entities/app-installation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
import { AppInstallationsForOrganizationProps } from '../../entities/app-definition'
import { AppInstallationProps, CreateAppInstallationProps } from '../../entities/app-installation'
import { OptionalDefaults } from '../wrappers/wrap'
import { CreateOrUpdate } from './base'

export type AppInstallationPlainClientAPI = {
/**
Expand Down Expand Up @@ -80,11 +81,7 @@ export type AppInstallationPlainClientAPI = {
* );
* ```
*/
upsert(
params: OptionalDefaults<GetAppInstallationParams>,
rawData: CreateAppInstallationProps,
headers?: RawAxiosRequestHeaders
): Promise<AppInstallationProps>
upsert: CreateOrUpdate<GetAppInstallationParams, CreateAppInstallationProps, AppInstallationProps>
/**
* Uninstalls the App
* @param params entity IDs to identify the App to uninstall
Expand Down
143 changes: 143 additions & 0 deletions lib/plain/entities/comment.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
import { CollectionProp, GetCommentParams, QueryParams } from '../../common-types'
import {
CommentProps,
CreateCommentParams,
CreateCommentProps,
DeleteCommentParams,
GetManyCommentsParams,
PlainTextBodyFormat,
RichTextBodyFormat,
RichTextCommentBodyPayload,
RichTextCommentProps,
UpdateCommentParams,
UpdateCommentProps,
} from '../../entities/comment'
import { OptionalDefaults } from '../wrappers/wrap'
import { CreateOrUpdate } from './base'

type GetManyRichText = GetManyCommentsParams & RichTextBodyFormat & QueryParams
type GetManyPlain = GetManyCommentsParams & PlainTextBodyFormat & QueryParams

export type CommentPlainClientAPI = {
/** Fetches a comment
*
* @param params Space ID, Comment ID, Entry ID, Environment ID
* @returns the comment
* @throws if the request fails, or the comment is not found
* @example
* ```javascript
* const comment = await client.comment.get({
* spaceId: '<space_id>',
* commentId: '<comment_id>',
* entryId: '<entry_id>',
* environmentId: '<environment_id>',
* bodyFormat: 'plain-text',
* });
* ```
* */
get(params: OptionalDefaults<GetCommentParams> & PlainTextBodyFormat): Promise<CommentProps>
/** Fetches a comment
*
* @param params Space ID, Comment ID, Entry ID, Environment ID
* @returns the comment
* @throws if the request fails, or the comment is not found
* @example
* ```javascript
* const comment = await client.comment.get({
* spaceId: '<space_id>',
* commentId: '<comment_id>',
* entryId: '<entry_id>',
* environmentId: '<environment_id>',
* bodyFormat: 'rich-text',
* });
* ```
* */
get(
params: OptionalDefaults<GetCommentParams> & RichTextBodyFormat
): Promise<RichTextCommentProps>
/** Fetches all comments
*
* @param params Space ID, Entry ID, Environment ID, and query parameters
* @returns a collection of comments
* @throws if the request fails or the comments are not found
* @example
* ```javascript
* const comments = await client.comment.getMany({
* spaceId: '<space_id>',
* entryId: '<entry_id>',
* environmentId: '<environment_id>',
* bodyFormat: 'plain-text',
* query: {
* limit: 100,
* }
* });
* ```
* */
getMany(
params: OptionalDefaults<GetManyRichText | GetManyPlain>
): Promise<CollectionProp<CommentProps | RichTextCommentProps>>
/** Creates a comment
*
* @param params
* @returns a comment
* @throws if the request fails, the entry is not found, or the payload is malformed
* @example
* ```javascript
* const comment = await client.comment.create({
* spaceId: '<space_id>',
* entryId: '<entry_id>',
* environmentId: '<environment_id>',
* bodyFormat: 'plain-text' | 'rich-text',
* },
* {
* body: 'Looks good to me!',
* status: 'active',
* });
* ```
*/
create: CreateOrUpdate<
CreateCommentParams,
CreateCommentProps | RichTextCommentBodyPayload,
CommentProps
>
/** Updates a comment
*
* @param params
* @returns a comment
* @throws if the request fails, the comment is not found, or the payload is malformed
* @example
* ```javascript
* const comment = await client.comment.update({
* spaceId: '<space_id>',
* commentId: '<comment_id>',
* entryId: '<entry_id>',
* environmentId: '<environment_id>',
* bodyFormat: 'rich-text' | 'plain-text',
* },
* {
* body: 'Looks good to me!',
* status: 'active',
* });
* ```
*/
update: CreateOrUpdate<
UpdateCommentParams,
UpdateCommentProps | RichTextCommentBodyPayload,
RichTextCommentProps
>
/** Deletes a comment
*
* @param params
* @throws if the request fails, or the comment is not found
* @example
* ```javascript
* await client.comment.delete({
* spaceId: '<space_id>',
* commentId: '<comment_id>',
* entryId: '<entry_id>',
* environmentId: '<environment_id>',
* });
* ```
*/
delete(params: OptionalDefaults<DeleteCommentParams>): Promise<void>
}
32 changes: 20 additions & 12 deletions lib/plain/plain-client-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ describe('Plain Client', () => {
})

it('should create a create object', async () => {
await plainClient.comment.create(props, { body: updateText })
await plainClient.comment.create(props, { body: updateText }, {})
expect(stub).to.have.been.calledWithMatch({
entityType: 'Comment',
action: 'create',
Expand All @@ -78,11 +78,15 @@ describe('Plain Client', () => {
})

it('should create a update object', async () => {
await plainClient.comment.update(props, {
body: updateText,
sys: { version: 2 },
status: 'active',
})
await plainClient.comment.update(
props,
{
body: updateText,
sys: { version: 2 },
status: 'active',
},
{}
)
expect(stub).to.have.been.calledWithMatch({
entityType: 'Comment',
action: 'update',
Expand Down Expand Up @@ -190,7 +194,7 @@ describe('Plain Client', () => {
})

it('should create a create object', async () => {
await plainClient.comment.create(props, { body: richTextBody })
await plainClient.comment.create(props, { body: richTextBody }, {})
expect(stub).to.have.been.calledWithMatch({
entityType: 'Comment',
action: 'create',
Expand All @@ -201,11 +205,15 @@ describe('Plain Client', () => {
})

it('should create a update object', async () => {
await plainClient.comment.update(props, {
body: richTextBody,
sys: { version: 2 },
status: 'active',
})
await plainClient.comment.update(
props,
{
body: richTextBody,
sys: { version: 2 },
status: 'active',
},
{}
)
expect(stub).to.have.been.calledWithMatch({
entityType: 'Comment',
action: 'update',
Expand Down

0 comments on commit 3f3de67

Please sign in to comment.