test-integration make all calls stubbed by default. fix a few bugs with stubbed server

pull/1137/head
Audric Ackermann 5 years ago
parent 3edff1e364
commit 1144609c2a
No known key found for this signature in database
GPG Key ID: 999F434D76324AD4

@ -18,13 +18,11 @@ describe('Add friends', function() {
const app1Props = { const app1Props = {
mnemonic: common.TEST_MNEMONIC1, mnemonic: common.TEST_MNEMONIC1,
displayName: common.TEST_DISPLAY_NAME1, displayName: common.TEST_DISPLAY_NAME1,
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,
}; };
[app, app2] = await Promise.all([ [app, app2] = await Promise.all([

@ -184,20 +184,11 @@ module.exports = {
async startAndStub({ async startAndStub({
mnemonic, mnemonic,
displayName, displayName,
stubSnode = false,
stubOpenGroups = false,
env = 'test-integration-session', env = 'test-integration-session',
}) { }) {
const app = await this.startAndAssureCleanedApp(env); const app = await this.startAndAssureCleanedApp(env);
if (stubSnode) { await this.startStubSnodeServer();
await this.startStubSnodeServer();
this.stubSnodeCalls(app);
}
if (stubOpenGroups) {
this.stubOpenGroupsCalls(app);
}
if (mnemonic && displayName) { if (mnemonic && displayName) {
await this.restoreFromMnemonic(app, mnemonic, displayName); await this.restoreFromMnemonic(app, mnemonic, displayName);
@ -246,13 +237,11 @@ module.exports = {
const app1Props = { const app1Props = {
mnemonic: this.TEST_MNEMONIC1, mnemonic: this.TEST_MNEMONIC1,
displayName: this.TEST_DISPLAY_NAME1, displayName: this.TEST_DISPLAY_NAME1,
stubSnode: true,
}; };
const app2Props = { const app2Props = {
mnemonic: this.TEST_MNEMONIC2, mnemonic: this.TEST_MNEMONIC2,
displayName: this.TEST_DISPLAY_NAME2, displayName: this.TEST_DISPLAY_NAME2,
stubSnode: true,
}; };
const [app1, app2] = await Promise.all([ const [app1, app2] = await Promise.all([
@ -469,9 +458,9 @@ module.exports = {
await app2.client.isExisting(RegistrationPage.conversationListContainer) await app2.client.isExisting(RegistrationPage.conversationListContainer)
.should.eventually.be.true; .should.eventually.be.true;
await app1.client.element(ConversationPage.settingsButtonSection).click(); await app1.client.element(SettingsPage.settingsButtonSection).click();
await app1.client await app1.client
.element(ConversationPage.settingsRowWithText('Devices')) .element(SettingsPage.settingsRowWithText('Devices'))
.click(); .click();
await app1.client.isExisting(ConversationPage.linkDeviceButtonDisabled) await app1.client.isExisting(ConversationPage.linkDeviceButtonDisabled)
.should.eventually.be.true; .should.eventually.be.true;
@ -536,17 +525,6 @@ module.exports = {
generateSendMessageText: () => generateSendMessageText: () =>
`Test message from integration tests ${Date.now()}`, `Test message from integration tests ${Date.now()}`,
stubOpenGroupsCalls: app1 => {
app1.webContents.executeJavaScript(
'window.LokiAppDotNetServerAPI = window.StubAppDotNetAPI;'
);
},
stubSnodeCalls(app1) {
app1.webContents.executeJavaScript(
'window.LokiMessageAPI = window.StubMessageAPI;'
);
},
async startStubSnodeServer() { async startStubSnodeServer() {
if (!this.stubSnode) { if (!this.stubSnode) {
@ -568,7 +546,7 @@ module.exports = {
this.messages[pubkey] = [...ori, { data, timestamp }]; this.messages[pubkey] = [...ori, { data, timestamp }];
response.writeHead(200, { 'Content-Type': 'text/html' }); response.writeHead(200, { 'Content-Type': 'application/json' });
response.end(); response.end();
} else { } else {
const messages = this.messages[pubkey] || []; const messages = this.messages[pubkey] || [];
@ -576,11 +554,11 @@ module.exports = {
if (ENABLE_LOG) { if (ENABLE_LOG) {
console.warn('GET for', pubkey, retrievedMessages); console.warn('GET for', pubkey, retrievedMessages);
} }
if (this.messages[pubkey]) { response.writeHead(200, { 'Content-Type': 'application/json' });
response.writeHead(200, { 'Content-Type': 'application/json' });
response.write(JSON.stringify(retrievedMessages)); response.write(JSON.stringify(retrievedMessages));
this.messages[pubkey] = []; this.messages[pubkey] = [];
}
response.end(); response.end();
} }
} }

@ -18,11 +18,9 @@ describe('Link Device', function() {
const app1Props = { const app1Props = {
mnemonic: common.TEST_MNEMONIC1, mnemonic: common.TEST_MNEMONIC1,
displayName: common.TEST_DISPLAY_NAME1, displayName: common.TEST_DISPLAY_NAME1,
stubSnode: true,
}; };
const app2Props = { const app2Props = {
stubSnode: true,
}; };
[app, app2] = await Promise.all([ [app, app2] = await Promise.all([
@ -68,8 +66,8 @@ describe('Link Device', function() {
); );
// no friends, no closed groups, no open groups. we should see those message sync in the log // no friends, no closed groups, no open groups. we should see those message sync in the log
await common.logsContains(primaryRenderLogs, 'No closed group to sync.'); await common.logsContains(primaryRenderLogs, 'No closed group to sync.', 1);
await common.logsContains(primaryRenderLogs, 'No open groups to sync'); await common.logsContains(primaryRenderLogs, 'No open groups to sync', 1);
await common.logsContains(primaryRenderLogs, 'No contacts to sync.'); await common.logsContains(primaryRenderLogs, 'No contacts to sync.', 1);
}); });
}); });

@ -15,7 +15,6 @@ describe('Open groups', function() {
const login = { const login = {
mnemonic: common.TEST_MNEMONIC1, mnemonic: common.TEST_MNEMONIC1,
displayName: common.TEST_DISPLAY_NAME1, displayName: common.TEST_DISPLAY_NAME1,
stubOpenGroups: true,
}; };
app = await common.startAndStub(login); app = await common.startAndStub(login);
}); });

@ -5,6 +5,7 @@
const { afterEach, beforeEach, describe, it } = require('mocha'); const { afterEach, beforeEach, describe, it } = require('mocha');
const common = require('./common'); const common = require('./common');
const SettingsPage = require('./page-objects/settings.page');
const RegistrationPage = require('./page-objects/registration.page'); const RegistrationPage = require('./page-objects/registration.page');
const ConversationPage = require('./page-objects/conversation.page'); const ConversationPage = require('./page-objects/conversation.page');
@ -104,7 +105,6 @@ describe('Window Test and Login', function() {
const login = { const login = {
mnemonic: common.TEST_MNEMONIC1, mnemonic: common.TEST_MNEMONIC1,
displayName: common.TEST_DISPLAY_NAME1, displayName: common.TEST_DISPLAY_NAME1,
stubOpenGroups: true,
}; };
app = await common.startAndStub(login); app = await common.startAndStub(login);
@ -117,7 +117,7 @@ describe('Window Test and Login', function() {
.executeJavaScript("window.storage.get('primaryDevicePubKey')") .executeJavaScript("window.storage.get('primaryDevicePubKey')")
.should.eventually.be.equal(common.TEST_PUBKEY1); .should.eventually.be.equal(common.TEST_PUBKEY1);
// delete account // delete account
await app.client.element(ConversationPage.settingsButtonSection).click(); await app.client.element(SettingsPage.settingsButtonSection).click();
await app.client.element(ConversationPage.deleteAccountButton).click(); await app.client.element(ConversationPage.deleteAccountButton).click();
await app.client.isExisting(ConversationPage.descriptionDeleteAccount) await app.client.isExisting(ConversationPage.descriptionDeleteAccount)
.should.eventually.be.true; .should.eventually.be.true;

@ -27,7 +27,6 @@ describe('Settings', function() {
const appProps = { const appProps = {
mnemonic: common.TEST_MNEMONIC1, mnemonic: common.TEST_MNEMONIC1,
displayName: common.TEST_DISPLAY_NAME1, displayName: common.TEST_DISPLAY_NAME1,
stubSnode: true,
}; };
app = await common.startAndStub(appProps); app = await common.startAndStub(appProps);

@ -0,0 +1,10 @@
/* eslint-disable class-methods-use-this */
class StubSnodeAPI {
async refreshSwarmNodesForPubKey() {
return [];
}
}
module.exports = StubSnodeAPI;

@ -59,7 +59,7 @@ function MessageReceiver(username, password, signalingKey, options = {}) {
openGroupBound = true; openGroupBound = true;
} }
} else { } else {
window.log.error('Can not handle open group data, API is not available'); window.log.warn('Can not handle open group data, API is not available');
} }
} }

@ -324,15 +324,32 @@ window.lokiSnodeAPI = new LokiSnodeAPI({
localUrl: config.localUrl, localUrl: config.localUrl,
}); });
window.LokiMessageAPI = require('./js/modules/loki_message_api');
if (process.env.USE_STUBBED_NETWORK) { if (process.env.USE_STUBBED_NETWORK) {
window.StubMessageAPI = require('./integration_test/stubs/stub_message_api'); const StubMessageAPI = require('./integration_test/stubs/stub_message_api');
window.StubAppDotNetApi = require('./integration_test/stubs/stub_app_dot_net_api'); window.LokiMessageAPI = StubMessageAPI;
const StubAppDotNetAPI = require('./integration_test/stubs/stub_app_dot_net_api');
window.LokiAppDotNetServerAPI = StubAppDotNetAPI;
const StubSnodeAPI = require('./integration_test/stubs/stub_snode_api');
window.lokiSnodeAPI = new StubSnodeAPI({
serverUrl: config.serverUrl,
localUrl: config.localUrl,
});
} else {
window.lokiSnodeAPI = new LokiSnodeAPI({
serverUrl: config.serverUrl,
localUrl: config.localUrl,
});
window.LokiMessageAPI = require('./js/modules/loki_message_api');
window.LokiAppDotNetServerAPI = require('./js/modules/loki_app_dot_net_api');
} }
window.LokiPublicChatAPI = require('./js/modules/loki_public_chat_api'); window.LokiPublicChatAPI = require('./js/modules/loki_public_chat_api');
window.LokiAppDotNetServerAPI = require('./js/modules/loki_app_dot_net_api');
window.LokiFileServerAPI = require('./js/modules/loki_file_server_api'); window.LokiFileServerAPI = require('./js/modules/loki_file_server_api');
@ -427,7 +444,8 @@ Promise.prototype.ignore = function() {
if ( if (
config.environment.includes('test') && config.environment.includes('test') &&
!config.environment.includes('swarm-testing') !config.environment.includes('swarm-testing') &&
!config.environment.includes('test-integration')
) { ) {
const isWindows = process.platform === 'win32'; const isWindows = process.platform === 'win32';
/* eslint-disable global-require, import/no-extraneous-dependencies */ /* eslint-disable global-require, import/no-extraneous-dependencies */
@ -449,5 +467,6 @@ if (config.environment.includes('test-integration')) {
multiDeviceUnpairing: true, multiDeviceUnpairing: true,
privateGroupChats: true, privateGroupChats: true,
useSnodeProxy: !process.env.USE_STUBBED_NETWORK, useSnodeProxy: !process.env.USE_STUBBED_NETWORK,
useOnionRequests: false,
}; };
} }

Loading…
Cancel
Save