Skip to content

Commit

Permalink
add tests and fix command types
Browse files Browse the repository at this point in the history
  • Loading branch information
nhannah committed Aug 26, 2020
1 parent d35d950 commit 278c22d
Show file tree
Hide file tree
Showing 3 changed files with 131 additions and 13 deletions.
25 changes: 12 additions & 13 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -584,29 +584,30 @@ export type ChannelOptions = {
};

export type CreateCommandOptions<CommandType extends string = LiteralStringForUnion> = {
description: string;
name: CommandVariants<CommandType>;
args?: string;
description?: string;
name?: CommandVariants<CommandType>;
set?: CommandVariants<CommandType>;
};

export type CreateCommandResponse<
CommandType extends string = LiteralStringForUnion
> = APIResponse & CreateCommandOptions<CommandType> & CreatedAtUpdatedAt;
> = APIResponse & { command: CreateCommandOptions<CommandType> & CreatedAtUpdatedAt };

export type UpdateCommandOptions<CommandType extends string = LiteralStringForUnion> = {
description: string;
args?: string;
description?: string;
set?: CommandVariants<CommandType>;
};

export type UpdateCommandResponse<
CommandType extends string = LiteralStringForUnion
> = APIResponse &
UpdateCommandOptions<CommandType> &
CreatedAtUpdatedAt & {
name: CommandVariants<CommandType>;
};
> = APIResponse & {
command: UpdateCommandOptions<CommandType> &
CreatedAtUpdatedAt & {
name: CommandVariants<CommandType>;
};
};

export type DeleteCommandResponse<
CommandType extends string = LiteralStringForUnion
Expand All @@ -616,14 +617,12 @@ export type DeleteCommandResponse<

export type GetCommandResponse<
CommandType extends string = LiteralStringForUnion
> = APIResponse & {
commands: Record<string, CreateCommandOptions<CommandType> & CreatedAtUpdatedAt>;
};
> = APIResponse & CreateCommandOptions<CommandType> & CreatedAtUpdatedAt;

export type ListCommandsResponse<
CommandType extends string = LiteralStringForUnion
> = APIResponse & {
commands: Record<string, CreateCommandOptions<CommandType> & CreatedAtUpdatedAt>;
commands: Array<CreateCommandOptions<CommandType> & CreatedAtUpdatedAt>;
};

export type CreateChannelOptions<CommandType extends string = LiteralStringForUnion> = {
Expand Down
30 changes: 30 additions & 0 deletions ts-test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,12 @@ const executables = [
// imports: ['StreamChat', 'Unpacked'],
// type: "Unpacked<ReturnType<StreamChat['createChannelType']>>",
// },
{
f: rg.createCommand,
imports: ['StreamChat', 'Unpacked'],
type:
"Unpacked<ReturnType<StreamChat<{}, {}, {}, {}, {}, {}, 'testCreateCommand' | 'testCreateCommand_set' | 'testDeleteCommand' | 'testDeleteCommand_set' | 'testGetCommand' | 'testGetCommand_set' | 'testListCommand' | 'testListCommand_set' | 'testUpdateCommand' | 'testUpdateCommand_set' | 'testUpdateCommand_set_two' >['createCommand']>>",
},
{
f: rg.createPermission,
imports: ['StreamChat', 'Unpacked'],
Expand All @@ -88,6 +94,12 @@ const executables = [
// imports: ['StreamChat', 'Unpacked'],
// type: "Unpacked<ReturnType<StreamChat['deleteChannelType']>>",
// },
{
f: rg.deleteCommand,
imports: ['StreamChat', 'Unpacked'],
type:
"Unpacked<ReturnType<StreamChat<{}, {}, {}, {}, {}, {}, 'testCreateCommand' | 'testCreateCommand_set' | 'testDeleteCommand' | 'testDeleteCommand_set' | 'testGetCommand' | 'testGetCommand_set' | 'testListCommand' | 'testListCommand_set' | 'testUpdateCommand' | 'testUpdateCommand_set' | 'testUpdateCommand_set_two' >['deleteCommand']>>",
},
{
f: rg.deleteFile,
imports: ['Channel', 'Unpacked'],
Expand Down Expand Up @@ -162,6 +174,12 @@ const executables = [
type:
"Unpacked<ReturnType<StreamChat<{}, {}, {}, {}, {}, {}>['getChannelType']>>",
},
{
f: rg.getCommand,
imports: ['StreamChat', 'Unpacked'],
type:
"Unpacked<ReturnType<StreamChat<{}, {}, {}, {}, {}, {}, 'testCreateCommand' | 'testCreateCommand_set' | 'testDeleteCommand' | 'testDeleteCommand_set' | 'testGetCommand' | 'testGetCommand_set' | 'testListCommand' | 'testListCommand_set' | 'testUpdateCommand' | 'testUpdateCommand_set' | 'testUpdateCommand_set_two' >['getCommand']>>",
},
{
f: rg.getConfig,
imports: ['Channel', 'Unpacked'],
Expand Down Expand Up @@ -226,6 +244,12 @@ const executables = [
type:
"Unpacked<ReturnType<StreamChat<{}, {}, {}, {}, {}, {}>['listChannelTypes']>>",
},
{
f: rg.listCommands,
imports: ['StreamChat', 'Unpacked'],
type:
"Unpacked<ReturnType<StreamChat<{}, {}, {}, {}, {}, {}, 'testCreateCommand' | 'testCreateCommand_set' | 'testDeleteCommand' | 'testDeleteCommand_set' | 'testGetCommand' | 'testGetCommand_set' | 'testListCommand' | 'testListCommand_set' | 'testUpdateCommand' | 'testUpdateCommand_set' | 'testUpdateCommand_set_two' >['listCommands']>>",
},
{
f: rg.listPermissions,
imports: ['StreamChat', 'Unpacked'],
Expand Down Expand Up @@ -437,6 +461,12 @@ const executables = [
type:
"Unpacked<ReturnType<StreamChat<{}, {}, {}, {}, {}, {}>['updateChannelType']>>",
},
{
f: rg.updateCommand,
imports: ['StreamChat', 'Unpacked'],
type:
"Unpacked<ReturnType<StreamChat<{}, {}, {}, {}, {}, {}, 'testCreateCommand' | 'testCreateCommand_set' | 'testDeleteCommand' | 'testDeleteCommand_set' | 'testGetCommand' | 'testGetCommand_set' | 'testListCommand' | 'testListCommand_set' | 'testUpdateCommand' | 'testUpdateCommand_set' | 'testUpdateCommand_set_two' >['updateCommand']>>",
},
{
f: rg.updateMessage,
imports: ['StreamChat', 'Unpacked'],
Expand Down
89 changes: 89 additions & 0 deletions ts-test/response-generators/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,37 @@ async function connect() {
return await authClient.connect();
}

async function createCommand() {
const authClient = await utils.getTestClient(true);
try {
await authClient.deleteCommand('testCreateCommand');
} catch {
// No command to delete
}
const result = await authClient.createCommand({
description: 'testCreateCommand',
name: 'testCreateCommand',
set: 'testCreateCommand_set',
});
await authClient.deleteCommand('testCreateCommand');
return result;
}

async function deleteCommand() {
const authClient = await utils.getTestClient(true);
try {
await authClient.deleteCommand('testDeleteCommand');
} catch {
// No command to delete
}
await authClient.createCommand({
description: 'testDeleteCommand',
name: 'testDeleteCommand',
set: 'testDeleteCommand_set',
});
return await authClient.deleteCommand('testDeleteCommand');
}

async function disconnect() {
const authClient = await utils.getTestClient(true);
await authClient.setAnonymousUser();
Expand All @@ -26,6 +57,23 @@ async function getAppSettings() {
return await authClient.getAppSettings();
}

async function getCommand() {
const authClient = await utils.getTestClient(true);
try {
await authClient.deleteCommand('testGetCommand');
} catch {
// No command to delete
}
await authClient.createCommand({
description: 'testGetCommand',
name: 'testGetCommand',
set: 'testGetCommand_set',
});
const result = await authClient.getCommand('testGetCommand');
await authClient.deleteCommand('testGetCommand');
return result;
}

async function getDevices() {
const user1 = uuidv4();
await utils.createUsers([user1]);
Expand All @@ -34,6 +82,23 @@ async function getDevices() {
return await client.getDevices(user1);
}

async function listCommands() {
const authClient = await utils.getTestClient(true);
try {
await authClient.deleteCommand('testListCommand');
} catch {
// No command to delete
}
await authClient.createCommand({
description: 'testListCommand',
name: 'testListCommand',
set: 'testListCommand_set',
});
const result = await authClient.listCommands();
await authClient.deleteCommand('testListCommand');
return result;
}

async function markAllRead() {
const user1 = uuidv4();
await utils.createUsers([user1]);
Expand Down Expand Up @@ -87,16 +152,40 @@ async function sync() {
);
}

async function updateCommand() {
const authClient = await utils.getTestClient(true);
try {
await authClient.createCommand({
description: 'testUpdateCommand',
name: 'testUpdateCommand',
set: 'testUpdateCommand_set',
});
} catch {
// Command exists
}
const result = await authClient.updateCommand('testUpdateCommand', {
set: 'testUpdateCommand_set_two',
description: 'testUpdateCommand',
});
await authClient.deleteCommand('testUpdateCommand');
return result;
}

module.exports = {
addDevice,
connect,
createCommand,
deleteCommand,
disconnect,
getAppSettings,
getCommand,
getDevices,
listCommands,
markAllRead,
queryUsers,
setAnonymousUser,
setGuestUser,
setUser,
sync,
updateCommand,
};

0 comments on commit 278c22d

Please sign in to comment.