add test for closed group chat

pull/1151/head
Audric Ackermann 5 years ago
parent 934838cc1c
commit 3840d061c3
No known key found for this signature in database
GPG Key ID: 999F434D76324AD4

@ -1,9 +1,10 @@
import { DataMessage } from './DataMessage';
import { SignalService } from '../../../../../protobuf';
import { MessageParams } from '../../Message';
import { ChatMessage } from './ChatMessage';
import { TextEncoder } from 'util';
interface ClosedGroupChatMessageParams extends MessageParams {
interface ClosedGroupChatMessageParams {
identifier?: string;
groupId: string;
chatMessage: ChatMessage;
}
@ -14,7 +15,7 @@ export class ClosedGroupChatMessage extends DataMessage {
constructor(params: ClosedGroupChatMessageParams) {
super({
timestamp: params.timestamp,
timestamp: params.chatMessage.timestamp,
identifier: params.identifier,
});
this.groupId = params.groupId;

@ -0,0 +1,50 @@
import { expect } from 'chai';
import { ChatMessage, ClosedGroupChatMessage } from '../../../session/messages/outgoing';
import { SignalService } from '../../../protobuf';
import { TextEncoder } from 'util';
describe('ClosedGroupChatMessage', () => {
it('can create empty message with timestamp, groupId and chatMessage', () => {
const chatMessage = new ChatMessage({
timestamp: Date.now(),
body: 'body',
});
const message = new ClosedGroupChatMessage({
groupId: '12',
chatMessage,
});
const plainText = message.plainTextBuffer();
const decoded = SignalService.Content.decode(plainText);
expect(decoded.dataMessage).to.have.property('group').to.have.deep.property('id', new TextEncoder().encode('12'));
expect(decoded.dataMessage).to.have.property('group').to.have.deep.property('type', SignalService.GroupContext.Type.DELIVER);
expect(decoded.dataMessage).to.have.deep.property('body', 'body');
// we use the timestamp of the chatMessage as parent timestamp
expect(message).to.have.property('timestamp').to.be.equal(chatMessage.timestamp);
});
it('ttl of 1 day', () => {
const chatMessage = new ChatMessage({
timestamp: Date.now(),
});
const message = new ClosedGroupChatMessage({
groupId: '12',
chatMessage,
});
expect(message.ttl()).to.equal(24 * 60 * 60 * 1000);
});
it('has an identifier', () => {
const chatMessage = new ChatMessage({
timestamp: Date.now(),
});
const message = new ClosedGroupChatMessage({
groupId: '12',
chatMessage,
});
expect(message.identifier).to.not.equal(null, 'identifier cannot be null');
expect(message.identifier).to.not.equal(undefined, 'identifier cannot be undefined');
});
});
Loading…
Cancel
Save