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

add tests and correct types for BlockList #455

Merged
merged 1 commit into from
Oct 2, 2020
Merged
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
11 changes: 5 additions & 6 deletions src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ import {
AppSettingsAPIResponse,
AscDesc,
BanUserOptions,
BlockList,
BlockListResponse,
ChannelAPIResponse,
ChannelData,
ChannelFilters,
Expand Down Expand Up @@ -75,7 +77,6 @@ import {
UserOptions,
UserResponse,
UserSort,
BlockList,
} from './types';

function isString(x: unknown): x is string {
Expand Down Expand Up @@ -2076,13 +2077,13 @@ export class StreamChat<
}

listBlockLists() {
return this.get<APIResponse & { blocklists: BlockList[] }>(
return this.get<APIResponse & { blocklists: BlockListResponse[] }>(
`${this.baseURL}/blocklists`,
);
}

getBlockList(name: string) {
return this.get<APIResponse & { blocklist: BlockList }>(
return this.get<APIResponse & { blocklist: BlockListResponse }>(
`${this.baseURL}/blocklists/${name}`,
);
}
Expand All @@ -2092,8 +2093,6 @@ export class StreamChat<
}

deleteBlockList(name: string) {
return this.delete<APIResponse & { blocklist: BlockList }>(
`${this.baseURL}/blocklists/${name}`,
);
return this.delete<APIResponse>(`${this.baseURL}/blocklists/${name}`);
}
}
15 changes: 10 additions & 5 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,11 @@ export type AppSettingsAPIResponse<
};
};

export type BlockListResponse = BlockList & {
created_at?: string;
updated_at?: string;
};

export type ChannelResponse<
ChannelType = UnknownType,
CommandType extends string = LiteralStringForUnion,
Expand Down Expand Up @@ -1188,6 +1193,11 @@ export type Attachment<T = UnknownType> = T & {
type?: string;
};

export type BlockList = {
name: string;
words: string[];
};

export type ChannelConfig<
CommandType extends string = LiteralStringForUnion
> = ChannelConfigFields &
Expand Down Expand Up @@ -1471,8 +1481,3 @@ export type User<T = UnknownType> = T & {
};

export type TypingStartEvent = Event;

export type BlockList = {
name: string;
words: string[];
};
30 changes: 30 additions & 0 deletions ts-test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,12 @@ const executables = [
type:
"Unpacked<ReturnType<Channel<{}, { description?: string }, string & {}, {}, {}, {}, {}>['create']>>",
},
{
f: rg.createBlockList,
imports: ['StreamChat', 'Unpacked'],
type:
"Unpacked<ReturnType<StreamChat<{}, { description?: string }, string & {}, {}, {}, {}, {}>['createBlockList']>>",
},
// createChannelType has a limit. So only run this when needed.
// {
// f: rg.createChannelType,
Expand All @@ -85,6 +91,12 @@ const executables = [
type:
"Unpacked<ReturnType<StreamChat<{}, {}, string & {}, {}, {}, {}, {}>['deactivateUser']>>",
},
{
f: rg.deleteBlockList,
imports: ['StreamChat', 'Unpacked'],
type:
"Unpacked<ReturnType<StreamChat<{}, { description?: string }, string & {}, {}, {}, {}, {}>['deleteBlockList']>>",
},
{
f: rg.deleteChannel,
imports: ['Channel', 'Unpacked'],
Expand Down Expand Up @@ -177,6 +189,12 @@ const executables = [
type:
"Unpacked<ReturnType<StreamChat<{}, {}, string & {}, {}, {}, {}, {}>['getAppSettings']>>",
},
{
f: rg.getBlockList,
imports: ['StreamChat', 'Unpacked'],
type:
"Unpacked<ReturnType<StreamChat<{}, {}, string & {}, {}, {}, {}, {}>['getBlockList']>>",
},
{
f: rg.getChannelType,
imports: ['StreamChat', 'Unpacked'],
Expand Down Expand Up @@ -249,6 +267,12 @@ const executables = [
type:
"Omit<ReturnType<ImmutableObject<Unpacked<ReturnType<Channel<{}, { description?: string }, string & {}, {}, {}, {}, {}>['lastMessage']>>>['asMutable']>, 'created_at' | 'updated_at'> & { created_at?: string; updated_at?: string }",
},
{
f: rg.listBlockLists,
imports: ['StreamChat', 'Unpacked'],
type:
"Unpacked<ReturnType<StreamChat<{}, {}, string & {}, {}, {}, {}, {}>['listBlockLists']>>",
},
{
f: rg.listChannelTypes,
imports: ['StreamChat', 'Unpacked'],
Expand Down Expand Up @@ -466,6 +490,12 @@ const executables = [
type:
"Unpacked<ReturnType<StreamChat<{}, {}, string & {}, {}, {}, {}, {}>['unmuteUser']>>",
},
{
f: rg.updateBlockList,
imports: ['StreamChat', 'Unpacked'],
type:
"Unpacked<ReturnType<StreamChat<{}, { description: string }, string & {}, {}, {}, {}, {}>['updateBlockList']>>",
},
{
f: rg.updateChannel,
imports: ['Channel', 'Unpacked'],
Expand Down
58 changes: 58 additions & 0 deletions ts-test/response-generators/moderation.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,15 @@ async function banUsers() {
});
}

async function createBlockList() {
const name = 'FWord';
const client = utils.getTestClient(true);

const returnValue = await client.createBlockList({ name, words: ['F*!k'] });
await client.deleteBlockList(name);
return returnValue;
}

async function createPermission() {
const authClient = await utils.getTestClient(true);
return await authClient.createPermission({
Expand All @@ -27,6 +36,18 @@ async function createRole() {
return await authClient.createRole(uuidv4());
}

async function deleteBlockList() {
const name = 'FWord';
const name2 = 'SWord';
const client = await utils.getTestClient(true);
await client.createBlockList({ name, words: ['F*!k'] });
await client.createBlockList({ name: name2, words: ['S!*t'] });

const returnValue = await client.deleteBlockList(name);
await client.deleteBlockList(name2);
return returnValue;
}

async function deletePermission() {
const authClient = await utils.getTestClient(true);
await authClient.createPermission({
Expand Down Expand Up @@ -118,6 +139,16 @@ async function flagUser() {
return await authClient.flagUser(evilId);
}

async function getBlockList() {
const name = 'FWord';
const client = await utils.getTestClient(true);
await client.createBlockList({ name, words: ['F*!k'] });

const returnValue = await client.getBlockList(name);
await client.deleteBlockList(name);
return returnValue;
}

async function getPermission() {
const authClient = await utils.getTestClient(true);
await authClient.createPermission({
Expand All @@ -127,6 +158,16 @@ async function getPermission() {
return await authClient.getPermission('TestGetPermission');
}

async function listBlockLists() {
const name = 'FWord';
const client = await utils.getTestClient(true);
await client.createBlockList({ name, words: ['F*!k'] });

const returnValue = await client.listBlockLists();
await client.deleteBlockList(name);
return returnValue;
}

async function listPermissions() {
const authClient = await utils.getTestClient(true);
await authClient.createPermission({
Expand Down Expand Up @@ -251,6 +292,18 @@ async function unmuteUser() {
return await client1.unmuteUser(user2);
}

async function updateBlockList() {
const name = 'FWord';
const client = await utils.getTestClient(true);
await client.createBlockList({ name, words: ['F*!k'] });

const returnValue = await client.updateBlockList(name, {
words: ['S*!t'],
});
await client.deleteBlockList(name);
return returnValue;
}

async function updatePermission() {
const authClient = await utils.getTestClient(true);
await authClient.createPermission({
Expand All @@ -264,19 +317,24 @@ async function updatePermission() {

module.exports = {
banUsers,
createBlockList,
createPermission,
createRole,
deleteBlockList,
deletePermission,
deleteRole,
flagMessage,
flagUser,
getBlockList,
getPermission,
listBlockLists,
listPermissions,
listRoles,
muteUser,
unbanUsers,
unflagMessage,
unflagUser,
unmuteUser,
updateBlockList,
updatePermission,
};