From 3f45ec441d5e8ad123def522f54cabb9ffffe0c3 Mon Sep 17 00:00:00 2001 From: nhannah Date: Fri, 2 Oct 2020 15:20:08 -0600 Subject: [PATCH] add tests and correct types for BlockList --- src/client.ts | 11 ++--- src/types.ts | 15 ++++-- ts-test/index.js | 30 ++++++++++++ ts-test/response-generators/moderation.js | 58 +++++++++++++++++++++++ 4 files changed, 103 insertions(+), 11 deletions(-) diff --git a/src/client.ts b/src/client.ts index 7da25bce7..2bcd6289f 100644 --- a/src/client.ts +++ b/src/client.ts @@ -19,6 +19,8 @@ import { AppSettingsAPIResponse, AscDesc, BanUserOptions, + BlockList, + BlockListResponse, ChannelAPIResponse, ChannelData, ChannelFilters, @@ -75,7 +77,6 @@ import { UserOptions, UserResponse, UserSort, - BlockList, } from './types'; function isString(x: unknown): x is string { @@ -2076,13 +2077,13 @@ export class StreamChat< } listBlockLists() { - return this.get( + return this.get( `${this.baseURL}/blocklists`, ); } getBlockList(name: string) { - return this.get( + return this.get( `${this.baseURL}/blocklists/${name}`, ); } @@ -2092,8 +2093,6 @@ export class StreamChat< } deleteBlockList(name: string) { - return this.delete( - `${this.baseURL}/blocklists/${name}`, - ); + return this.delete(`${this.baseURL}/blocklists/${name}`); } } diff --git a/src/types.ts b/src/types.ts index 5a23e6520..c45c9e3e8 100644 --- a/src/types.ts +++ b/src/types.ts @@ -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, @@ -1188,6 +1193,11 @@ export type Attachment = T & { type?: string; }; +export type BlockList = { + name: string; + words: string[]; +}; + export type ChannelConfig< CommandType extends string = LiteralStringForUnion > = ChannelConfigFields & @@ -1471,8 +1481,3 @@ export type User = T & { }; export type TypingStartEvent = Event; - -export type BlockList = { - name: string; - words: string[]; -}; diff --git a/ts-test/index.js b/ts-test/index.js index 0adb3fb36..8a87c1111 100644 --- a/ts-test/index.js +++ b/ts-test/index.js @@ -61,6 +61,12 @@ const executables = [ type: "Unpacked['create']>>", }, + { + f: rg.createBlockList, + imports: ['StreamChat', 'Unpacked'], + type: + "Unpacked['createBlockList']>>", + }, // createChannelType has a limit. So only run this when needed. // { // f: rg.createChannelType, @@ -85,6 +91,12 @@ const executables = [ type: "Unpacked['deactivateUser']>>", }, + { + f: rg.deleteBlockList, + imports: ['StreamChat', 'Unpacked'], + type: + "Unpacked['deleteBlockList']>>", + }, { f: rg.deleteChannel, imports: ['Channel', 'Unpacked'], @@ -177,6 +189,12 @@ const executables = [ type: "Unpacked['getAppSettings']>>", }, + { + f: rg.getBlockList, + imports: ['StreamChat', 'Unpacked'], + type: + "Unpacked['getBlockList']>>", + }, { f: rg.getChannelType, imports: ['StreamChat', 'Unpacked'], @@ -249,6 +267,12 @@ const executables = [ type: "Omit['lastMessage']>>>['asMutable']>, 'created_at' | 'updated_at'> & { created_at?: string; updated_at?: string }", }, + { + f: rg.listBlockLists, + imports: ['StreamChat', 'Unpacked'], + type: + "Unpacked['listBlockLists']>>", + }, { f: rg.listChannelTypes, imports: ['StreamChat', 'Unpacked'], @@ -466,6 +490,12 @@ const executables = [ type: "Unpacked['unmuteUser']>>", }, + { + f: rg.updateBlockList, + imports: ['StreamChat', 'Unpacked'], + type: + "Unpacked['updateBlockList']>>", + }, { f: rg.updateChannel, imports: ['Channel', 'Unpacked'], diff --git a/ts-test/response-generators/moderation.js b/ts-test/response-generators/moderation.js index 7d8bdb594..6ddd4d078 100644 --- a/ts-test/response-generators/moderation.js +++ b/ts-test/response-generators/moderation.js @@ -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({ @@ -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({ @@ -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({ @@ -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({ @@ -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({ @@ -264,13 +317,17 @@ async function updatePermission() { module.exports = { banUsers, + createBlockList, createPermission, createRole, + deleteBlockList, deletePermission, deleteRole, flagMessage, flagUser, + getBlockList, getPermission, + listBlockLists, listPermissions, listRoles, muteUser, @@ -278,5 +335,6 @@ module.exports = { unflagMessage, unflagUser, unmuteUser, + updateBlockList, updatePermission, };