fix: allow change of accept edits in realtime connection

Signed-off-by: Tilman Vatteroth <git@tilmanvatteroth.de>
This commit is contained in:
Tilman Vatteroth 2023-05-08 18:07:48 +02:00
parent eebbb79d08
commit 3c1ea7bda9
2 changed files with 20 additions and 14 deletions

View file

@ -84,21 +84,27 @@ describe('websocket connection', () => {
expect(sut.getRealtimeUserStateAdapter()).toBe(realtimeUserStatus);
});
it('returns the correct sync adapter', () => {
const yDocSyncServerAdapter = Mock.of<YDocSyncServerAdapter>({});
jest
.spyOn(HedgeDocCommonsModule, 'YDocSyncServerAdapter')
.mockImplementation(() => yDocSyncServerAdapter);
it.each([true, false])(
'creates a sync adapter with acceptEdits %s',
(acceptEdits) => {
const yDocSyncServerAdapter = Mock.of<YDocSyncServerAdapter>({});
jest
.spyOn(HedgeDocCommonsModule, 'YDocSyncServerAdapter')
.mockImplementation((messageTransporter, doc, acceptEditsProvider) => {
expect((acceptEditsProvider as () => boolean)()).toBe(acceptEdits);
return yDocSyncServerAdapter;
});
const sut = new RealtimeConnection(
mockedMessageTransporter,
mockedUser,
mockedRealtimeNote,
true,
);
const sut = new RealtimeConnection(
mockedMessageTransporter,
mockedUser,
mockedRealtimeNote,
acceptEdits,
);
expect(sut.getSyncAdapter()).toBe(yDocSyncServerAdapter);
});
expect(sut.getSyncAdapter()).toBe(yDocSyncServerAdapter);
},
);
it('removes the client from the note on transporter disconnect', () => {
const sut = new RealtimeConnection(

View file

@ -35,7 +35,7 @@ export class RealtimeConnection {
messageTransporter: MessageTransporter,
private user: User | null,
private realtimeNote: RealtimeNote,
private acceptEdits: boolean,
public acceptEdits: boolean,
) {
this.displayName = user?.displayName ?? generateRandomName();
this.transporter = messageTransporter;