From aa6ce0787b7dd909be5bdfcad7c34aa480a9bb2c Mon Sep 17 00:00:00 2001 From: Vincent Date: Mon, 22 Jun 2020 12:05:37 +1000 Subject: [PATCH] with-electron? --- integration_test/settings_test.js | 1 + integration_test/utils/SyncMessage_test.js | 56 ++++++++++++ ts/session/utils/SyncMessage.ts | 11 +++ ts/test/session/sending/MessageQueue_test.ts | 2 +- ts/test/session/utils/Groups_test.ts | 35 ++++++++ ts/test/session/utils/Messages_test.ts | 22 ++--- ts/test/session/utils/Promise_test.ts | 40 +++++++++ ts/test/session/utils/String_test.ts | 32 +++++++ ts/test/session/utils/SyncMessage_test.ts | 93 +++++++++++++++++--- 9 files changed, 268 insertions(+), 24 deletions(-) create mode 100644 integration_test/utils/SyncMessage_test.js create mode 100644 ts/test/session/utils/Groups_test.ts create mode 100644 ts/test/session/utils/Promise_test.ts create mode 100644 ts/test/session/utils/String_test.ts diff --git a/integration_test/settings_test.js b/integration_test/settings_test.js index cf463a411..50f2b507e 100644 --- a/integration_test/settings_test.js +++ b/integration_test/settings_test.js @@ -31,6 +31,7 @@ describe('Settings', function() { app = await common.startAndStub(appProps); }); + after(async () => { await common.stopApp(app); diff --git a/integration_test/utils/SyncMessage_test.js b/integration_test/utils/SyncMessage_test.js new file mode 100644 index 000000000..526ece449 --- /dev/null +++ b/integration_test/utils/SyncMessage_test.js @@ -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); + }); + }); + + + + +}); diff --git a/ts/session/utils/SyncMessage.ts b/ts/session/utils/SyncMessage.ts index cdbe6b3f7..033a2241d 100644 --- a/ts/session/utils/SyncMessage.ts +++ b/ts/session/utils/SyncMessage.ts @@ -27,12 +27,23 @@ export async function getSyncContacts(): Promise | undefined> { if (!thisDevice) { 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( diff --git a/ts/test/session/sending/MessageQueue_test.ts b/ts/test/session/sending/MessageQueue_test.ts index 813ae20c6..6b7c4685c 100644 --- a/ts/test/session/sending/MessageQueue_test.ts +++ b/ts/test/session/sending/MessageQueue_test.ts @@ -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 diff --git a/ts/test/session/utils/Groups_test.ts b/ts/test/session/utils/Groups_test.ts new file mode 100644 index 000000000..2fda27ea2 --- /dev/null +++ b/ts/test/session/utils/Groups_test.ts @@ -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 () => { + // + }); + }); + + + + +}); diff --git a/ts/test/session/utils/Messages_test.ts b/ts/test/session/utils/Messages_test.ts index 61cdce164..922d5c758 100644 --- a/ts/test/session/utils/Messages_test.ts +++ b/ts/test/session/utils/Messages_test.ts @@ -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; diff --git a/ts/test/session/utils/Promise_test.ts b/ts/test/session/utils/Promise_test.ts new file mode 100644 index 000000000..a120e5fe8 --- /dev/null +++ b/ts/test/session/utils/Promise_test.ts @@ -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 () => { + // + }); + }); + +}); diff --git a/ts/test/session/utils/String_test.ts b/ts/test/session/utils/String_test.ts new file mode 100644 index 000000000..73cac6bcf --- /dev/null +++ b/ts/test/session/utils/String_test.ts @@ -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 () => { + // + }); + }); + +}); diff --git a/ts/test/session/utils/SyncMessage_test.ts b/ts/test/session/utils/SyncMessage_test.ts index c5dc70db1..dc28dda6e 100644 --- a/ts/test/session/utils/SyncMessage_test.ts +++ b/ts/test/session/utils/SyncMessage_test.ts @@ -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, ''); }); - }); + it('un-syncable message returns false', async () => { + const message = TestUtils.generateChatMessage(); - describe('getSyncContacts', () => { - it('', async () => { - + // 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); + + // }); + + // }); +