From 60bb36612f35ef07f8e607b9758e2d5b89cb1663 Mon Sep 17 00:00:00 2001 From: thassiov Date: Thu, 25 Aug 2022 16:49:40 -0300 Subject: [PATCH] Set message editor by default on updates --- src/server/accessors/ModifyUpdater.ts | 6 +++++- tests/server/accessors/ModifyUpdater.spec.ts | 4 ++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/server/accessors/ModifyUpdater.ts b/src/server/accessors/ModifyUpdater.ts index a564398c1..b0af05b87 100644 --- a/src/server/accessors/ModifyUpdater.ts +++ b/src/server/accessors/ModifyUpdater.ts @@ -29,7 +29,7 @@ export class ModifyUpdater implements IModifyUpdater { public async message(messageId: string, updater: IUser): Promise { const msg = await this.bridges.getMessageBridge().doGetById(messageId, this.appId); - return new MessageBuilder(msg); + return new MessageBuilder(msg).setEditor(updater); } public async room(roomId: string, updater: IUser): Promise { @@ -60,6 +60,10 @@ export class ModifyUpdater implements IModifyUpdater { throw new Error('Invalid sender assigned to the message.'); } + if (!result.editor || !result.editor.id) { + throw new Error('Invalid editor assigned to the message.'); + } + return this.bridges.getMessageBridge().doUpdate(result, this.appId); } diff --git a/tests/server/accessors/ModifyUpdater.spec.ts b/tests/server/accessors/ModifyUpdater.spec.ts index c6fb8d0d4..eea30b4ef 100644 --- a/tests/server/accessors/ModifyUpdater.spec.ts +++ b/tests/server/accessors/ModifyUpdater.spec.ts @@ -73,6 +73,10 @@ export class ModifyUpdaterTestFixture { msgBd.setSender(TestData.getUser()); Expect(msg.sender).toBeDefined(); + await Expect(async () => await mc.finish(msgBd)).toThrowErrorAsync(Error, 'Invalid editor assigned to the message.'); + msgBd.setEditor(TestData.getUser()); + Expect(msg.editor).toBeDefined(); + const msgBriSpy = SpyOn(this.mockMessageBridge, 'doUpdate'); Expect(await mc.finish(msgBd)).not.toBeDefined(); Expect(msgBriSpy).toHaveBeenCalledWith(msg, this.mockAppId);