add tests for opengroup message

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

@ -4,7 +4,7 @@ import { QuotedAttachmentType } from '../../../components/conversation/Quote';
interface OpenGroupMessageParams extends MessageParams {
server: string;
attachments: [AttachmentType];
attachments?: Array<AttachmentType>;
body?: string;
quote?: QuotedAttachmentType;
}
@ -12,7 +12,7 @@ interface OpenGroupMessageParams extends MessageParams {
export class OpenGroupMessage extends Message {
public readonly server: string;
public readonly body?: string;
public readonly attachments: [AttachmentType]; // TODO: Not sure if we should only use a subset of this type
public readonly attachments?: Array<AttachmentType>;
public readonly quote?: QuotedAttachmentType;
constructor({

@ -51,7 +51,6 @@ describe('DeviceLinkMessage', () => {
expect(decoded.pairingAuthorisation).to.have.property('requestSignature').to.deep.equal(new Uint8Array([1, 2, 3, 4, 5, 6]));
});
it('has no pairingAuthorisation.grantSignature', () => {
console.log(decoded)
expect(decoded.pairingAuthorisation).to.have.property('grantSignature').to.have.lengthOf(0);
});
it('has no lokiProfile', () => {

@ -0,0 +1,88 @@
import { expect } from 'chai';
import { OpenGroupMessage } from '../../../session/messages/outgoing';
import { AttachmentType } from '../../../types/Attachment';
import * as MIME from '../../../../ts/types/MIME';
import { QuotedAttachmentType } from '../../../components/conversation/Quote';
describe('OpenGroupMessage', () => {
it('can create empty message with just a timestamp and server', () => {
const message = new OpenGroupMessage({
timestamp: Date.now(),
server: 'server',
});
expect(message).to.have.property('timestamp').to.be.approximately(Date.now(), 10);
expect(message).to.have.deep.property('server', 'server');
});
it('can create message with a body', () => {
const message = new OpenGroupMessage({
timestamp: Date.now(),
server: 'server',
body: 'body',
});
expect(message).to.have.deep.property('body', 'body');
});
it('can create message with a expire timer', () => {
const message = new OpenGroupMessage({
timestamp: Date.now(),
server: 'server',
body: 'body',
});
expect(message).to.have.deep.property('body', 'body');
});
it('can create message with a quote', () => {
let quote: QuotedAttachmentType;
quote = {
contentType: MIME.IMAGE_JPEG,
fileName: 'fileName',
isVoiceMessage: false,
};
const message = new OpenGroupMessage({
timestamp: Date.now(),
server: 'server',
quote,
});
expect(message?.quote).to.have.property('contentType', MIME.IMAGE_JPEG);
expect(message?.quote).to.have.deep.property('fileName', 'fileName');
expect(message?.quote).to.have.deep.property('isVoiceMessage', false);
});
it('can create message with an attachment', () => {
let attachment: AttachmentType;
attachment = {
url: 'url',
caption: 'caption',
fileName: 'fileName',
contentType: MIME.AUDIO_AAC,
};
const attachments = new Array<AttachmentType>();
attachments.push(attachment);
const message = new OpenGroupMessage({
timestamp: Date.now(),
server: 'server',
attachments: attachments,
});
expect(message?.attachments).to.have.lengthOf(1);
expect(message).to.have.nested.property('attachments[0].caption').to.have.be.deep.equal('caption');
expect(message).to.have.nested.property('attachments[0].fileName').to.have.be.deep.equal('fileName');
expect(message).to.have.nested.property('attachments[0].contentType').to.be.deep.equal(MIME.AUDIO_AAC);
expect(message).to.have.nested.property('attachments[0].url').to.be.deep.equal('url');
});
it('has an identifier', () => {
const message = new OpenGroupMessage({
timestamp: Date.now(),
server: 'server',
});
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