You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
session-desktop/integration_test/stubs/stub_app_dot_net_api.js

167 lines
3.7 KiB
JavaScript

Integration tests (#975) * add first integration test Session Checking window title Checking window count Can restore from seed * FIXME torevert once found why this crash on app close * [test] add join valid open group test * [test] validate cannot join two times the same open group * [test] move common things to common.js * [test] move tests to separate files * [test] clean * [test] add send message to open group test * [test] lint * [test] rename hooks -> common * [test] add 15s delay before considering test as slow * upgrade electron 8.0.3 and spectron 10.0.0 * [test] signin from seed: validate pubkey * Replace spellchecker in favor of typo-js * [test] refactor common calls to common.js * [test] add two different pubkey, mnemonic and displayname * [test] FIXME unsafe eval needed for now * [test] add: add friends test * [test] working multi instance tests * [test] FIXME disable snodeproxy * [test] update yarn.lock * [test] make tests more robust with restart from scratch each test * [test] add link of two devices test and hard rm of apps before start (rm -r) * remove unused file * [test] lint * [test] add registration from generated pubkey test * [test] add beginning of network stub * [test] stub "token" endpoint * [test] add test of one message on pub group pull * [test] add starting port randomize. looks to help for some bad start with multi instance * [test] add stub for one to one chats (sessions) * [test] clean code * [test] finish add friend test and stub snode server * [test] stub calls during link device test * [test] add a flag to show some logs on stubbed snode * [test] finish link of two device test. check both pubkey matches * [test] add and use function to wrap erase+start+login+stub app * [test] add method to login as friend and closed group test&messages * Revert "[test] FIXME unsafe eval needed for now" This reverts commit de5322fdae6cdab8e3b9bd9a52b7d172c9bc2d26. * [test] apply review * [test] fix lint * [test] fix existing test with new spectron version * [test] fix lint * [test] refactor page objects * [test] add delete account test * [test] add unlink of two device test * [test] make tiny waitForExists -> isExisting * [test] add checks of link new device buttons * upgrade fs-extra@9.0.0 * address pr review * [test] fix spell_check test Co-authored-by: Josh Perez <60019601+josh-signal@users.noreply.github.com>
5 years ago
/* global clearTimeout, Buffer, TextDecoder, process */
const OriginalAppDotNetApi = require('../../js/modules/loki_app_dot_net_api.js');
const sampleFeed =
'<?xml version="1.0" encoding="windows-1252"?><rss version="2.0"><channel> <title>FeedForAll Sample Feed</title></channel></rss>';
const samplesGetMessages = {
meta: { code: 200 },
data: [
{
channel_id: 1,
created_at: '2020-03-18T04:48:44.000Z',
entities: {
mentions: [],
hashtags: [],
links: [],
},
id: 3662,
machine_only: false,
num_replies: 0,
source: {},
thread_id: 3662,
reply_to: null,
text: 'hgt',
html: '<span itemscope="https://app.net/schemas/Post">hgt</span>',
annotations: [
{
type: 'network.loki.messenger.publicChat',
value: {
timestamp: 1584506921361,
sig:
'262ab113810564d7ff6474dea264e10e2143d91c004903d06d8d9fddb5b74b2c6245865544d5cf76ee16a3fca045bc028a48c51f8a290508a29b6013d014dc83',
sigver: 1,
},
},
],
user: {
id: 2448,
username:
'050cd79763303bcc251bd489a6f7da823a2b8555402b01a7959ebca550d048600f',
created_at: '2020-03-18T02:42:05.000Z',
canonical_url: null,
type: null,
timezone: null,
locale: null,
avatar_image: {
url: null,
width: null,
height: null,
is_default: false,
},
cover_image: {
url: null,
width: null,
height: null,
is_default: false,
},
counts: {
following: 0,
posts: 0,
followers: 0,
stars: 0,
},
name: 'asdf',
annotations: [],
},
},
],
};
class StubAppDotNetAPI extends OriginalAppDotNetApi {
// make a request to the server
async serverRequest(endpoint, options = {}) {
const { method } = options;
// console.warn('STUBBED ', method, ':', endpoint);
if (
endpoint === 'loki/v1/rss/messenger' ||
endpoint === 'loki/v1/rss/loki'
) {
return {
statusCode: 200,
response: {
data: sampleFeed,
},
};
}
if (endpoint === 'channels/1/messages') {
if (!method) {
return {
statusCode: 200,
response: samplesGetMessages,
};
}
return {
statusCode: 200,
response: {
data: [],
meta: {
max_id: 0,
},
},
};
}
if (
endpoint === 'loki/v1/channel/1/deletes' ||
endpoint === 'loki/v1/channel/1/moderators'
) {
return {
statusCode: 200,
response: {
data: [],
meta: {
max_id: 0,
},
},
};
}
if (endpoint === 'channels/1') {
let name = 'Unknown group';
if (this.baseServerUrl.includes('/chat-dev.lokinet.org')) {
name = 'Loki Dev Chat';
} else if (this.baseServerUrl.includes('/chat.getsession.org')) {
name = 'Session Public Chat';
}
return {
statusCode: 200,
response: {
data: {
annotations: [
{
type: 'net.patter-app.settings',
value: {
name,
},
},
],
},
},
};
}
if (endpoint === 'token') {
return {
statusCode: 200,
response: {
data: {
user: {
name: 'unknown name',
},
},
},
};
}
return {
statusCode: 200,
response: {},
};
}
}
module.exports = StubAppDotNetAPI;