Custom Emojis not updating on application (#8853)
* feat: add custom emoji deletion logic to handleCustomEmojis method * test: add custom emoji deletion logic to HandleCustomEmojis test case * fix: improve custom emoji deletion logic
This commit is contained in:
parent
085e3f3839
commit
5838887066
2 changed files with 70 additions and 0 deletions
|
|
@ -70,12 +70,70 @@ describe('*** DataOperator: Base Handlers tests ***', () => {
|
|||
expect(spyOnHandleRecords).toHaveBeenCalledWith({
|
||||
fieldName: 'name',
|
||||
createOrUpdateRawValues: emojis,
|
||||
deleteRawValues: [],
|
||||
tableName: 'CustomEmoji',
|
||||
prepareRecordsOnly: false,
|
||||
transformer: transformCustomEmojiRecord,
|
||||
}, 'handleCustomEmojis');
|
||||
});
|
||||
|
||||
it('=> HandleCustomEmojis: should write to the CUSTOM_EMOJI table and delete custom emojis that have the same name but the id is different', async () => {
|
||||
expect.assertions(2);
|
||||
|
||||
const spyOnHandleRecords = jest.spyOn(operator, 'handleRecords');
|
||||
const emojis: CustomEmoji[] = [
|
||||
{
|
||||
id: 'i',
|
||||
create_at: 1580913641769,
|
||||
update_at: 1580913641769,
|
||||
delete_at: 0,
|
||||
creator_id: '4cprpki7ri81mbx8efixcsb8jo',
|
||||
name: 'boomI',
|
||||
},
|
||||
];
|
||||
|
||||
await operator.handleCustomEmojis({
|
||||
emojis,
|
||||
prepareRecordsOnly: false,
|
||||
});
|
||||
|
||||
const emojiWithTheSameName: CustomEmoji[] = [
|
||||
{
|
||||
id: 'j',
|
||||
create_at: 1580913641770,
|
||||
update_at: 1580913641770,
|
||||
delete_at: 0,
|
||||
creator_id: 'ounobhp3c7f6xcj3bs6ngenhdo',
|
||||
name: 'boomI',
|
||||
},
|
||||
];
|
||||
|
||||
await operator.handleCustomEmojis({
|
||||
emojis: emojiWithTheSameName,
|
||||
prepareRecordsOnly: false,
|
||||
});
|
||||
|
||||
expect(spyOnHandleRecords).toHaveBeenCalledTimes(2);
|
||||
expect(spyOnHandleRecords.mock.calls).toEqual([
|
||||
[{
|
||||
fieldName: 'name',
|
||||
createOrUpdateRawValues: emojis,
|
||||
deleteRawValues: [],
|
||||
tableName: 'CustomEmoji',
|
||||
prepareRecordsOnly: false,
|
||||
transformer: transformCustomEmojiRecord,
|
||||
}, 'handleCustomEmojis'],
|
||||
[{
|
||||
fieldName: 'name',
|
||||
createOrUpdateRawValues: emojiWithTheSameName,
|
||||
deleteRawValues: [{name: 'boomI'}],
|
||||
tableName: 'CustomEmoji',
|
||||
prepareRecordsOnly: false,
|
||||
transformer: transformCustomEmojiRecord,
|
||||
}, 'handleCustomEmojis'],
|
||||
]);
|
||||
});
|
||||
|
||||
it('=> HandleSystem: should write to the SYSTEM table', async () => {
|
||||
expect.assertions(1);
|
||||
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@ import {
|
|||
transformSystemRecord,
|
||||
} from '@database/operator/server_data_operator/transformers/general';
|
||||
import {getUniqueRawsBy} from '@database/operator/utils/general';
|
||||
import {queryCustomEmojisByName} from '@queries/servers/custom_emoji';
|
||||
import {logWarning} from '@utils/log';
|
||||
|
||||
import {sanitizeReactions} from '../../utils/reaction';
|
||||
|
|
@ -53,11 +54,22 @@ export default class ServerDataOperatorBase extends BaseDataOperator {
|
|||
return [];
|
||||
}
|
||||
|
||||
const uniqueNamesToSearch = [...new Set(emojis.map((e) => e.name))];
|
||||
|
||||
const customEmojisFound = await queryCustomEmojisByName(this.database, uniqueNamesToSearch).fetch();
|
||||
|
||||
const emojiIds = new Set(emojis.map((e) => e.id));
|
||||
|
||||
const deleteRawValues = customEmojisFound.
|
||||
filter((local) => !emojiIds.has(local.id)).
|
||||
map((local) => ({name: local.name}));
|
||||
|
||||
return this.handleRecords({
|
||||
fieldName: 'name',
|
||||
transformer: transformCustomEmojiRecord,
|
||||
prepareRecordsOnly,
|
||||
createOrUpdateRawValues: getUniqueRawsBy({raws: emojis, key: 'name'}),
|
||||
deleteRawValues,
|
||||
tableName: CUSTOM_EMOJI,
|
||||
}, 'handleCustomEmojis') as Promise<CustomEmojiModel[]>;
|
||||
};
|
||||
|
|
|
|||
Loading…
Reference in a new issue