move stub of integration tests to typescript

pull/1287/head
Audric Ackermann 5 years ago
parent fec0ead1de
commit c12c3b5f64
No known key found for this signature in database
GPG Key ID: 999F434D76324AD4

@ -34,6 +34,7 @@ export interface LokiPublicChannelAPI {
} }
declare class LokiAppDotNetServerAPI implements LokiAppDotNetServerInterface { declare class LokiAppDotNetServerAPI implements LokiAppDotNetServerInterface {
public baseServerUrl: string;
constructor(ourKey: string, url: string); constructor(ourKey: string, url: string);
} }

@ -117,7 +117,7 @@ class LokiPublicChatFactoryAPI extends EventEmitter {
// after verification then we can start up all the pollers // after verification then we can start up all the pollers
if (process.env.USE_STUBBED_NETWORK) { if (process.env.USE_STUBBED_NETWORK) {
// eslint-disable-next-line global-require // 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); thisServer = new StubAppDotNetAPI(this.ourKey, serverUrl);
} else { } else {
thisServer = new LokiAppDotNetAPI(this.ourKey, serverUrl); thisServer = new LokiAppDotNetAPI(this.ourKey, serverUrl);

@ -341,10 +341,10 @@ const { OnionAPI } = require('./ts/session/onions');
window.OnionAPI = OnionAPI; window.OnionAPI = OnionAPI;
if (process.env.USE_STUBBED_NETWORK) { 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; 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; window.LokiAppDotNetServerAPI = StubAppDotNetAPI;
} else { } else {
window.LokiMessageAPI = require('./js/modules/loki_message_api'); window.LokiMessageAPI = require('./js/modules/loki_message_api');

@ -2,6 +2,7 @@
/* eslint-disable import/no-extraneous-dependencies */ /* eslint-disable import/no-extraneous-dependencies */
// tslint:disable: await-promise // tslint:disable: await-promise
// tslint:disable: no-implicit-dependencies // tslint:disable: no-implicit-dependencies
// tslint:disable: no-invalid-this
import { afterEach, beforeEach, describe, it } from 'mocha'; import { afterEach, beforeEach, describe, it } from 'mocha';
import { Common } from './common'; import { Common } from './common';
@ -10,10 +11,10 @@ import { Application } from 'spectron';
import ConversationPage from './page-objects/conversation.page'; import ConversationPage from './page-objects/conversation.page';
describe('Add contact', function() { describe('Add contact', function() {
this.timeout(60000);
this.slow(20000);
let app: Application; let app: Application;
let app2: Application; let app2: Application;
this.timeout(60000);
this.slow(15000);
beforeEach(async () => { beforeEach(async () => {
await Common.killallElectron(); await Common.killallElectron();

@ -1,37 +1,42 @@
/* eslint-disable func-names */ /* eslint-disable func-names */
/* eslint-disable import/no-extraneous-dependencies */ /* eslint-disable import/no-extraneous-dependencies */
const { afterEach, beforeEach, describe, it } = require('mocha'); // tslint:disable: await-promise
const common = require('./common'); // 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() { describe('Closed groups', function() {
let app;
let app2;
this.timeout(60000); this.timeout(60000);
this.slow(15000); this.slow(20000);
let app: Application;
let app2: Application;
beforeEach(async () => { beforeEach(async () => {
await common.killallElectron(); await Common.killallElectron();
await common.stopStubSnodeServer(); await Common.stopStubSnodeServer();
[app, app2] = await common.startAppsAsFriends(); [app, app2] = await Common.startAppsAsFriends();
}); });
afterEach(async () => { afterEach(async () => {
await common.stopApp(app); await Common.stopApp(app);
await common.killallElectron(); await Common.killallElectron();
await common.stopStubSnodeServer(); await Common.stopStubSnodeServer();
}); });
it('closedGroup: can create a closed group with a friend and send/receive a message', async () => { it('closedGroup: can create a closed group with a friend and send/receive a message', async () => {
const useSenderKeys = false; const useSenderKeys = false;
// create group and add new friend // 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 // send a message from app and validate it is received on app2
const textMessage = common.generateSendMessageText(); const textMessage = Common.generateSendMessageText();
await app.client await app.client
.element(ConversationPage.sendMessageTextarea) .element(ConversationPage.sendMessageTextarea)
.setValue(textMessage); .setValue(textMessage);

@ -1,7 +1,6 @@
import { Common } from './common'; import { Common } from './common';
// tslint:disable: no-import-side-effect // tslint:disable: no-import-side-effect no-invalid-this await-promise
// tslint:disable: await-promise
import './registration_test'; import './registration_test';
import './open_group_test'; import './open_group_test';
@ -13,11 +12,13 @@ import './link_device_test';
// import'./message_sync_test'; // import'./message_sync_test';
// import './sender_keys_test'; // import './sender_keys_test';
before(async () => { before(async function() {
// start the app once before all tests to get the platform-dependent // 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 // 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 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; Common.USER_DATA_ROOT_FOLDER = ret;
await Common.stopApp(app1); await Common.stopApp(app1);

@ -4,6 +4,7 @@
/* eslint-disable import/no-extraneous-dependencies */ /* eslint-disable import/no-extraneous-dependencies */
// tslint:disable: no-implicit-dependencies // tslint:disable: no-implicit-dependencies
// tslint:disable: await-promise // tslint:disable: await-promise
// tslint:disable: no-invalid-this
import { afterEach, beforeEach, describe, it } from 'mocha'; import { afterEach, beforeEach, describe, it } from 'mocha';
import { Common } from './common'; import { Common } from './common';
@ -12,11 +13,10 @@ import * as TestUtils from '../../test-utils/utils/stubbing';
import { expect } from 'chai'; import { expect } from 'chai';
describe('Link Device', function() { describe('Link Device', function() {
this.timeout(60000);
this.slow(20000);
let app: Application; let app: Application;
let app2: Application; let app2: Application;
this.timeout(60000);
this.slow(15000);
beforeEach(async () => { beforeEach(async () => {
await Common.killallElectron(); await Common.killallElectron();

@ -1,41 +1,44 @@
/* eslint-disable prefer-destructuring */
/* eslint-disable more/no-then */
/* eslint-disable func-names */ /* eslint-disable func-names */
/* eslint-disable import/no-extraneous-dependencies */ /* 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'); import path from 'path';
const common = require('./common'); import { afterEach, beforeEach, describe, it } from 'mocha';
const ConversationPage = require('./page-objects/conversation.page'); import { Common } from './common';
import { Application } from 'spectron';
import ConversationPage from './page-objects/conversation.page';
describe('Message Functions', function() { describe('Message Functions', function() {
let app;
let app2;
this.timeout(60000); this.timeout(60000);
this.slow(15000); this.slow(20000);
let app: Application;
let app2: Application;
beforeEach(async () => { beforeEach(async () => {
await common.killallElectron(); await Common.killallElectron();
await common.stopStubSnodeServer(); await Common.stopStubSnodeServer();
[app, app2] = await common.startAppsAsFriends(); [app, app2] = await Common.startAppsAsFriends();
}); });
afterEach(async () => { afterEach(async () => {
await common.stopApp(app); await Common.stopApp(app);
await common.killallElectron(); await Common.killallElectron();
await common.stopStubSnodeServer(); await Common.stopStubSnodeServer();
}); });
it('can send attachment', async () => { it('can send attachment', async () => {
// create group and add new friend // 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 // send attachment from app1 to closed group
const fileLocation = path.join(__dirname, 'test_attachment'); const fileLocation = path.join(__dirname, 'test_attachment');
const messageText = 'test_attachment'; const messageText = 'test_attachment';
await common.sendMessage(app, messageText, fileLocation); await Common.sendMessage(app, messageText, fileLocation);
// validate attachment sent // validate attachment sent
await app.client.waitForExist( await app.client.waitForExist(
@ -51,9 +54,9 @@ describe('Message Functions', function() {
it('can delete message', async () => { it('can delete message', async () => {
// create group and add new friend // create group and add new friend
await common.addFriendToNewClosedGroup([app, app2], false); await Common.addFriendToNewClosedGroup([app, app2], false);
const messageText = 'delete_me'; const messageText = 'delete_me';
await common.sendMessage(app, messageText); await Common.sendMessage(app, messageText);
await app.client.waitForExist( await app.client.waitForExist(
ConversationPage.existingSendMessageText(messageText), ConversationPage.existingSendMessageText(messageText),

@ -1,39 +1,43 @@
/* eslint-disable func-names */ /* eslint-disable func-names */
/* eslint-disable import/no-extraneous-dependencies */ /* 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() { describe('Message Syncing', function() {
let Alice1;
let Bob1;
let Alice2;
this.timeout(60000); 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, // 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) // so you need to run all of those tests together (running only one might fail)
before(async () => { before(async () => {
await common.killallElectron(); await Common.killallElectron();
await common.stopStubSnodeServer(); await Common.stopStubSnodeServer();
const alice2Props = {}; 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.addFriendToNewClosedGroup([Alice1, Bob1], false);
await common.joinOpenGroup( await Common.joinOpenGroup(
Alice1, Alice1,
common.VALID_GROUP_URL, Common.VALID_GROUP_URL,
common.VALID_GROUP_NAME 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 () => { after(async () => {
await common.killallElectron(); await Common.killallElectron();
await common.stopStubSnodeServer(); await Common.stopStubSnodeServer();
}); });
it('message syncing with 1 friend, 1 closed group, 1 open group', async () => { 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 // Linking Alice2 to Alice1
// alice2 should trigger auto FR with bob1 as it's one of her friend // 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 // 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.linkApp2ToApp(Alice1, Alice2, Common.TEST_PUBKEY1);
await common.timeout(25000); await Common.timeout(25000);
// validate pubkey of app2 is the set // validate pubkey of app2 is the set
const alice2Pubkey = await Alice2.webContents.executeJavaScript( const alice2Pubkey = await Alice2.webContents.executeJavaScript(
@ -65,17 +69,17 @@ describe('Message Syncing', function() {
const alice2Logs = await Alice2.client.getRenderProcessLogs(); const alice2Logs = await Alice2.client.getRenderProcessLogs();
// validate primary alice // validate primary alice
await common.logsContains( await Common.logsContains(
alice1Logs, alice1Logs,
'Sending closed-group-sync-send:outgoing message to OUR SECONDARY PUBKEY', 'Sending closed-group-sync-send:outgoing message to OUR SECONDARY PUBKEY',
1 1
); );
await common.logsContains( await Common.logsContains(
alice1Logs, alice1Logs,
'Sending open-group-sync-send:outgoing message to OUR SECONDARY PUBKEY', 'Sending open-group-sync-send:outgoing message to OUR SECONDARY PUBKEY',
1 1
); );
await common.logsContains( await Common.logsContains(
alice1Logs, alice1Logs,
'Sending contact-sync-send:outgoing message to OUR SECONDARY PUBKEY', 'Sending contact-sync-send:outgoing message to OUR SECONDARY PUBKEY',
1 1
@ -86,29 +90,29 @@ describe('Message Syncing', function() {
// alice2 receives group sync, contact sync and open group sync // alice2 receives group sync, contact sync and open group sync
// alice2 triggers session request with closed group members and autoFR with contact sync received // alice2 triggers session request with closed group members and autoFR with contact sync received
// once autoFR is auto-accepted, alice2 trigger contact sync // once autoFR is auto-accepted, alice2 trigger contact sync
await common.logsContains( await Common.logsContains(
alice2Logs, alice2Logs,
'Got sync group message with group id', 'Got sync group message with group id',
1 1
); );
await common.logsContains( await Common.logsContains(
alice2Logs, alice2Logs,
'Received GROUP_SYNC with open groups: [chat.getsession.org]', 'Received GROUP_SYNC with open groups: [chat.getsession.org]',
1 1
); );
await common.logsContains( await Common.logsContains(
alice2Logs, alice2Logs,
`Sending auto-friend-request:friend-request message to ${common.TEST_PUBKEY2}`, `Sending auto-friend-request:friend-request message to ${Common.TEST_PUBKEY2}`,
1 1
); );
await common.logsContains( await Common.logsContains(
alice2Logs, alice2Logs,
`Sending session-request:friend-request message to ${common.TEST_PUBKEY2}`, `Sending session-request:friend-request message to ${Common.TEST_PUBKEY2}`,
1 1
); );
await common.logsContains( await Common.logsContains(
alice2Logs, alice2Logs,
`Sending contact-sync-send:outgoing message to OUR_PRIMARY_PUBKEY`, 'Sending contact-sync-send:outgoing message to OUR_PRIMARY_PUBKEY',
1 1
); );
@ -117,25 +121,25 @@ describe('Message Syncing', function() {
// bob1 receives session request from alice2 // bob1 receives session request from alice2
// bob1 accept auto fr by sending a bg message // bob1 accept auto fr by sending a bg message
// once autoFR is auto-accepted, alice2 trigger contact sync // once autoFR is auto-accepted, alice2 trigger contact sync
await common.logsContains( await Common.logsContains(
bob1Logs, bob1Logs,
`Received FALLBACK_MESSAGE from source: ${alice2Pubkey}`, `Received FALLBACK_MESSAGE from source: ${alice2Pubkey}`,
1 1
); );
await common.logsContains( await Common.logsContains(
bob1Logs, bob1Logs,
`Received AUTO_FRIEND_REQUEST from source: ${alice2Pubkey}`, `Received AUTO_FRIEND_REQUEST from source: ${alice2Pubkey}`,
1 1
); );
await common.logsContains( await Common.logsContains(
bob1Logs, bob1Logs,
`Sending auto-friend-accept:onlineBroadcast message to ${alice2Pubkey}`, `Sending auto-friend-accept:onlineBroadcast message to ${alice2Pubkey}`,
1 1
); );
// be sure only one autoFR accept was sent (even if multi device, we need to reply to that specific device only) // 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, bob1Logs,
`Sending auto-friend-accept:onlineBroadcast message to`, 'Sending auto-friend-accept:onlineBroadcast message to',
1 1
); );
}); });

@ -2,6 +2,7 @@
/* eslint-disable import/no-extraneous-dependencies */ /* eslint-disable import/no-extraneous-dependencies */
// tslint:disable: await-promise // tslint:disable: await-promise
// tslint:disable: no-implicit-dependencies // tslint:disable: no-implicit-dependencies
// tslint:disable: no-invalid-this
import { afterEach, beforeEach, describe, it } from 'mocha'; import { afterEach, beforeEach, describe, it } from 'mocha';
import { Common } from './common'; import { Common } from './common';
@ -10,9 +11,9 @@ import { Application } from 'spectron';
import ConversationPage from './page-objects/conversation.page'; import ConversationPage from './page-objects/conversation.page';
describe('Open groups', function() { describe('Open groups', function() {
this.timeout(60000);
this.slow(20000);
let app: Application; let app: Application;
this.timeout(40000);
this.slow(15000);
beforeEach(async () => { beforeEach(async () => {
await Common.killallElectron(); await Common.killallElectron();

@ -3,6 +3,7 @@
/* eslint-disable import/no-extraneous-dependencies */ /* eslint-disable import/no-extraneous-dependencies */
// tslint:disable: no-implicit-dependencies // tslint:disable: no-implicit-dependencies
// tslint:disable: await-promise // tslint:disable: await-promise
// tslint:disable: no-invalid-this
import { afterEach, beforeEach, describe, it } from 'mocha'; import { afterEach, beforeEach, describe, it } from 'mocha';
import { Common } from './common'; import { Common } from './common';
@ -13,9 +14,9 @@ import RegistrationPage from './page-objects/registration.page';
import ConversationPage from './page-objects/conversation.page'; import ConversationPage from './page-objects/conversation.page';
describe('Window Test and Login', function() { describe('Window Test and Login', function() {
this.timeout(60000);
this.slow(20000);
let app: Application; let app: Application;
this.timeout(20000);
this.slow(15000);
beforeEach(async () => { beforeEach(async () => {
await Common.killallElectron(); await Common.killallElectron();

@ -1,13 +1,17 @@
/* eslint-disable func-names */ /* eslint-disable func-names */
/* eslint-disable import/no-extraneous-dependencies */ /* eslint-disable import/no-extraneous-dependencies */
const { afterEach, beforeEach, describe, it } = require('mocha'); // tslint:disable: await-promise
const common = require('./common'); // 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 // send a message from app and validate it is received on app2
const textMessage = common.generateSendMessageText(); const textMessage = Common.generateSendMessageText();
await app.client await app.client
.element(ConversationPage.sendMessageTextarea) .element(ConversationPage.sendMessageTextarea)
.setValue(textMessage); .setValue(textMessage);
@ -28,8 +32,11 @@ async function generateAndSendMessage(app) {
return textMessage; return textMessage;
} }
async function makeFriendsPlusMessage(app, [app2, pubkey]) { async function makeFriendsPlusMessage(
await common.makeFriends(app, [app2, pubkey]); app: Application,
[app2, pubkey]: [Application, string]
) {
await Common.makeFriends(app, [app2, pubkey]);
// Send something back so that `app` can see our name // Send something back so that `app` can see our name
const text = await generateAndSendMessage(app2); const text = await generateAndSendMessage(app2);
@ -43,12 +50,12 @@ async function makeFriendsPlusMessage(app, [app2, pubkey]) {
} }
async function testTwoMembers() { async function testTwoMembers() {
const [app, app2] = await common.startAppsAsFriends(); const [app, app2] = await Common.startAppsAsFriends();
const useSenderKeys = true; const useSenderKeys = true;
// create group and add new friend // create group and add new friend
await common.addFriendToNewClosedGroup([app, app2], useSenderKeys); await Common.addFriendToNewClosedGroup([app, app2], useSenderKeys);
const text1 = await generateAndSendMessage(app); const text1 = await generateAndSendMessage(app);
@ -73,39 +80,39 @@ async function testThreeMembers() {
// 1. Make three clients A, B, C // 1. Make three clients A, B, C
const app1Props = { const app1Props = {
mnemonic: common.TEST_MNEMONIC1, mnemonic: Common.TEST_MNEMONIC1,
displayName: common.TEST_DISPLAY_NAME1, displayName: Common.TEST_DISPLAY_NAME1,
stubSnode: true, stubSnode: true,
}; };
const app2Props = { const app2Props = {
mnemonic: common.TEST_MNEMONIC2, mnemonic: Common.TEST_MNEMONIC2,
displayName: common.TEST_DISPLAY_NAME2, displayName: Common.TEST_DISPLAY_NAME2,
stubSnode: true, stubSnode: true,
}; };
const app3Props = { const app3Props = {
mnemonic: common.TEST_MNEMONIC3, mnemonic: Common.TEST_MNEMONIC3,
displayName: common.TEST_DISPLAY_NAME3, displayName: Common.TEST_DISPLAY_NAME3,
stubSnode: true, stubSnode: true,
}; };
const [app1, app2, app3] = await Promise.all([ const [app1, app2, app3] = await Promise.all([
common.startAndStub(app1Props), Common.startAndStub(app1Props),
common.startAndStubN(app2Props, 2), Common.startAndStubN(app2Props, 2),
common.startAndStubN(app3Props, 3), Common.startAndStubN(app3Props, 3),
]); ]);
// 2. Make A friends with B and C (B and C are not friends) // 2. Make A friends with B and C (B and C are not friends)
await makeFriendsPlusMessage(app1, [app2, common.TEST_PUBKEY2]); await makeFriendsPlusMessage(app1, [app2, Common.TEST_PUBKEY2]);
await makeFriendsPlusMessage(app1, [app3, common.TEST_PUBKEY3]); await makeFriendsPlusMessage(app1, [app3, Common.TEST_PUBKEY3]);
const useSenderKeys = true; const useSenderKeys = true;
// 3. Add all three to the group // 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 // 4. Test that all members can see the message from app1
const text1 = await generateAndSendMessage(app1); const text1 = await generateAndSendMessage(app1);
@ -131,20 +138,16 @@ async function testThreeMembers() {
} }
describe('senderkeys', function() { describe('senderkeys', function() {
let app; this.timeout(60000);
this.slow(20000);
this.timeout(600000);
this.slow(40000);
beforeEach(async () => { beforeEach(async () => {
await common.killallElectron(); await Common.killallElectron();
await common.stopStubSnodeServer(); await Common.stopStubSnodeServer();
}); });
afterEach(async () => { afterEach(async () => {
await common.stopApp(app); await Common.killallElectron();
await common.killallElectron(); await Common.stopStubSnodeServer();
await common.stopStubSnodeServer();
}); });
it('Two member group', testTwoMembers); it('Two member group', testTwoMembers);

@ -1,41 +1,43 @@
/* eslint-disable prefer-destructuring */
/* eslint-disable more/no-then */
/* eslint-disable func-names */
/* eslint-disable import/no-extraneous-dependencies */ /* 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'); import { after, before, describe, it } from 'mocha';
const common = require('./common'); import { Common } from './common';
import { Application } from 'spectron';
const SettingsPage = require('./page-objects/settings.page'); import SettingsPage from './page-objects/settings.page';
const CommonPage = require('./page-objects/common.page'); import CommonPage from './page-objects/common.page';
// Generate random password // Generate random password
// tslint:disable-next-line: insecure-random
const password = Math.random() const password = Math.random()
.toString(36) .toString(36)
.substr(2, 8); .substr(2, 8);
const passwordInputID = 'password-modal-input'; const passwordInputID = 'password-modal-input';
describe('Settings', function() { describe('Settings', function() {
let app;
this.timeout(60000); this.timeout(60000);
this.slow(15000); this.slow(20000);
let app: Application;
before(async () => { before(async () => {
await common.killallElectron(); await Common.killallElectron();
await common.stopStubSnodeServer(); await Common.stopStubSnodeServer();
const appProps = { const appProps = {
mnemonic: common.TEST_MNEMONIC1, mnemonic: Common.TEST_MNEMONIC1,
displayName: common.TEST_DISPLAY_NAME1, displayName: Common.TEST_DISPLAY_NAME1,
}; };
app = await common.startAndStub(appProps); app = await Common.startAndStub(appProps);
}); });
after(async () => { after(async () => {
await common.stopApp(app); await Common.stopApp(app);
await common.killallElectron(); await Common.killallElectron();
await common.stopStubSnodeServer(); await Common.stopStubSnodeServer();
}); });
it('can toggle menubar', async () => { it('can toggle menubar', async () => {
@ -60,12 +62,12 @@ describe('Settings', function() {
.element(SettingsPage.settingButtonWithText('Set Password')) .element(SettingsPage.settingButtonWithText('Set Password'))
.click(); .click();
await common.setValueWrapper( await Common.setValueWrapper(
app, app,
CommonPage.inputWithId(passwordInputID), CommonPage.inputWithId(passwordInputID),
password password
); );
await common.setValueWrapper( await Common.setValueWrapper(
app, app,
CommonPage.inputWithId(`${passwordInputID}-confirm`), CommonPage.inputWithId(`${passwordInputID}-confirm`),
password password
@ -79,12 +81,12 @@ describe('Settings', function() {
2000 2000
); );
await common.closeToast(app); await Common.closeToast(app);
}); });
it('can remove password', async () => { it('can remove password', async () => {
// Enter password to unlock settings // Enter password to unlock settings
await common.setValueWrapper( await Common.setValueWrapper(
app, app,
CommonPage.inputWithId('password-lock-input'), CommonPage.inputWithId('password-lock-input'),
password password
@ -97,7 +99,7 @@ describe('Settings', function() {
.element(SettingsPage.settingButtonWithText('Remove Password')) .element(SettingsPage.settingButtonWithText('Remove Password'))
.click(); .click();
await common.setValueWrapper( await Common.setValueWrapper(
app, app,
CommonPage.inputWithId(passwordInputID), CommonPage.inputWithId(passwordInputID),
password password

@ -1,6 +1,6 @@
/* global clearTimeout, Buffer, TextDecoder, process */ /* 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 = const sampleFeed =
'<?xml version="1.0" encoding="windows-1252"?><rss version="2.0"><channel> <title>FeedForAll Sample Feed</title></channel></rss>'; '<?xml version="1.0" encoding="windows-1252"?><rss version="2.0"><channel> <title>FeedForAll Sample Feed</title></channel></rss>';
@ -69,9 +69,12 @@ const samplesGetMessages = {
], ],
}; };
class StubAppDotNetAPI extends OriginalAppDotNetApi { class StubAppDotNetAPI extends LokiAppDotNetServerAPI {
// make a request to the server // make a request to the server
async serverRequest(endpoint, options = {}) { public async serverRequest(
endpoint: string,
options: { method?: string } = {}
) {
const { method } = options; const { method } = options;
// console.warn('STUBBED ', method, ':', endpoint); // console.warn('STUBBED ', method, ':', endpoint);

@ -1,22 +1,30 @@
/* global clearTimeout, dcodeIO, Buffer, TextDecoder, process */ import { StringUtils } from '../../../../session/utils';
const nodeFetch = require('node-fetch');
import fetch from 'node-fetch';
class StubMessageAPI { class StubMessageAPI {
constructor(ourKey) { public ourKey: string;
public baseUrl: string;
constructor(ourKey: string) {
this.ourKey = ourKey; this.ourKey = ourKey;
this.baseUrl = 'http://localhost:3000'; this.baseUrl = 'http://localhost:3000';
} }
// eslint-disable-next-line no-unused-vars // 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); // console.warn('STUBBED message api ', pubKey, ttl);
const post = { const post = {
method: 'POST', method: 'POST',
}; };
const data64 = dcodeIO.ByteBuffer.wrap(data).toString('base64'); const data64 = StringUtils.decode(data, 'base64');
await fetch(
await nodeFetch(
`${ `${
this.baseUrl this.baseUrl
}/messages?pubkey=${pubKey}&timestamp=${messageTimeStamp}&data=${encodeURIComponent( }/messages?pubkey=${pubKey}&timestamp=${messageTimeStamp}&data=${encodeURIComponent(
Loading…
Cancel
Save