From c12c3b5f64b4f3c033c317ff1851523ad45d3789 Mon Sep 17 00:00:00 2001 From: Audric Ackermann Date: Mon, 3 Aug 2020 11:25:06 +1000 Subject: [PATCH] move stub of integration tests to typescript --- js/modules/loki_app_dot_net_api.d.ts | 1 + js/modules/loki_public_chat_api.js | 2 +- preload.js | 4 +- .../session/integration/add_contacts_test.ts | 5 +- .../session/integration/closed_group_test.ts | 33 ++++---- .../session/integration/integration_test.ts | 9 ++- .../session/integration/link_device_test.ts | 6 +- .../integration/message_functions_test.ts | 41 +++++----- .../session/integration/message_sync_test.ts | 72 +++++++++--------- .../session/integration/open_group_test.ts | 5 +- .../session/integration/registration_test.ts | 5 +- .../session/integration/sender_keys_test.ts | 65 ++++++++-------- .../test/session/integration/settings_test.ts | 46 +++++------ .../integration/stubs/stub_app_dot_net_api.ts | 9 ++- .../integration/stubs/stub_message_api.ts | 22 ++++-- .../test/session/integration}/test_attachment | Bin 16 files changed, 179 insertions(+), 146 deletions(-) rename integration_test/closed_group_test.js => ts/test/session/integration/closed_group_test.ts (61%) rename integration_test/message_functions_test.js => ts/test/session/integration/message_functions_test.ts (66%) rename integration_test/message_sync_test.js => ts/test/session/integration/message_sync_test.ts (67%) rename integration_test/sender_keys_test.js => ts/test/session/integration/sender_keys_test.ts (66%) rename integration_test/settings_test.js => ts/test/session/integration/settings_test.ts (70%) rename integration_test/stubs/stub_app_dot_net_api.js => ts/test/session/integration/stubs/stub_app_dot_net_api.ts (93%) rename integration_test/stubs/stub_message_api.js => ts/test/session/integration/stubs/stub_message_api.ts (54%) rename {integration_test => ts/test/session/integration}/test_attachment (100%) diff --git a/js/modules/loki_app_dot_net_api.d.ts b/js/modules/loki_app_dot_net_api.d.ts index f578c40ab..df50f3424 100644 --- a/js/modules/loki_app_dot_net_api.d.ts +++ b/js/modules/loki_app_dot_net_api.d.ts @@ -34,6 +34,7 @@ export interface LokiPublicChannelAPI { } declare class LokiAppDotNetServerAPI implements LokiAppDotNetServerInterface { + public baseServerUrl: string; constructor(ourKey: string, url: string); } diff --git a/js/modules/loki_public_chat_api.js b/js/modules/loki_public_chat_api.js index e37c01f3c..4578baade 100644 --- a/js/modules/loki_public_chat_api.js +++ b/js/modules/loki_public_chat_api.js @@ -117,7 +117,7 @@ class LokiPublicChatFactoryAPI extends EventEmitter { // after verification then we can start up all the pollers if (process.env.USE_STUBBED_NETWORK) { // eslint-disable-next-line global-require - const StubAppDotNetAPI = require('../../integration_test/stubs/stub_app_dot_net_api.js'); + const StubAppDotNetAPI = require('../.././ts/test/session/integration/stubs/stub_app_dot_net_api'); thisServer = new StubAppDotNetAPI(this.ourKey, serverUrl); } else { thisServer = new LokiAppDotNetAPI(this.ourKey, serverUrl); diff --git a/preload.js b/preload.js index 38ed1056b..c5a57bf92 100644 --- a/preload.js +++ b/preload.js @@ -341,10 +341,10 @@ const { OnionAPI } = require('./ts/session/onions'); window.OnionAPI = OnionAPI; if (process.env.USE_STUBBED_NETWORK) { - const StubMessageAPI = require('./integration_test/stubs/stub_message_api'); + const StubMessageAPI = require('./ts/test/session/integration/stubs/stub_message_api'); window.LokiMessageAPI = StubMessageAPI; - const StubAppDotNetAPI = require('./integration_test/stubs/stub_app_dot_net_api'); + const StubAppDotNetAPI = require('./ts/test/session/integration/stubs/stub_app_dot_net_api'); window.LokiAppDotNetServerAPI = StubAppDotNetAPI; } else { window.LokiMessageAPI = require('./js/modules/loki_message_api'); diff --git a/ts/test/session/integration/add_contacts_test.ts b/ts/test/session/integration/add_contacts_test.ts index 7d617f984..d644284b2 100644 --- a/ts/test/session/integration/add_contacts_test.ts +++ b/ts/test/session/integration/add_contacts_test.ts @@ -2,6 +2,7 @@ /* eslint-disable import/no-extraneous-dependencies */ // tslint:disable: await-promise // tslint:disable: no-implicit-dependencies +// tslint:disable: no-invalid-this import { afterEach, beforeEach, describe, it } from 'mocha'; import { Common } from './common'; @@ -10,10 +11,10 @@ import { Application } from 'spectron'; import ConversationPage from './page-objects/conversation.page'; describe('Add contact', function() { + this.timeout(60000); + this.slow(20000); let app: Application; let app2: Application; - this.timeout(60000); - this.slow(15000); beforeEach(async () => { await Common.killallElectron(); diff --git a/integration_test/closed_group_test.js b/ts/test/session/integration/closed_group_test.ts similarity index 61% rename from integration_test/closed_group_test.js rename to ts/test/session/integration/closed_group_test.ts index 49aabf0f1..c6023c713 100644 --- a/integration_test/closed_group_test.js +++ b/ts/test/session/integration/closed_group_test.ts @@ -1,37 +1,42 @@ /* eslint-disable func-names */ /* eslint-disable import/no-extraneous-dependencies */ -const { afterEach, beforeEach, describe, it } = require('mocha'); -const common = require('./common'); +// tslint:disable: await-promise +// tslint:disable: no-implicit-dependencies +// tslint:disable: no-invalid-this -const ConversationPage = require('./page-objects/conversation.page'); +import { afterEach, beforeEach, describe, it } from 'mocha'; +import { Common } from './common'; +import { Application } from 'spectron'; + +import ConversationPage from './page-objects/conversation.page'; describe('Closed groups', function() { - let app; - let app2; this.timeout(60000); - this.slow(15000); + this.slow(20000); + let app: Application; + let app2: Application; beforeEach(async () => { - await common.killallElectron(); - await common.stopStubSnodeServer(); + await Common.killallElectron(); + await Common.stopStubSnodeServer(); - [app, app2] = await common.startAppsAsFriends(); + [app, app2] = await Common.startAppsAsFriends(); }); afterEach(async () => { - await common.stopApp(app); - await common.killallElectron(); - await common.stopStubSnodeServer(); + await Common.stopApp(app); + await Common.killallElectron(); + await Common.stopStubSnodeServer(); }); it('closedGroup: can create a closed group with a friend and send/receive a message', async () => { const useSenderKeys = false; // create group and add new friend - await common.addFriendToNewClosedGroup([app, app2], useSenderKeys); + await Common.addFriendToNewClosedGroup([app, app2], useSenderKeys); // send a message from app and validate it is received on app2 - const textMessage = common.generateSendMessageText(); + const textMessage = Common.generateSendMessageText(); await app.client .element(ConversationPage.sendMessageTextarea) .setValue(textMessage); diff --git a/ts/test/session/integration/integration_test.ts b/ts/test/session/integration/integration_test.ts index a1bd00acf..cde34e6f3 100644 --- a/ts/test/session/integration/integration_test.ts +++ b/ts/test/session/integration/integration_test.ts @@ -1,7 +1,6 @@ import { Common } from './common'; -// tslint:disable: no-import-side-effect -// tslint:disable: await-promise +// tslint:disable: no-import-side-effect no-invalid-this await-promise import './registration_test'; import './open_group_test'; @@ -13,11 +12,13 @@ import './link_device_test'; // import'./message_sync_test'; // import './sender_keys_test'; -before(async () => { +before(async function() { // start the app once before all tests to get the platform-dependent // path of user data and store it to common.USER_DATA_ROOT_FOLDER + this.timeout(60000); + this.slow(20000); const app1 = await Common.startApp(); - const ret = (await app1.electron.remote.app.getPath('appData')) as any; + const ret = await app1.electron.remote.app.getPath('appData'); Common.USER_DATA_ROOT_FOLDER = ret; await Common.stopApp(app1); diff --git a/ts/test/session/integration/link_device_test.ts b/ts/test/session/integration/link_device_test.ts index 51900c536..b1d1d04ac 100644 --- a/ts/test/session/integration/link_device_test.ts +++ b/ts/test/session/integration/link_device_test.ts @@ -4,6 +4,7 @@ /* eslint-disable import/no-extraneous-dependencies */ // tslint:disable: no-implicit-dependencies // tslint:disable: await-promise +// tslint:disable: no-invalid-this import { afterEach, beforeEach, describe, it } from 'mocha'; import { Common } from './common'; @@ -12,11 +13,10 @@ import * as TestUtils from '../../test-utils/utils/stubbing'; import { expect } from 'chai'; describe('Link Device', function() { + this.timeout(60000); + this.slow(20000); let app: Application; let app2: Application; - this.timeout(60000); - this.slow(15000); - beforeEach(async () => { await Common.killallElectron(); diff --git a/integration_test/message_functions_test.js b/ts/test/session/integration/message_functions_test.ts similarity index 66% rename from integration_test/message_functions_test.js rename to ts/test/session/integration/message_functions_test.ts index 245664ff1..ac25701ff 100644 --- a/integration_test/message_functions_test.js +++ b/ts/test/session/integration/message_functions_test.ts @@ -1,41 +1,44 @@ -/* eslint-disable prefer-destructuring */ -/* eslint-disable more/no-then */ /* eslint-disable func-names */ /* eslint-disable import/no-extraneous-dependencies */ -const path = require('path'); +// tslint:disable: await-promise +// tslint:disable: no-implicit-dependencies +// tslint:disable: no-invalid-this -const { afterEach, beforeEach, describe, it } = require('mocha'); -const common = require('./common'); -const ConversationPage = require('./page-objects/conversation.page'); +import path from 'path'; +import { afterEach, beforeEach, describe, it } from 'mocha'; +import { Common } from './common'; +import { Application } from 'spectron'; + +import ConversationPage from './page-objects/conversation.page'; describe('Message Functions', function() { - let app; - let app2; this.timeout(60000); - this.slow(15000); + this.slow(20000); + let app: Application; + let app2: Application; beforeEach(async () => { - await common.killallElectron(); - await common.stopStubSnodeServer(); + await Common.killallElectron(); + await Common.stopStubSnodeServer(); - [app, app2] = await common.startAppsAsFriends(); + [app, app2] = await Common.startAppsAsFriends(); }); afterEach(async () => { - await common.stopApp(app); - await common.killallElectron(); - await common.stopStubSnodeServer(); + await Common.stopApp(app); + await Common.killallElectron(); + await Common.stopStubSnodeServer(); }); it('can send attachment', async () => { // create group and add new friend - await common.addFriendToNewClosedGroup([app, app2], false); + await Common.addFriendToNewClosedGroup([app, app2], false); // send attachment from app1 to closed group const fileLocation = path.join(__dirname, 'test_attachment'); const messageText = 'test_attachment'; - await common.sendMessage(app, messageText, fileLocation); + await Common.sendMessage(app, messageText, fileLocation); // validate attachment sent await app.client.waitForExist( @@ -51,9 +54,9 @@ describe('Message Functions', function() { it('can delete message', async () => { // create group and add new friend - await common.addFriendToNewClosedGroup([app, app2], false); + await Common.addFriendToNewClosedGroup([app, app2], false); const messageText = 'delete_me'; - await common.sendMessage(app, messageText); + await Common.sendMessage(app, messageText); await app.client.waitForExist( ConversationPage.existingSendMessageText(messageText), diff --git a/integration_test/message_sync_test.js b/ts/test/session/integration/message_sync_test.ts similarity index 67% rename from integration_test/message_sync_test.js rename to ts/test/session/integration/message_sync_test.ts index 3aa078e23..d05ad04b3 100644 --- a/integration_test/message_sync_test.js +++ b/ts/test/session/integration/message_sync_test.ts @@ -1,39 +1,43 @@ /* eslint-disable func-names */ /* eslint-disable import/no-extraneous-dependencies */ -const { after, before, describe, it } = require('mocha'); +// tslint:disable: await-promise +// tslint:disable: no-implicit-dependencies +// tslint:disable: no-invalid-this -const common = require('./common'); +import { after, before, describe, it } from 'mocha'; +import { Common } from './common'; +import { Application } from 'spectron'; describe('Message Syncing', function() { - let Alice1; - let Bob1; - let Alice2; this.timeout(60000); - this.slow(15000); + this.slow(20000); + let Alice1: Application; + let Bob1: Application; + let Alice2: Application; // this test suite builds a complex usecase over several tests, // so you need to run all of those tests together (running only one might fail) before(async () => { - await common.killallElectron(); - await common.stopStubSnodeServer(); + await Common.killallElectron(); + await Common.stopStubSnodeServer(); const alice2Props = {}; - [Alice1, Bob1] = await common.startAppsAsFriends(); // Alice and Bob are friends + [Alice1, Bob1] = await Common.startAppsAsFriends(); // Alice and Bob are friends - await common.addFriendToNewClosedGroup([Alice1, Bob1], false); - await common.joinOpenGroup( + await Common.addFriendToNewClosedGroup([Alice1, Bob1], false); + await Common.joinOpenGroup( Alice1, - common.VALID_GROUP_URL, - common.VALID_GROUP_NAME + Common.VALID_GROUP_URL, + Common.VALID_GROUP_NAME ); - Alice2 = await common.startAndStubN(alice2Props, 4); // Alice secondary, just start the app for now. no linking + Alice2 = await Common.startAndStubN(alice2Props, 4); // Alice secondary, just start the app for now. no linking }); after(async () => { - await common.killallElectron(); - await common.stopStubSnodeServer(); + await Common.killallElectron(); + await Common.stopStubSnodeServer(); }); it('message syncing with 1 friend, 1 closed group, 1 open group', async () => { @@ -51,8 +55,8 @@ describe('Message Syncing', function() { // Linking Alice2 to Alice1 // alice2 should trigger auto FR with bob1 as it's one of her friend // and alice2 should trigger a FALLBACK_MESSAGE with bob1 as he is in a closed group with her - await common.linkApp2ToApp(Alice1, Alice2, common.TEST_PUBKEY1); - await common.timeout(25000); + await Common.linkApp2ToApp(Alice1, Alice2, Common.TEST_PUBKEY1); + await Common.timeout(25000); // validate pubkey of app2 is the set const alice2Pubkey = await Alice2.webContents.executeJavaScript( @@ -65,17 +69,17 @@ describe('Message Syncing', function() { const alice2Logs = await Alice2.client.getRenderProcessLogs(); // validate primary alice - await common.logsContains( + await Common.logsContains( alice1Logs, 'Sending closed-group-sync-send:outgoing message to OUR SECONDARY PUBKEY', 1 ); - await common.logsContains( + await Common.logsContains( alice1Logs, 'Sending open-group-sync-send:outgoing message to OUR SECONDARY PUBKEY', 1 ); - await common.logsContains( + await Common.logsContains( alice1Logs, 'Sending contact-sync-send:outgoing message to OUR SECONDARY PUBKEY', 1 @@ -86,29 +90,29 @@ describe('Message Syncing', function() { // alice2 receives group sync, contact sync and open group sync // alice2 triggers session request with closed group members and autoFR with contact sync received // once autoFR is auto-accepted, alice2 trigger contact sync - await common.logsContains( + await Common.logsContains( alice2Logs, 'Got sync group message with group id', 1 ); - await common.logsContains( + await Common.logsContains( alice2Logs, 'Received GROUP_SYNC with open groups: [chat.getsession.org]', 1 ); - await common.logsContains( + await Common.logsContains( alice2Logs, - `Sending auto-friend-request:friend-request message to ${common.TEST_PUBKEY2}`, + `Sending auto-friend-request:friend-request message to ${Common.TEST_PUBKEY2}`, 1 ); - await common.logsContains( + await Common.logsContains( alice2Logs, - `Sending session-request:friend-request message to ${common.TEST_PUBKEY2}`, + `Sending session-request:friend-request message to ${Common.TEST_PUBKEY2}`, 1 ); - await common.logsContains( + await Common.logsContains( alice2Logs, - `Sending contact-sync-send:outgoing message to OUR_PRIMARY_PUBKEY`, + 'Sending contact-sync-send:outgoing message to OUR_PRIMARY_PUBKEY', 1 ); @@ -117,25 +121,25 @@ describe('Message Syncing', function() { // bob1 receives session request from alice2 // bob1 accept auto fr by sending a bg message // once autoFR is auto-accepted, alice2 trigger contact sync - await common.logsContains( + await Common.logsContains( bob1Logs, `Received FALLBACK_MESSAGE from source: ${alice2Pubkey}`, 1 ); - await common.logsContains( + await Common.logsContains( bob1Logs, `Received AUTO_FRIEND_REQUEST from source: ${alice2Pubkey}`, 1 ); - await common.logsContains( + await Common.logsContains( bob1Logs, `Sending auto-friend-accept:onlineBroadcast message to ${alice2Pubkey}`, 1 ); // be sure only one autoFR accept was sent (even if multi device, we need to reply to that specific device only) - await common.logsContains( + await Common.logsContains( bob1Logs, - `Sending auto-friend-accept:onlineBroadcast message to`, + 'Sending auto-friend-accept:onlineBroadcast message to', 1 ); }); diff --git a/ts/test/session/integration/open_group_test.ts b/ts/test/session/integration/open_group_test.ts index a38d5f570..ecf8acf07 100644 --- a/ts/test/session/integration/open_group_test.ts +++ b/ts/test/session/integration/open_group_test.ts @@ -2,6 +2,7 @@ /* eslint-disable import/no-extraneous-dependencies */ // tslint:disable: await-promise // tslint:disable: no-implicit-dependencies +// tslint:disable: no-invalid-this import { afterEach, beforeEach, describe, it } from 'mocha'; import { Common } from './common'; @@ -10,9 +11,9 @@ import { Application } from 'spectron'; import ConversationPage from './page-objects/conversation.page'; describe('Open groups', function() { + this.timeout(60000); + this.slow(20000); let app: Application; - this.timeout(40000); - this.slow(15000); beforeEach(async () => { await Common.killallElectron(); diff --git a/ts/test/session/integration/registration_test.ts b/ts/test/session/integration/registration_test.ts index 5e62052b5..cbbcd28bb 100644 --- a/ts/test/session/integration/registration_test.ts +++ b/ts/test/session/integration/registration_test.ts @@ -3,6 +3,7 @@ /* eslint-disable import/no-extraneous-dependencies */ // tslint:disable: no-implicit-dependencies // tslint:disable: await-promise +// tslint:disable: no-invalid-this import { afterEach, beforeEach, describe, it } from 'mocha'; import { Common } from './common'; @@ -13,9 +14,9 @@ import RegistrationPage from './page-objects/registration.page'; import ConversationPage from './page-objects/conversation.page'; describe('Window Test and Login', function() { + this.timeout(60000); + this.slow(20000); let app: Application; - this.timeout(20000); - this.slow(15000); beforeEach(async () => { await Common.killallElectron(); diff --git a/integration_test/sender_keys_test.js b/ts/test/session/integration/sender_keys_test.ts similarity index 66% rename from integration_test/sender_keys_test.js rename to ts/test/session/integration/sender_keys_test.ts index 836af43c2..e194b545f 100644 --- a/integration_test/sender_keys_test.js +++ b/ts/test/session/integration/sender_keys_test.ts @@ -1,13 +1,17 @@ /* eslint-disable func-names */ /* eslint-disable import/no-extraneous-dependencies */ -const { afterEach, beforeEach, describe, it } = require('mocha'); -const common = require('./common'); +// tslint:disable: await-promise +// tslint:disable: no-implicit-dependencies +// tslint:disable: no-invalid-this -const ConversationPage = require('./page-objects/conversation.page'); +import { afterEach, beforeEach, describe, it } from 'mocha'; +import { Common } from './common'; +import { Application } from 'spectron'; +import ConversationPage from './page-objects/conversation.page'; -async function generateAndSendMessage(app) { +async function generateAndSendMessage(app: Application) { // send a message from app and validate it is received on app2 - const textMessage = common.generateSendMessageText(); + const textMessage = Common.generateSendMessageText(); await app.client .element(ConversationPage.sendMessageTextarea) .setValue(textMessage); @@ -28,8 +32,11 @@ async function generateAndSendMessage(app) { return textMessage; } -async function makeFriendsPlusMessage(app, [app2, pubkey]) { - await common.makeFriends(app, [app2, pubkey]); +async function makeFriendsPlusMessage( + app: Application, + [app2, pubkey]: [Application, string] +) { + await Common.makeFriends(app, [app2, pubkey]); // Send something back so that `app` can see our name const text = await generateAndSendMessage(app2); @@ -43,12 +50,12 @@ async function makeFriendsPlusMessage(app, [app2, pubkey]) { } async function testTwoMembers() { - const [app, app2] = await common.startAppsAsFriends(); + const [app, app2] = await Common.startAppsAsFriends(); const useSenderKeys = true; // create group and add new friend - await common.addFriendToNewClosedGroup([app, app2], useSenderKeys); + await Common.addFriendToNewClosedGroup([app, app2], useSenderKeys); const text1 = await generateAndSendMessage(app); @@ -73,39 +80,39 @@ async function testThreeMembers() { // 1. Make three clients A, B, C const app1Props = { - mnemonic: common.TEST_MNEMONIC1, - displayName: common.TEST_DISPLAY_NAME1, + mnemonic: Common.TEST_MNEMONIC1, + displayName: Common.TEST_DISPLAY_NAME1, stubSnode: true, }; const app2Props = { - mnemonic: common.TEST_MNEMONIC2, - displayName: common.TEST_DISPLAY_NAME2, + mnemonic: Common.TEST_MNEMONIC2, + displayName: Common.TEST_DISPLAY_NAME2, stubSnode: true, }; const app3Props = { - mnemonic: common.TEST_MNEMONIC3, - displayName: common.TEST_DISPLAY_NAME3, + mnemonic: Common.TEST_MNEMONIC3, + displayName: Common.TEST_DISPLAY_NAME3, stubSnode: true, }; const [app1, app2, app3] = await Promise.all([ - common.startAndStub(app1Props), - common.startAndStubN(app2Props, 2), - common.startAndStubN(app3Props, 3), + Common.startAndStub(app1Props), + Common.startAndStubN(app2Props, 2), + Common.startAndStubN(app3Props, 3), ]); // 2. Make A friends with B and C (B and C are not friends) - await makeFriendsPlusMessage(app1, [app2, common.TEST_PUBKEY2]); - await makeFriendsPlusMessage(app1, [app3, common.TEST_PUBKEY3]); + await makeFriendsPlusMessage(app1, [app2, Common.TEST_PUBKEY2]); + await makeFriendsPlusMessage(app1, [app3, Common.TEST_PUBKEY3]); const useSenderKeys = true; // 3. Add all three to the group - await common.addFriendToNewClosedGroup([app1, app2, app3], useSenderKeys); + await Common.addFriendToNewClosedGroup([app1, app2, app3], useSenderKeys); // 4. Test that all members can see the message from app1 const text1 = await generateAndSendMessage(app1); @@ -131,20 +138,16 @@ async function testThreeMembers() { } describe('senderkeys', function() { - let app; - - this.timeout(600000); - this.slow(40000); - + this.timeout(60000); + this.slow(20000); beforeEach(async () => { - await common.killallElectron(); - await common.stopStubSnodeServer(); + await Common.killallElectron(); + await Common.stopStubSnodeServer(); }); afterEach(async () => { - await common.stopApp(app); - await common.killallElectron(); - await common.stopStubSnodeServer(); + await Common.killallElectron(); + await Common.stopStubSnodeServer(); }); it('Two member group', testTwoMembers); diff --git a/integration_test/settings_test.js b/ts/test/session/integration/settings_test.ts similarity index 70% rename from integration_test/settings_test.js rename to ts/test/session/integration/settings_test.ts index cf463a411..a41221221 100644 --- a/integration_test/settings_test.js +++ b/ts/test/session/integration/settings_test.ts @@ -1,41 +1,43 @@ -/* eslint-disable prefer-destructuring */ -/* eslint-disable more/no-then */ -/* eslint-disable func-names */ /* eslint-disable import/no-extraneous-dependencies */ +// tslint:disable: await-promise +// tslint:disable: no-implicit-dependencies +// tslint:disable: no-invalid-this -const { after, before, describe, it } = require('mocha'); -const common = require('./common'); +import { after, before, describe, it } from 'mocha'; +import { Common } from './common'; +import { Application } from 'spectron'; -const SettingsPage = require('./page-objects/settings.page'); -const CommonPage = require('./page-objects/common.page'); +import SettingsPage from './page-objects/settings.page'; +import CommonPage from './page-objects/common.page'; // Generate random password +// tslint:disable-next-line: insecure-random const password = Math.random() .toString(36) .substr(2, 8); const passwordInputID = 'password-modal-input'; describe('Settings', function() { - let app; this.timeout(60000); - this.slow(15000); + this.slow(20000); + let app: Application; before(async () => { - await common.killallElectron(); - await common.stopStubSnodeServer(); + await Common.killallElectron(); + await Common.stopStubSnodeServer(); const appProps = { - mnemonic: common.TEST_MNEMONIC1, - displayName: common.TEST_DISPLAY_NAME1, + mnemonic: Common.TEST_MNEMONIC1, + displayName: Common.TEST_DISPLAY_NAME1, }; - app = await common.startAndStub(appProps); + app = await Common.startAndStub(appProps); }); after(async () => { - await common.stopApp(app); - await common.killallElectron(); - await common.stopStubSnodeServer(); + await Common.stopApp(app); + await Common.killallElectron(); + await Common.stopStubSnodeServer(); }); it('can toggle menubar', async () => { @@ -60,12 +62,12 @@ describe('Settings', function() { .element(SettingsPage.settingButtonWithText('Set Password')) .click(); - await common.setValueWrapper( + await Common.setValueWrapper( app, CommonPage.inputWithId(passwordInputID), password ); - await common.setValueWrapper( + await Common.setValueWrapper( app, CommonPage.inputWithId(`${passwordInputID}-confirm`), password @@ -79,12 +81,12 @@ describe('Settings', function() { 2000 ); - await common.closeToast(app); + await Common.closeToast(app); }); it('can remove password', async () => { // Enter password to unlock settings - await common.setValueWrapper( + await Common.setValueWrapper( app, CommonPage.inputWithId('password-lock-input'), password @@ -97,7 +99,7 @@ describe('Settings', function() { .element(SettingsPage.settingButtonWithText('Remove Password')) .click(); - await common.setValueWrapper( + await Common.setValueWrapper( app, CommonPage.inputWithId(passwordInputID), password diff --git a/integration_test/stubs/stub_app_dot_net_api.js b/ts/test/session/integration/stubs/stub_app_dot_net_api.ts similarity index 93% rename from integration_test/stubs/stub_app_dot_net_api.js rename to ts/test/session/integration/stubs/stub_app_dot_net_api.ts index 48414c6de..ca6d796cd 100644 --- a/integration_test/stubs/stub_app_dot_net_api.js +++ b/ts/test/session/integration/stubs/stub_app_dot_net_api.ts @@ -1,6 +1,6 @@ /* global clearTimeout, Buffer, TextDecoder, process */ -const OriginalAppDotNetApi = require('../../js/modules/loki_app_dot_net_api.js'); +import LokiAppDotNetServerAPI from '../../../../../js/modules/loki_app_dot_net_api'; const sampleFeed = ' FeedForAll Sample Feed'; @@ -69,9 +69,12 @@ const samplesGetMessages = { ], }; -class StubAppDotNetAPI extends OriginalAppDotNetApi { +class StubAppDotNetAPI extends LokiAppDotNetServerAPI { // make a request to the server - async serverRequest(endpoint, options = {}) { + public async serverRequest( + endpoint: string, + options: { method?: string } = {} + ) { const { method } = options; // console.warn('STUBBED ', method, ':', endpoint); diff --git a/integration_test/stubs/stub_message_api.js b/ts/test/session/integration/stubs/stub_message_api.ts similarity index 54% rename from integration_test/stubs/stub_message_api.js rename to ts/test/session/integration/stubs/stub_message_api.ts index 869fd00fc..3265709a6 100644 --- a/integration_test/stubs/stub_message_api.js +++ b/ts/test/session/integration/stubs/stub_message_api.ts @@ -1,22 +1,30 @@ -/* global clearTimeout, dcodeIO, Buffer, TextDecoder, process */ -const nodeFetch = require('node-fetch'); +import { StringUtils } from '../../../../session/utils'; + +import fetch from 'node-fetch'; class StubMessageAPI { - constructor(ourKey) { + public ourKey: string; + public baseUrl: string; + constructor(ourKey: string) { this.ourKey = ourKey; this.baseUrl = 'http://localhost:3000'; } // eslint-disable-next-line no-unused-vars - async sendMessage(pubKey, data, messageTimeStamp, ttl, options = {}) { + public async sendMessage( + pubKey: string, + data: any, + messageTimeStamp: number, + ttl: number, + options = {} + ) { // console.warn('STUBBED message api ', pubKey, ttl); const post = { method: 'POST', }; - const data64 = dcodeIO.ByteBuffer.wrap(data).toString('base64'); - - await nodeFetch( + const data64 = StringUtils.decode(data, 'base64'); + await fetch( `${ this.baseUrl }/messages?pubkey=${pubKey}×tamp=${messageTimeStamp}&data=${encodeURIComponent( diff --git a/integration_test/test_attachment b/ts/test/session/integration/test_attachment similarity index 100% rename from integration_test/test_attachment rename to ts/test/session/integration/test_attachment