from-to-toSyncMessage

pull/1199/head
Vincent 5 years ago
parent 58ab611c9e
commit 65148300e7

@ -52,7 +52,7 @@ export class MessageQueue implements MessageQueueInterface {
// Sync to our devices if syncable
if (SyncMessageUtils.canSync(message)) {
const syncMessage = SyncMessageUtils.from(message);
const syncMessage = SyncMessageUtils.toSyncMessage(message);
if (!syncMessage) {
throw new Error(
'MessageQueue internal error occured: failed to make sync message'

@ -1,10 +1,10 @@
import * as _ from 'lodash';
import { UserUtil } from '../../util/';
import { UserUtil } from '../../util';
import { getAllConversations } from '../../../js/modules/data';
import { ContentMessage, SyncMessage } from '../messages/outgoing';
import { MultiDeviceProtocol } from '../protocols';
export function from(message: ContentMessage): SyncMessage | undefined {
export function toSyncMessage(message: ContentMessage): SyncMessage | undefined {
if (message instanceof SyncMessage) {
return message;
}
@ -18,7 +18,7 @@ export function canSync(message: ContentMessage): boolean {
// to know about the recipient
// Stubbed for now
return Boolean(from(message));
return Boolean(toSyncMessage(message));
}
export async function getSyncContacts(): Promise<Array<any> | undefined> {

@ -1,6 +1,6 @@
import * as MessageUtils from './Messages';
import * as GroupUtils from './Groups';
import * as SyncMessageUtils from './SyncMessageUtils';
import * as SyncMessageUtils from './SyncMessage';
import * as StringUtils from './String';
import * as PromiseUtils from './Promise';

@ -1,18 +1,13 @@
import { expect } from 'chai';
import * as sinon from 'sinon';
import { v4 as uuid } from 'uuid';
import { timeout } from '../../test-utils';
import chai from 'chai';
import { generateChatMessage, generateFakePubKey } from '../../test-utils/testUtils';
import { toRawMessage } from '../../../session/utils/Messages';
import { RawMessage } from '../../../session/types/';
import { padPlainTextBuffer } from '../../../session/crypto/MessageEncrypter';
import { PubKey } from '../../../session/types/';
// tslint:disable-next-line: no-require-imports no-var-requires
const chaiAsPromised = require('chai-as-promised');
chai.use(chaiAsPromised);
const { assert } = chai;
const { expect } = chai;
describe('Message Utils', () => {
@ -40,7 +35,7 @@ describe('Message Utils', () => {
const rawBuffer = rawMessage.plainTextBuffer;
const rawBufferJSON = JSON.stringify(rawBuffer);
const messageBufferJSON = JSON.stringify(message.plainTextBuffer);
const messageBufferJSON = JSON.stringify(message.plainTextBuffer());
expect(rawBuffer instanceof Uint8Array).to.equal(true, 'raw message did not contain a plainTextBuffer');
expect(rawBufferJSON).to.equal(messageBufferJSON, 'plainTextBuffer was not converted correctly');
@ -50,7 +45,11 @@ describe('Message Utils', () => {
const device = generateFakePubKey();
const message = generateChatMessage();
const rawMessage =
const rawMessage = toRawMessage(device, message);
const derivedPubKey = PubKey.from(rawMessage.device);
expect(derivedPubKey).to.exist;
expect(derivedPubKey?.isEqual(device)).to.equal(true, 'pubkey of message was not converted correctly');
});
});

@ -0,0 +1,43 @@
import chai from 'chai';
import { generateChatMessage, generateFakePubKey } from '../../test-utils/testUtils';
import { toRawMessage } from '../../../session/utils/Messages';
import { PubKey } from '../../../session/types/';
import { from } from '../../../session/utils/SyncMessage';
// tslint:disable-next-line: no-require-imports no-var-requires
const chaiAsPromised = require('chai-as-promised');
chai.use(chaiAsPromised);
const { expect } = chai;
describe('Sync Message Utils', () => {
describe('from', () => {
it('can convert to sync message', async () => {
const message = generateChatMessage();
const syncMessage = from(message);
// Stubbed
});
});
describe('canSync', () => {
it('', async () => {
});
});
describe('getSyncContacts', () => {
it('', async () => {
});
});
});
Loading…
Cancel
Save