Skip to content

Commit

Permalink
CHAT-878 custom commands crud integration tests (#394)
Browse files Browse the repository at this point in the history
  • Loading branch information
gumuz authored Aug 26, 2020
1 parent af64818 commit f79baa3
Show file tree
Hide file tree
Showing 3 changed files with 334 additions and 4 deletions.
27 changes: 27 additions & 0 deletions src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,13 @@ import {
FlagMessageResponse,
MarkAllReadOptions,
StreamChatOptions,
CreateCommandOptions,
CreateCommandResponse,
UpdateCommandOptions,
UpdateCommandResponse,
DeleteCommandResponse,
GetCommandResponse,
ListCommandsResponse,
CreateChannelOptions,
CreateChannelResponse,
GetChannelTypeResponse,
Expand Down Expand Up @@ -1663,6 +1670,26 @@ export class StreamChat<
});
}

createCommand(data: CreateCommandOptions) {
return this.post<CreateCommandResponse>(this.baseURL + '/commands', data);
}

getCommand(name: string) {
return this.get<GetCommandResponse>(this.baseURL + `/commands/${name}`);
}

updateCommand(name: string, data: UpdateCommandOptions) {
return this.put<UpdateCommandResponse>(this.baseURL + `/commands/${name}`, data);
}

deleteCommand(name: string) {
return this.delete<DeleteCommandResponse>(this.baseURL + `/commands/${name}`);
}

listCommands() {
return this.get<ListCommandsResponse>(this.baseURL + `/commands`);
}

createChannelType(data: CreateChannelOptions) {
const channelData = Object.assign({}, { commands: ['all'] }, data);
return this.post<CreateChannelResponse>(this.baseURL + '/channeltypes', channelData);
Expand Down
50 changes: 50 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -517,6 +517,56 @@ export type ChannelOptions = {
watch?: boolean;
};

export type CreateCommandOptions = {
args?: string;
description?: string;
name?: string;
set?: string;
};

export type CreateCommandResponse = APIResponse &
CreateCommandOptions & {
created_at: string;
updated_at: string;
};

export type UpdateCommandOptions = {
args?: string;
description?: string;
set?: string;
};

export type UpdateCommandResponse = APIResponse &
UpdateCommandOptions & {
created_at: string;
name: string;
updated_at: string;
};

export type DeleteCommandResponse = APIResponse & {
name?: string;
};

export type GetCommandResponse = APIResponse & {
commands: Record<
string,
CreateCommandOptions & {
created_at: string;
updated_at: string;
}
>;
};

export type ListCommandsResponse = APIResponse & {
commands: Record<
string,
CreateCommandOptions & {
created_at: string;
updated_at: string;
}
>;
};

export type CreateChannelOptions = {
automod?: ChannelConfigAutomod;
automod_behavior?: ChannelConfigAutomodBehavior;
Expand Down
Loading

0 comments on commit f79baa3

Please sign in to comment.