removed SlashCommands from the Server database schema (#6116)

This commit is contained in:
Avinash Lingaloo
2022-04-01 19:23:57 +04:00
committed by GitHub
parent b7d04afa21
commit 764e08e25d
17 changed files with 6 additions and 281 deletions

View File

@@ -4,7 +4,6 @@
import DatabaseManager from '@database/manager';
import {
isRecordMyTeamEqualToRaw,
isRecordSlashCommandEqualToRaw,
isRecordTeamChannelHistoryEqualToRaw,
isRecordTeamEqualToRaw,
isRecordTeamMembershipEqualToRaw,
@@ -12,7 +11,6 @@ import {
} from '@database/operator/server_data_operator/comparators';
import {
transformMyTeamRecord,
transformSlashCommandRecord,
transformTeamChannelHistoryRecord,
transformTeamMembershipRecord,
transformTeamRecord,
@@ -184,46 +182,4 @@ describe('*** Operator: Team Handlers tests ***', () => {
transformer: transformTeamSearchHistoryRecord,
});
});
it('=> HandleSlashCommand: should write to the SLASH_COMMAND table', async () => {
expect.assertions(2);
const spyOnHandleRecords = jest.spyOn(operator, 'handleRecords');
const slashCommands = [
{
id: 'command_1',
auto_complete: true,
auto_complete_desc: 'mock_command',
auto_complete_hint: 'hint',
create_at: 1445538153952,
creator_id: 'creator_id',
delete_at: 1445538153952,
description: 'description',
display_name: 'display_name',
icon_url: 'display_name',
method: 'get',
team_id: 'teamA',
token: 'token',
trigger: 'trigger',
update_at: 1445538153953,
url: 'url',
username: 'userA',
},
];
await operator.handleSlashCommand({
slashCommands,
prepareRecordsOnly: false,
});
expect(spyOnHandleRecords).toHaveBeenCalledTimes(1);
expect(spyOnHandleRecords).toHaveBeenCalledWith({
fieldName: 'id',
createOrUpdateRawValues: slashCommands,
tableName: 'SlashCommand',
prepareRecordsOnly: false,
findMatchingRecordBy: isRecordSlashCommandEqualToRaw,
transformer: transformSlashCommandRecord,
});
});
});

View File

@@ -5,7 +5,6 @@ import {MM_TABLES} from '@constants/database';
import DataOperatorException from '@database/exceptions/data_operator_exception';
import {
isRecordMyTeamEqualToRaw,
isRecordSlashCommandEqualToRaw,
isRecordTeamChannelHistoryEqualToRaw,
isRecordTeamEqualToRaw,
isRecordTeamMembershipEqualToRaw,
@@ -13,7 +12,6 @@ import {
} from '@database/operator/server_data_operator/comparators';
import {
transformMyTeamRecord,
transformSlashCommandRecord,
transformTeamChannelHistoryRecord,
transformTeamMembershipRecord,
transformTeamRecord,
@@ -34,7 +32,6 @@ import type TeamSearchHistoryModel from '@typings/database/models/servers/team_s
const {
MY_TEAM,
SLASH_COMMAND,
TEAM,
TEAM_CHANNEL_HISTORY,
TEAM_MEMBERSHIP,
@@ -159,33 +156,6 @@ const TeamHandler = (superclass: any) => class extends superclass {
});
};
/**
* handleSlashCommand: Handler responsible for the Create/Update operations occurring on the SLASH_COMMAND table from the 'Server' schema
* @param {HandleSlashCommandArgs} slashCommandsArgs
* @param {SlashCommand[]} slashCommandsArgs.slashCommands
* @param {boolean} slashCommandsArgs.prepareRecordsOnly
* @throws DataOperatorException
* @returns {Promise<SlashCommandModel[]>}
*/
handleSlashCommand = ({slashCommands, prepareRecordsOnly = true}: HandleSlashCommandArgs): Promise<SlashCommandModel[]> => {
if (!slashCommands.length) {
throw new DataOperatorException(
'An empty "slashCommands" array has been passed to the handleSlashCommand method',
);
}
const createOrUpdateRawValues = getUniqueRawsBy({raws: slashCommands, key: 'id'});
return this.handleRecords({
fieldName: 'id',
findMatchingRecordBy: isRecordSlashCommandEqualToRaw,
transformer: transformSlashCommandRecord,
prepareRecordsOnly,
createOrUpdateRawValues,
tableName: SLASH_COMMAND,
});
};
/**
* handleMyTeam: Handler responsible for the Create/Update operations occurring on the MY_TEAM table from the 'Server' schema
* @param {HandleMyTeamArgs} myTeamsArgs

View File

@@ -3,7 +3,6 @@
import {
transformMyTeamRecord,
transformSlashCommandRecord,
transformTeamChannelHistoryRecord,
transformTeamMembershipRecord,
transformTeamRecord,
@@ -13,43 +12,6 @@ import {createTestConnection} from '@database/operator/utils/create_test_connect
import {OperationType} from '@typings/database/enums';
describe('*** TEAM Prepare Records Test ***', () => {
it('=> transformSlashCommandRecord: should return an array of type SlashCommand', async () => {
expect.assertions(3);
const database = await createTestConnection({databaseName: 'team_prepare_records', setActive: true});
expect(database).toBeTruthy();
const preparedRecords = await transformSlashCommandRecord({
action: OperationType.CREATE,
database: database!,
value: {
record: undefined,
raw: {
id: 'command_1',
auto_complete: true,
auto_complete_desc: 'mock_command',
auto_complete_hint: 'hint',
create_at: 1445538153952,
creator_id: 'creator_id',
delete_at: 1445538153952,
description: 'description',
display_name: 'display_name',
icon_url: 'display_name',
method: 'get',
team_id: 'teamA',
token: 'token',
trigger: 'trigger',
update_at: 1445538153953,
url: 'url',
username: 'userA',
},
},
});
expect(preparedRecords).toBeTruthy();
expect(preparedRecords!.collection.modelClass.name).toBe('SlashCommandModel');
});
it('=> transformMyTeamRecord: should return an array of type MyTeam', async () => {
expect.assertions(3);

View File

@@ -7,7 +7,6 @@ import {OperationType} from '@typings/database/enums';
import type {TransformerArgs} from '@typings/database/database';
import type MyTeamModel from '@typings/database/models/servers/my_team';
import type SlashCommandModel from '@typings/database/models/servers/slash_command';
import type TeamModel from '@typings/database/models/servers/team';
import type TeamChannelHistoryModel from '@typings/database/models/servers/team_channel_history';
import type TeamMembershipModel from '@typings/database/models/servers/team_membership';
@@ -15,7 +14,6 @@ import type TeamSearchHistoryModel from '@typings/database/models/servers/team_s
const {
MY_TEAM,
SLASH_COMMAND,
TEAM,
TEAM_CHANNEL_HISTORY,
TEAM_MEMBERSHIP,
@@ -140,41 +138,6 @@ export const transformTeamSearchHistoryRecord = ({action, database, value}: Tran
}) as Promise<TeamSearchHistoryModel>;
};
/**
* transformSlashCommandRecord: Prepares a record of the SERVER database 'SlashCommand' table for update or create actions.
* @param {DataFactory} operator
* @param {Database} operator.database
* @param {RecordPair} operator.value
* @returns {Promise<SlashCommandModel>}
*/
export const transformSlashCommandRecord = ({action, database, value}: TransformerArgs): Promise<SlashCommandModel> => {
const raw = value.raw as SlashCommand;
const record = value.record as SlashCommandModel;
const isCreateAction = action === OperationType.CREATE;
// If isCreateAction is true, we will use the id (API response) from the RAW, else we shall use the existing record id from the database
const fieldsMapper = (slashCommand: SlashCommandModel) => {
slashCommand._raw.id = isCreateAction ? (raw?.id ?? slashCommand.id) : record.id;
slashCommand.isAutoComplete = raw.auto_complete;
slashCommand.description = raw.description;
slashCommand.displayName = raw.display_name;
slashCommand.hint = raw.auto_complete_hint;
slashCommand.method = raw.method;
slashCommand.teamId = raw.team_id;
slashCommand.token = raw.token;
slashCommand.trigger = raw.trigger;
slashCommand.updateAt = raw.update_at;
};
return prepareBaseRecord({
action,
database,
tableName: SLASH_COMMAND,
value,
fieldsMapper,
}) as Promise<SlashCommandModel>;
};
/**
* transformMyTeamRecord: Prepares a record of the SERVER database 'MyTeam' table for update or create actions.
* @param {DataFactory} operator

View File

@@ -10,7 +10,7 @@ import type SlashCommandModel from '@typings/database/models/servers/slash_comma
import type TeamModel from '@typings/database/models/servers/team';
import type UserModel from '@typings/database/models/servers/user';
const {CHANNEL, POST, SLASH_COMMAND, TEAM, USER} = MM_TABLES.SERVER;
const {CHANNEL, POST, TEAM, USER} = MM_TABLES.SERVER;
/**
* getValidRecordsForUpdate: Database Operations on some tables are expensive. As such, we would like to operate if and only if we are
@@ -22,7 +22,7 @@ const {CHANNEL, POST, SLASH_COMMAND, TEAM, USER} = MM_TABLES.SERVER;
* @returns {boolean}
*/
export const getValidRecordsForUpdate = ({tableName, newValue, existingRecord}: IdenticalRecordArgs) => {
const guardTables = [CHANNEL, POST, SLASH_COMMAND, TEAM, USER];
const guardTables = [CHANNEL, POST, TEAM, USER];
if (guardTables.includes(tableName)) {
type Raw = Post | UserProfile | Team | SlashCommand | Channel;
type ExistingRecord = PostModel | UserModel | TeamModel | SlashCommandModel | ChannelModel;