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

This commit is contained in:
Audric Ackermann 2020-05-14 14:42:38 +10:00
parent 3edff1e364
commit 1144609c2a
No known key found for this signature in database
GPG key ID: 999F434D76324AD4
9 changed files with 49 additions and 48 deletions

View file

@ -18,13 +18,11 @@ describe('Add friends', function() {
const app1Props = {
mnemonic: common.TEST_MNEMONIC1,
displayName: common.TEST_DISPLAY_NAME1,
stubSnode: true,
};
const app2Props = {
mnemonic: common.TEST_MNEMONIC2,
displayName: common.TEST_DISPLAY_NAME2,
stubSnode: true,
};
[app, app2] = await Promise.all([

View file

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

View file

@ -18,11 +18,9 @@ describe('Link Device', function() {
const app1Props = {
mnemonic: common.TEST_MNEMONIC1,
displayName: common.TEST_DISPLAY_NAME1,
stubSnode: true,
};
const app2Props = {
stubSnode: true,
};
[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
await common.logsContains(primaryRenderLogs, 'No closed group to sync.');
await common.logsContains(primaryRenderLogs, 'No open groups to sync');
await common.logsContains(primaryRenderLogs, 'No contacts to sync.');
await common.logsContains(primaryRenderLogs, 'No closed group to sync.', 1);
await common.logsContains(primaryRenderLogs, 'No open groups to sync', 1);
await common.logsContains(primaryRenderLogs, 'No contacts to sync.', 1);
});
});

View file

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

View file

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

View file

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

View file

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

View file

@ -59,7 +59,7 @@ function MessageReceiver(username, password, signalingKey, options = {}) {
openGroupBound = true;
}
} 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');
}
}

View file

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