forked from Superalgos/Superalgos
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request Superalgos#3997 from Superalgos/develop
merge develop into master
- Loading branch information
Showing
845 changed files
with
38,820 additions
and
9,993 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
node_modules | ||
package-lock.json | ||
package.json | ||
*.desktop |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
"env": { | ||
"node": true, | ||
"commonjs": true, | ||
"es2021": true | ||
}, | ||
"extends": "eslint:recommended", | ||
"parserOptions": { | ||
"ecmaVersion": "latest" | ||
}, | ||
"rules": { | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
#!/bin/sh | ||
. "$(dirname "$0")/_/husky.sh" | ||
|
||
npm run unitTest |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
const getRemotesResponse = [ | ||
{ | ||
name: 'origin', | ||
refs: { | ||
fetch: 'https://github.com/contributor/Superalgos', | ||
push: 'https://github.com/contributor/Superalgos' | ||
} | ||
}, | ||
{ | ||
name: 'upstream', | ||
refs: { | ||
fetch: 'https://github.com/Superalgos/Superalgos', | ||
push: 'https://github.com/Superalgos/Superalgos' | ||
} | ||
} | ||
] | ||
|
||
const branchLocalResponse = { | ||
all: [ 'develop', 'master' ], | ||
branches: { | ||
develop: { | ||
current: true, | ||
name: 'develop', | ||
commit: 'eb9999999', | ||
label: "the latest commit message" | ||
}, | ||
master: { | ||
current: false, | ||
name: 'master', | ||
commit: '0afffffff', | ||
label: '[behind 9999] Merge pull request #9999 from contributor/branch' | ||
} | ||
}, | ||
current: 'develop', | ||
detached: false | ||
} | ||
|
||
const removeRemoteResponse = { | ||
removed: 'https://github.com/contributor/Superalgos/branch' | ||
} | ||
|
||
module.exports = { | ||
getRemotesResponse, | ||
branchLocalResponse, | ||
removeRemoteResponse | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
const env = require("../Environment") | ||
const path = require("path") | ||
|
||
let basePath | ||
if (process.env.PACKAGED_PATH) { | ||
basePath = process.env.PACKAGED_PATH | ||
} else { | ||
basePath = path.dirname(__dirname) | ||
} | ||
|
||
const projectPluginMap = require(path.join(basePath, 'Plugins/project-plugin-map.json')) | ||
|
||
const expectedObject = { | ||
DEMO_MODE: false, | ||
DEMO_MODE_HOST: "super-super-uzzdd68dwm9w-22a320db4ede63aa.elb.us-east-2.amazonaws.com", | ||
BASE_PATH: basePath, | ||
WEB_SERVER_URL: 'localhost', | ||
PLATFORM_WEB_SOCKETS_INTERFACE_PORT: 18041, | ||
NETWORK_WEB_SOCKETS_INTERFACE_PORT: 17041, | ||
DESKTOP_WEB_SOCKETS_INTERFACE_PORT: 16041, | ||
DESKTOP_WEB_SOCKETS_INTERFACE_HOST: 'localhost', | ||
PLATFORM_HTTP_INTERFACE_PORT: 34248, | ||
DESKTOP_HTTP_INTERFACE_PORT: 33248, | ||
NETWORK_HTTP_INTERFACE_PORT: 31248, | ||
PATH_TO_DATA_STORAGE: path.join(basePath, './Platform/My-Data-Storage'), | ||
PATH_TO_PROJECTS: path.join(basePath, './Projects'), | ||
PATH_TO_PLUGINS: path.join(basePath, './Plugins'), | ||
PROJECT_PLUGIN_MAP: projectPluginMap, | ||
PATH_TO_LOG_FILES: path.join(basePath, './Platform/My-Log-Files'), | ||
PATH_TO_PROJECTS_REQUIRED: path.join(basePath, './Projects'), | ||
PATH_TO_PROJECT_SCHEMA: path.join(basePath, './Projects/ProjectsSchema.json'), | ||
PATH_TO_PLATFORM: path.join(basePath, './Platform'), | ||
PATH_TO_DESKTOP: './Desktop', | ||
PATH_TO_DEFAULT_WORKSPACE: path.join(basePath, './Plugins/Foundations/Workspaces'), | ||
PATH_TO_MY_WORKSPACES: path.join(basePath, './Platform/My-Workspaces'), | ||
PATH_TO_SECRETS: path.join(basePath, './My-Secrets'), | ||
PATH_TO_FONTS: path.join(basePath, './Platform/WebServer/Fonts'), | ||
DESKTOP_APP_SIGNING_ACCOUNT: 'Social-Trading-Desktop-App-1', | ||
DESKTOP_APP_MAX_OUTGOING_PEERS: 1, | ||
DESKTOP_APP_MAX_OUTGOING_START_PEERS: 0, | ||
TASK_SERVER_APP_MAX_OUTGOING_PEERS: 1, | ||
TASK_SERVER_APP_MAX_OUTGOING_START_PEERS: 1, | ||
MOBILE_APP_SIGNING_ACCOUNT: 'Social-Trading-Mobile-App-1', | ||
SERVER_APP_SIGNING_ACCOUNT: 'Social-Trading-Server-App-1', | ||
PLATFORM_APP_SIGNING_ACCOUNT: 'Algo-Traders-Platform-1', | ||
P2P_NETWORK_NODE_SIGNING_ACCOUNT: 'P2P-Network-Node-1', | ||
P2P_NETWORK_NODE_MAX_INCOMING_CLIENTS: 2, | ||
P2P_NETWORK_NODE_MAX_INCOMING_PEERS: 0, | ||
P2P_NETWORK_NODE_MAX_OUTGOING_PEERS: 0, | ||
DESKTOP_TARGET_NETWORK_TYPE: 'P2P Network', | ||
DESKTOP_TARGET_NETWORK_CODENAME: 'Testnet', | ||
TASK_SERVER_TARGET_NETWORK_TYPE: 'P2P Network', | ||
TASK_SERVER_TARGET_NETWORK_CODENAME: 'Testnet', | ||
DESKTOP_DEFAULT_SOCIAL_PERSONA: 'Social-Persona-1', | ||
DESKTOP_DEFAULT_SOCIAL_TRADING_BOT: 'Social-Trading-Bot-1', | ||
NPM_NEEDED_VERSION: '5', | ||
NODE_NEEDED_VERSION: '12', | ||
GIT_NEEDED_VERSION: '2', | ||
EXTERNAL_SCRIPTS: [ | ||
'https://code.jquery.com/jquery-3.6.0.js', | ||
'https://code.jquery.com/ui/1.13.0/jquery-ui.js' | ||
] | ||
} | ||
|
||
describe('newEnvironment', () => { | ||
it('should contain no new environment variables', () => { | ||
expect(env.newEnvironment()).toEqual(expectedObject) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
const createShortcut = require('../../Launch-Scripts/createShortcut') | ||
const os = require('os') | ||
|
||
// ****** IMPORTANT NOTE ****** | ||
// unless strictly necessary, do not use mockReturnValueOnce and instead | ||
// use mockReturnValue. otherwise when you are console.logging or calling it | ||
// anywhere else and your test depends on it, the test will fail!!! | ||
|
||
// base mock for happy path | ||
jest.mock('child_process', () => { | ||
const path = require("path") | ||
|
||
let cwd = '/this/path' | ||
let dir = cwd.split(path.sep) | ||
let target = path.join('root/path', "launch-windows.bat") | ||
let icon = path.join('root/path', "superalgos.ico") | ||
let name = dir[dir.length - 2] | ||
return { | ||
// assuming exit code 0 is success | ||
execSync: jest.fn((command) => { | ||
if (command === `$ws = New-Object -ComObject WScript.Shell; $s = $ws.CreateShortcut("${dir}"); $S.TargetPath = "${target}"; $S.IconLocation = "${icon}"; $S.Save()`) { | ||
return 0 | ||
} | ||
if (command === `cp ${name}.desktop ~/Desktop/${name}.desktop & cp ${name}.desktop ~/.local/share/applications/${name}.desktop`) { | ||
return 0 | ||
} | ||
if (command === `chmod +x ${name}.command & cp ${name}.command ~/Desktop/${name}.command`) { | ||
return 0 | ||
} | ||
if (command === `npm install -g fileicon`) { | ||
return 0 | ||
} | ||
if (command === `./node_modules/fileicon/bin/fileicon set ~/Desktop/${name}.command ./Launch-Scripts/superalgos.ico`) { | ||
return 0 | ||
} | ||
if (command === `npm uninstall -g fileicon`) { | ||
return 0 | ||
} | ||
}) | ||
} | ||
}) | ||
|
||
jest.createMockFromModule('fs') | ||
|
||
afterEach(() => { | ||
jest.clearAllMocks() | ||
}) | ||
|
||
describe('createShortcut()', () => { | ||
it('should create a new shortcut for windows system', () => { | ||
jest.spyOn(os, 'platform').mockReturnValue('win32') | ||
jest.spyOn(os, 'version').mockReturnValue('10') | ||
|
||
expect(createShortcut()).toEqual( | ||
"Shortcuts created for windows system" | ||
) | ||
}) | ||
it('should warn shortcuts not supported on non-ubuntu linux', () => { | ||
jest.spyOn(os, 'platform').mockReturnValue('linux') | ||
jest.spyOn(os, 'version').mockReturnValue('Fedora') | ||
|
||
expect(createShortcut()).toEqual( | ||
'Linux shortcuts supported for Ubuntu only' | ||
) | ||
}) | ||
it('should create shortcuts for ubuntu system', () => { | ||
jest.spyOn(os, 'platform').mockReturnValue('linux') | ||
jest.spyOn(os, 'version').mockReturnValue('Ubuntu') | ||
|
||
expect(createShortcut()).toEqual( | ||
"Shortcuts created for Ubuntu" | ||
) | ||
}) | ||
it('should create shortcuts and run all commands on darwin', () => { | ||
jest.spyOn(os, 'platform').mockReturnValue('darwin') | ||
|
||
expect(createShortcut()).toEqual( | ||
"Shortcuts created for Mac" | ||
) | ||
}) | ||
it('should warn shortcuts not supported on non-darwin, non-linux, non-win32', () => { | ||
jest.spyOn(os, 'platform').mockReturnValue('windows95') | ||
jest.spyOn(os, 'version').mockReturnValue('95') | ||
|
||
expect(createShortcut()).toEqual( | ||
'Shortcuts not supported on your system' | ||
) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
const os = require('os') | ||
const child_process = require('child_process') | ||
|
||
const { | ||
fatalErrorHelp, | ||
runPlatform | ||
} = require('../../Launch-Scripts/runPlatform') | ||
|
||
jest.mock('fs', () => { | ||
return { | ||
existsSync: jest.fn(() => true) | ||
} | ||
}) | ||
|
||
jest.mock('child_process', () => { | ||
return { | ||
fork: jest.fn((dir, args, options) => false) | ||
} | ||
}) | ||
|
||
afterEach(() => { | ||
jest.clearAllMocks() | ||
}) | ||
|
||
describe ('fatalErrorHelp()', () => { | ||
it('should return an error', () => { | ||
expect(fatalErrorHelp()).toEqual('fatal error help message displayed') | ||
}) | ||
}) | ||
|
||
describe('runPlatform()', () => { | ||
it('should run the client when no errors', () => { | ||
jest.spyOn(os, 'totalmem').mockReturnValue(8148832256) | ||
|
||
expect(runPlatform()).toEqual('client running') | ||
}) | ||
it('should display help message when command line args like \'-h\'', () => { | ||
process.argv.push('-h') | ||
|
||
expect(runPlatform()).toEqual('help message has been displayed') | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
const nock = require('nock') | ||
const simpleGit = require('simple-git') | ||
const process = require('process') | ||
const env = require('../../Environment').newEnvironment() | ||
const externalScriptsURLs = env.EXTERNAL_SCRIPTS | ||
const { | ||
getRemotesResponse, | ||
branchLocalResponse, | ||
removeRemoteResponse | ||
} = require('../../.mocks/simple-git') | ||
const { | ||
setUpstreamAndOrigin, | ||
runSetup, | ||
installExternalScripts, | ||
errorResp | ||
} = require('../../Launch-Scripts/runSetup') | ||
|
||
// ****** VERY IMPORTANT NOTE ******* | ||
// when your node module has a special character | ||
// like '-' in it, you cannot mock it like this: | ||
// jest.mock('simple-git', () => { | ||
// return { ..... } | ||
// }) | ||
// | ||
// THIS WILL NOT WORK and will break your tests, you must mock it as seen | ||
// below | ||
jest.mock('simple-git') | ||
simpleGit.mockReturnValue({ | ||
getRemotes: jest.fn(() => { | ||
return { | ||
catch: jest.fn(() => getRemotesResponse) | ||
} | ||
}), | ||
addRemote: jest.fn(() => { | ||
return 'done' | ||
}), | ||
branchLocal: jest.fn(() => { | ||
return { | ||
catch: jest.fn(() => branchLocalResponse) | ||
} | ||
}), | ||
checkout: jest.fn(() => { | ||
return {} | ||
}), | ||
removeRemote: jest.fn(() => { | ||
return { | ||
catch: jest.fn(() => removeRemoteResponse) | ||
} | ||
}) | ||
}) | ||
|
||
jest.mock('process', () => { | ||
return { | ||
cwd: jest.fn(() => './'), | ||
exit: jest.fn(() => 'there was an error') | ||
} | ||
}) | ||
|
||
jest.mock('child_process', () => { | ||
return { | ||
exec: jest.fn((command, dir) => { | ||
if (command.includes('echo Results of install at')) { | ||
return 1 | ||
} else { | ||
return 0 | ||
} | ||
}) | ||
} | ||
}) | ||
|
||
for (let i = 0; i< externalScriptsURLs.length; i++) { | ||
nock(externalScriptsURLs[i]) | ||
.get('') | ||
.reply(200, 'successfully mocked') | ||
} | ||
|
||
afterEach(() => { | ||
jest.clearAllMocks() | ||
nock.restore() | ||
}) | ||
|
||
describe('errorResp()', () => { | ||
it('should exit if error caught', () => { | ||
const mockExit = jest.spyOn(process, 'exit').mockImplementation(() => {}) | ||
errorResp('there was an error') | ||
|
||
expect(mockExit).toHaveBeenCalledWith() | ||
}) | ||
}) | ||
describe('setUpstreamAndOrigin()', () => { | ||
it('should return success msg if github is setup correctly', async () => { | ||
const resp = await setUpstreamAndOrigin('./') | ||
|
||
expect(resp).toEqual('Set upstream and origin for github') | ||
}) | ||
}) | ||
describe('installExternalScripts()', () => { | ||
// TODO: figure out how to properly mock createWriteStream | ||
it('should install all external scripts to disk', async () => { | ||
expect(installExternalScripts()).toEqual('External scripts installed') | ||
}) | ||
}) | ||
describe('runSetup()', () => { | ||
it('should return success message if setup completes properly', () => { | ||
expect(runSetup()).toEqual('Setup complete') | ||
}) | ||
}) |
Oops, something went wrong.