Skip to content

Commit

Permalink
standardized tab sizes, initialized unintall file for robust testing,…
Browse files Browse the repository at this point in the history
… initialized testing
  • Loading branch information
Char1zardd committed Mar 6, 2022
1 parent c6b4c05 commit 991b8db
Show file tree
Hide file tree
Showing 10 changed files with 417 additions and 405 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,5 @@ Plugins/Trading-Signals
tmp/
Superalgos.desktop
.dccache
testfile.js
testfile.js
.vscode
108 changes: 54 additions & 54 deletions .tests/Environment.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,67 +3,67 @@ const path = require("path")

let basePath
if (process.env.PACKAGED_PATH) {
basePath = process.env.PACKAGED_PATH
basePath = process.env.PACKAGED_PATH
} else {
basePath = path.dirname(__dirname)
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'
]
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)
})
it('should contain no new environment variables', () => {
expect(env.newEnvironment()).toEqual(expectedObject)
})
})
130 changes: 65 additions & 65 deletions .tests/Launch-Scripts/createShortcut.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,82 +8,82 @@ const os = require('os')

// base mock for happy path
jest.mock('child_process', () => {
const path = require("path")
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
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
}
})
}
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
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()
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')
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(
"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(
'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 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 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'
)
})
expect(createShortcut()).toEqual(
'Shortcuts not supported on your system'
)
})
})
2 changes: 2 additions & 0 deletions .tests/Launch-Scripts/uninstall.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
const uninstall = require('../../Launch-Scripts/uninstallAll')
const os = require('os')
Loading

0 comments on commit 991b8db

Please sign in to comment.