with-electron?

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

@ -32,6 +32,7 @@ describe('Settings', function() {
app = await common.startAndStub(appProps);
});
after(async () => {
await common.stopApp(app);
await common.killallElectron();

@ -0,0 +1,56 @@
/* eslint-disable prefer-destructuring */
/* eslint-disable more/no-then */
/* eslint-disable func-names */
/* eslint-disable import/no-extraneous-dependencies */
const { after, before, describe, it } = require('mocha');
const common = require('../common');
const libsession = require('../../ts/session');
describe('SyncMessage Utils', function() {
let app;
this.timeout(60000);
this.slow(15000);
before(async () => {
await common.killallElectron();
await common.stopStubSnodeServer();
const appProps = {
mnemonic: common.TEST_MNEMONIC1,
displayName: common.TEST_DISPLAY_NAME1,
};
app = await common.startAndStub(appProps);
});
after(async () => {
await common.stopApp(app);
await common.killallElectron();
await common.stopStubSnodeServer();
});
describe('getSyncContacts', async () => {
it('can get sync contacts', async () => {
const contacts = libsession.Protocols.SessionProtocol.
// const menuBarVisible = await app.browserWindow.isMenuBarVisible();
// await app.client.element(SettingsPage.settingsButtonSection).click();
// await app.client
// .element(SettingsPage.settingToggleWithText('Hide Menu Bar'))
// .click();
// // Confirm that toggling works
// const menuBarToggled = await app.browserWindow.isMenuBarVisible();
// menuBarToggled.should.equal(!menuBarVisible);
});
});
});

@ -28,11 +28,22 @@ export async function getSyncContacts(): Promise<Array<any> | undefined> {
return [];
}
console.log('[vince] window.Whisper:', window.Whisper);
console.log('[vince] window.Whisper:', window.Whisper);
console.log('[vince] window.Whisper:', window.Whisper);
console.log('[vince] window.Whisper:', window.Whisper);
const primaryDevice = await MultiDeviceProtocol.getPrimaryDevice(thisDevice);
const conversations = await getAllConversations({
ConversationCollection: window.Whisper.ConversationCollection,
});
console.log('[vince] conversations:', conversations);
console.log('[vince] conversations:', conversations);
console.log('[vince] conversations:', conversations);
console.log('[vince] conversations:', conversations);
console.log('[vince] conversations:', conversations);
// We are building a set of all contacts
const primaryContacts =
conversations.filter(

@ -250,7 +250,7 @@ describe('MessageQueue', () => {
sandbox.stub(SyncMessageUtils, 'canSync').returns(true);
sandbox
.stub(SyncMessageUtils, 'from')
.stub(SyncMessageUtils, 'toSyncMessage')
.returns(new TestSyncMessage({ timestamp: Date.now() }));
// This stub ensures that the message won't process

@ -0,0 +1,35 @@
import chai from 'chai';
import * as sinon from 'sinon';
import { PubKey } from '../../../session/types/';
import { SyncMessageUtils } from '../../../session/utils/';
import { SyncMessage } from '../../../session/messages/outgoing';
import { TestUtils } from '../../test-utils';
import { UserUtil } from '../../../util';
// tslint:disable-next-line: no-require-imports no-var-requires
const chaiAsPromised = require('chai-as-promised');
chai.use(chaiAsPromised);
const { expect } = chai;
describe('Groups Utils', () => {
describe('getGroupMembers', () => {
it('', async () => {
//
});
});
describe('isMediumGroup', () => {
it('', async () => {
//
});
});
});

@ -1,6 +1,6 @@
import chai from 'chai';
import { generateChatMessage, generateFakePubKey } from '../../test-utils/testUtils';
import { toRawMessage } from '../../../session/utils/Messages';
import { TestUtils } from '../../test-utils/';
import { MessageUtils } from '../../../session/utils/';
import { PubKey } from '../../../session/types/';
// tslint:disable-next-line: no-require-imports no-var-requires
@ -13,10 +13,10 @@ describe('Message Utils', () => {
describe('toRawMessage', () => {
it('can convert to raw message', async () => {
const device = generateFakePubKey();
const message = generateChatMessage();
const device = TestUtils.generateFakePubKey();
const message = TestUtils.generateChatMessage();
const rawMessage = toRawMessage(device, message);
const rawMessage = MessageUtils.toRawMessage(device, message);
expect(Object.keys(rawMessage)).to.have.length(6);
expect(rawMessage.identifier).to.exist;
@ -28,10 +28,10 @@ describe('Message Utils', () => {
});
it('should generate valid plainTextBuffer', async () => {
const device = generateFakePubKey();
const message = generateChatMessage();
const device = TestUtils.generateFakePubKey();
const message = TestUtils.generateChatMessage();
const rawMessage = toRawMessage(device, message);
const rawMessage = MessageUtils.toRawMessage(device, message);
const rawBuffer = rawMessage.plainTextBuffer;
const rawBufferJSON = JSON.stringify(rawBuffer);
@ -42,10 +42,10 @@ describe('Message Utils', () => {
});
it('should maintain pubkey', async () => {
const device = generateFakePubKey();
const message = generateChatMessage();
const device = TestUtils.generateFakePubKey();
const message = TestUtils.generateChatMessage();
const rawMessage = toRawMessage(device, message);
const rawMessage = MessageUtils.toRawMessage(device, message);
const derivedPubKey = PubKey.from(rawMessage.device);
expect(derivedPubKey).to.exist;

@ -0,0 +1,40 @@
import chai from 'chai';
import * as sinon from 'sinon';
import { PubKey } from '../../../session/types/';
import { SyncMessageUtils } from '../../../session/utils/';
import { SyncMessage } from '../../../session/messages/outgoing';
import { TestUtils } from '../../test-utils';
import { UserUtil } from '../../../util';
// tslint:disable-next-line: no-require-imports no-var-requires
const chaiAsPromised = require('chai-as-promised');
chai.use(chaiAsPromised);
const { expect } = chai;
describe('Promise Utils', () => {
describe('poll', () => {
it('', async () => {
//
});
});
describe('waitForTask', () => {
it('', async () => {
//
});
});
describe('waitUntil', () => {
it('', async () => {
//
});
});
});

@ -0,0 +1,32 @@
import chai from 'chai';
import * as sinon from 'sinon';
import { PubKey } from '../../../session/types/';
import { SyncMessageUtils } from '../../../session/utils/';
import { SyncMessage } from '../../../session/messages/outgoing';
import { TestUtils } from '../../test-utils';
import { UserUtil } from '../../../util';
// tslint:disable-next-line: no-require-imports no-var-requires
const chaiAsPromised = require('chai-as-promised');
chai.use(chaiAsPromised);
const { expect } = chai;
describe('String Utils', () => {
describe('encode', () => {
it('', async () => {
//
});
});
describe('decode', () => {
it('', async () => {
//
});
});
});

@ -1,8 +1,13 @@
import chai from 'chai';
import { generateChatMessage, generateFakePubKey } from '../../test-utils/testUtils';
import { toRawMessage } from '../../../session/utils/Messages';
import * as sinon from 'sinon';
import { PubKey } from '../../../session/types/';
import { from } from '../../../session/utils/SyncMessage';
import { SyncMessageUtils } from '../../../session/utils/';
import { SyncMessage } from '../../../session/messages/outgoing';
import { TestUtils } from '../../test-utils';
import { UserUtil } from '../../../util';
import { generateFakePubKey } from '../../test-utils/testUtils';
import { MultiDeviceProtocol } from '../../../session/protocols';
// tslint:disable-next-line: no-require-imports no-var-requires
const chaiAsPromised = require('chai-as-promised');
@ -11,32 +16,96 @@ chai.use(chaiAsPromised);
const { expect } = chai;
describe('Sync Message Utils', () => {
// getSyncContacts function is tested in test-integration with Electron
describe('from', () => {
describe('toSyncMessage', () => {
it('can convert to sync message', async () => {
const message = generateChatMessage();
const message = TestUtils.generateChatMessage();
const syncMessage = SyncMessageUtils.toSyncMessage(message);
const syncMessage = from(message);
// Stubbed
expect(syncMessage).to.not.exist;
// expect(syncMessage instanceof SyncMessage).to.equal(true, 'message was not converted to SyncMessage');
// Further tests required
});
});
describe('canSync', () => {
it('', async () => {
it('syncable message returns true', async () => {
const message = TestUtils.generateChatMessage();
// Stubbed
const canSync = SyncMessageUtils.canSync(message);
expect(canSync).to.equal(false, '');
});
});
describe('getSyncContacts', () => {
it('', async () => {
it('un-syncable message returns false', async () => {
const message = TestUtils.generateChatMessage();
// Stubbed
const canSync = SyncMessageUtils.canSync(message);
expect(canSync).to.equal(false, '');
});
});
// describe('getSyncContacts', () => {
// let getAllConversationsStub: sinon.SinonStub;
// const primaryDevicePubkey = generateFakePubKey().key;
// let conversations = [
// {
// isPrivate: () => true,
// isOurLocalDevice: () => false,
// isBlocked: () => false,
// getPrimaryDevicePubKey: () => primaryDevicePubkey,
// attributes: {
// secondaryStatus: undefined,
// },
// },
// ];
// const sandbox = sinon.createSandbox();
// const ourDevice = TestUtils.generateFakePubKey();
// const ourNumber = ourDevice.key;
// const ourPrimaryDevice = TestUtils.generateFakePubKey();
// const ourPrimaryNumber = ourPrimaryDevice.key;
// beforeEach(async () => {
// getAllConversationsStub = TestUtils.stubData('getAllConversations').resolves(conversations);
// // Stubs
// sandbox.stub(UserUtil, 'getCurrentDevicePubKey').resolves(ourNumber);
// sandbox.stub(MultiDeviceProtocol, 'getPrimaryDevice').resolves(ourPrimaryDevice);
// });
// afterEach(() => {
// sandbox.restore();
// });
// it('can get sync contacts', async () => {
// // MAKE MORE SPECIFIC, CHECK PARAMETERS
// const contacts = await SyncMessageUtils.getSyncContacts();
// console.log('[vince] contacts:', contacts);
// console.log('[vince] contacts:', contacts);
// console.log('[vince] getAllConversationsStub.callCount:', getAllConversationsStub.callCount);
// console.log('[vince] getAllConversationsStub.callCount:', getAllConversationsStub.callCount);
// });
// });

Loading…
Cancel
Save