mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2025-05-24 12:07:08 -04:00
test: add tests for methods in RealtimeNote
Signed-off-by: Philip Molares <philip.molares@udo.edu>
This commit is contained in:
parent
331747f61b
commit
d75095bce4
1 changed files with 36 additions and 0 deletions
|
@ -3,6 +3,10 @@
|
||||||
*
|
*
|
||||||
* SPDX-License-Identifier: AGPL-3.0-only
|
* SPDX-License-Identifier: AGPL-3.0-only
|
||||||
*/
|
*/
|
||||||
|
import {
|
||||||
|
encodeDocumentDeletedMessage,
|
||||||
|
encodeMetadataUpdatedMessage,
|
||||||
|
} from '@hedgedoc/realtime';
|
||||||
import { Mock } from 'ts-mockery';
|
import { Mock } from 'ts-mockery';
|
||||||
|
|
||||||
import { Note } from '../../notes/note.entity';
|
import { Note } from '../../notes/note.entity';
|
||||||
|
@ -87,4 +91,36 @@ describe('realtime note', () => {
|
||||||
sut.destroy();
|
sut.destroy();
|
||||||
expect(() => sut.destroy()).toThrow();
|
expect(() => sut.destroy()).toThrow();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('announcePermissionChange to all clients', () => {
|
||||||
|
const sut = new RealtimeNote(mockedNote, 'nothing');
|
||||||
|
const client1 = mockConnection(true);
|
||||||
|
sut.addClient(client1);
|
||||||
|
const client2 = mockConnection(true);
|
||||||
|
sut.addClient(client2);
|
||||||
|
const metadataMessage = encodeMetadataUpdatedMessage();
|
||||||
|
sut.announcePermissionChange();
|
||||||
|
expect(client1.send).toHaveBeenCalledWith(metadataMessage);
|
||||||
|
expect(client2.send).toHaveBeenCalledWith(metadataMessage);
|
||||||
|
sut.removeClient(client2);
|
||||||
|
sut.announcePermissionChange();
|
||||||
|
expect(client1.send).toHaveBeenCalledTimes(2);
|
||||||
|
expect(client2.send).toHaveBeenCalledTimes(1);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('announceNoteDeletion to all clients', () => {
|
||||||
|
const sut = new RealtimeNote(mockedNote, 'nothing');
|
||||||
|
const client1 = mockConnection(true);
|
||||||
|
sut.addClient(client1);
|
||||||
|
const client2 = mockConnection(true);
|
||||||
|
sut.addClient(client2);
|
||||||
|
const deletedMessage = encodeDocumentDeletedMessage();
|
||||||
|
sut.announceNoteDeletion();
|
||||||
|
expect(client1.send).toHaveBeenCalledWith(deletedMessage);
|
||||||
|
expect(client2.send).toHaveBeenCalledWith(deletedMessage);
|
||||||
|
sut.removeClient(client2);
|
||||||
|
sut.announceNoteDeletion();
|
||||||
|
expect(client1.send).toHaveBeenCalledTimes(2);
|
||||||
|
expect(client2.send).toHaveBeenCalledTimes(1);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue