Skip to content

Commit

Permalink
Merge 780563f into 4ba65f4
Browse files Browse the repository at this point in the history
  • Loading branch information
Justin Wilaby committed Oct 23, 2018
2 parents 4ba65f4 + 780563f commit f355d52
Show file tree
Hide file tree
Showing 18 changed files with 310 additions and 243 deletions.
98 changes: 49 additions & 49 deletions packages/app/main/src/commands/clientInitCommands.spec.ts
Expand Up @@ -3,7 +3,6 @@ import { BotConfigWithPathImpl, CommandRegistryImpl } from '@bfemulator/sdk-shar
import { bot } from '../botData/reducers/bot';
import * as store from '../botData/store';
import { mainWindow } from '../main';
import { getStore } from '../settingsData/store';
import { registerCommands } from './clientInitCommands';
import { combineReducers, createStore } from 'redux';
import reducers from '../settingsData/reducers';
Expand All @@ -13,13 +12,13 @@ const mockCreateStore = () => createStore(reducers);
const mockSettingsImpl = SettingsImpl;
jest.mock('../settingsData/store', () => ({
getStore: function () {
return mockSettingsStore || (mockSettingsStore = mockCreateStore())
return mockSettingsStore || (mockSettingsStore = mockCreateStore());
},
getSettings: function () {
return new mockSettingsImpl(mockSettingsStore.getState());
},
get dispatch() {
return mockSettingsStore.dispatch
return mockSettingsStore.dispatch;
}
}));

Expand Down Expand Up @@ -55,16 +54,16 @@ jest.mock('electron', () => ({
jest.mock('mkdirp', () => ({
sync: () => void(0)
}));
const mockReadFileSyncResponses = ['{"bots":[]}', '[]'];
const mockReadFileSyncResponses = [`{"bots":[]}`, '[]'];
jest.mock('../utils/readFileSync', () => ({
readFileSync: (file) => {
if (file.includes('.transcript')) {
return '[]';
}
if (file.includes('bots.json')) {
return '{"bots":[]}'
return `{"bots":[]}`;
}
mockReadFileSyncResponses.shift()
return mockReadFileSyncResponses.shift();
}
}));

Expand Down Expand Up @@ -104,12 +103,12 @@ describe('The clientInitCommands', () => {
};

await command();
expect(localCommandArgs).toEqual([["electron:set-title-bar"], ["electron:set-fullscreen", false]]);
expect(remoteCommandArgs).toEqual([["receive-global-settings", {
"cwd": jasmine.any(String),
"locale": "",
"serverUrl": "http://localhost:3000",
"users": {}
expect(localCommandArgs).toEqual([['electron:set-title-bar'], ['electron:set-fullscreen', false]]);
expect(remoteCommandArgs).toEqual([['receive-global-settings', {
'cwd': jasmine.any(String),
'locale': '',
'serverUrl': 'http://localhost:3000',
'users': {}
}]]);
});

Expand All @@ -121,11 +120,11 @@ describe('The clientInitCommands', () => {
remoteCommandArgs.push(args);
};
await command();
expect(remoteCommandArgs).toEqual([["receive-global-settings", {
"cwd": jasmine.any(String),
"locale": "",
"serverUrl": "http://localhost:3000",
"users": {}
expect(remoteCommandArgs).toEqual([['receive-global-settings', {
'cwd': jasmine.any(String),
'locale': '',
'serverUrl': 'http://localhost:3000',
'users': {}
}]]);
});

Expand Down Expand Up @@ -156,51 +155,52 @@ describe('The clientInitCommands', () => {
remoteCommandArgs.push(args);
};

(mainWindow.commandService as any).call = (...args) => {
(mainWindow.commandService as any).call = (...args: any[]) => {
localCommandArgs.push(args);
if (args[0] === SharedConstants.Commands.Bot.Open) {
return mockBot;
}
return null;
};

const command = registry.getCommand(SharedConstants.Commands.ClientInit.PostWelcomeScreen).handler;
await command();
expect(localCommandArgs).toEqual([
["menu:update-file-menu"], ["bot:open", "pathtobot.bot", undefined], ["bot:set-active", {
"description": "",
"name": "AuthBot",
"overrides": null,
"padlock": "",
"path": "some/path",
"services": [{
"appId": "4f8fde3f-48d3-4d8a-a954-393efe39809e",
"appPassword": "REDACTED",
"endpoint": "http://localhost:55697/api/messages",
"id": "cded37c0-83f2-11e8-ac6d-b7172cd24b28",
"name": "authsample",
"type": "endpoint"
['menu:update-file-menu'], ['bot:open', 'pathtobot.bot', undefined], ['bot:set-active', {
'description': '',
'name': 'AuthBot',
'overrides': null,
'padlock': '',
'path': 'some/path',
'services': [{
'appId': '4f8fde3f-48d3-4d8a-a954-393efe39809e',
'appPassword': 'REDACTED',
'endpoint': 'http://localhost:55697/api/messages',
'id': 'cded37c0-83f2-11e8-ac6d-b7172cd24b28',
'name': 'authsample',
'type': 'endpoint'
}],
"version": "2.0"
'version': '2.0'
}]]);

expect(remoteCommandArgs).toEqual([["transcript:open", "deepLinkedTranscript", {
"activities": [],
"inMemory": true
}], ["bot:load", {
"description": "",
"name": "AuthBot",
"overrides": null,
"padlock": "",
"path": "some/path",
"services": [{
"appId": "4f8fde3f-48d3-4d8a-a954-393efe39809e",
"appPassword": "REDACTED",
"endpoint": "http://localhost:55697/api/messages",
"id": "cded37c0-83f2-11e8-ac6d-b7172cd24b28",
"name": "authsample",
"type": "endpoint"
expect(remoteCommandArgs).toEqual([['transcript:open', 'deepLinkedTranscript', {
'activities': [],
'inMemory': true
}], ['bot:load', {
'description': '',
'name': 'AuthBot',
'overrides': null,
'padlock': '',
'path': 'some/path',
'services': [{
'appId': '4f8fde3f-48d3-4d8a-a954-393efe39809e',
'appPassword': 'REDACTED',
'endpoint': 'http://localhost:55697/api/messages',
'id': 'cded37c0-83f2-11e8-ac6d-b7172cd24b28',
'name': 'authsample',
'type': 'endpoint'
}],
"version": "2.0"
'version': '2.0'
}]]);
});
});
49 changes: 0 additions & 49 deletions packages/app/main/src/utils/directoryExists.ts

This file was deleted.

4 changes: 2 additions & 2 deletions packages/app/main/src/utils/ensureStoragePath.ts
Expand Up @@ -32,7 +32,7 @@
//

import * as path from 'path';
import * as Mkdirp from 'mkdirp';
import * as mkdirp from 'mkdirp';
import * as globals from '../globals';
import * as electron from 'electron'; // use a lowercase name "electron" to prevent clash with "Electron" namespace
const electronApp: Electron.App = electron.app;
Expand All @@ -43,6 +43,6 @@ export const ensureStoragePath = (): string => {
const commandLineArgs = globals.getGlobal('commandlineargs');
const app = electronApp || electronRemote.app;
const storagePath = commandLineArgs.storagepath || path.join(app.getPath('userData'), 'botframework-emulator');
Mkdirp.sync(storagePath);
mkdirp.sync(storagePath);
return storagePath;
};
26 changes: 26 additions & 0 deletions packages/app/main/src/utils/exceptionToAPIException.spec.ts
@@ -0,0 +1,26 @@
import { APIException } from '@bfemulator/app-shared';
import * as HttpStatus from 'http-status-codes';
import { exceptionToAPIException } from './exceptionToAPIException';

describe('The exceptionToAPIException', () => {
it('should pass an APIException though unchanged', () => {
const apiException: APIException = {
error: { error: { code: '42', message: 'oh noes!' } },
statusCode: HttpStatus.BAD_REQUEST
};

expect(exceptionToAPIException(apiException)).toBe(apiException);
});

it('should convert an exception to an APIException', () => {
const error = new Error('This is an error');
expect(exceptionToAPIException(error)).toEqual({
'error': {
'error': {
'code': 'ServiceError',
'message': 'This is an error'
}
}, 'statusCode': HttpStatus.BAD_REQUEST
});
});
});
49 changes: 0 additions & 49 deletions packages/app/main/src/utils/fileExists.ts

This file was deleted.

11 changes: 11 additions & 0 deletions packages/app/main/src/utils/getThemes.spec.ts
@@ -0,0 +1,11 @@
import { getThemes } from './getThemes';

describe('The getThemes utility', () => {
it('should retrieve the available themes from the themes directory', () => {
const themes = getThemes();
expect(themes).toEqual([
{ 'href': './themes/dark.css', 'name': 'Dark' },
{ 'href': './themes/high-contrast.css', 'name': 'High-contrast' },
{ 'href': './themes/light.css', 'name': 'Light' }]);
});
});
4 changes: 0 additions & 4 deletions packages/app/main/src/utils/index.ts
Expand Up @@ -33,23 +33,19 @@

export * from './botListsAreDifferent';
export * from './conversation';
export * from './directoryExists';
export * from './ensureStoragePath';
export * from './exceptionToAPIException';
export * from './fileExists';
export * from './getBotsFromDisk';
export * from './getDirectories';
export * from './getFilesInDir';
export * from './getSafeBotName';
export * from './isDev';
export * from './isLocalhostUrl';
export * from './isSecureUrl';
export * from './loadSettings';
export * from './parseActivitiesFromChatFile';
export * from './readFileSync';
export * from './saveSettings';
export * from './sendErrorResponse';
export * from './showMessageBox';
export * from './showOpenDialog';
export * from './showSaveDialog';
export * from './writeFile';
Expand Down
11 changes: 11 additions & 0 deletions packages/app/main/src/utils/isLocalHostUrl.spec.ts
@@ -0,0 +1,11 @@
import { isLocalhostUrl } from './isLocalhostUrl';

describe('The isLocalHostUrl util', () => {
it('should return true for urls that contain "localhost"', () => {
expect(isLocalhostUrl('http://localhost')).toBeTruthy();
});

it('should return true for urls that contain "127.0.0.1" ', () => {
expect(isLocalhostUrl('http://127.0.0.1')).toBeTruthy();
});
});
39 changes: 0 additions & 39 deletions packages/app/main/src/utils/isSecureUrl.ts

This file was deleted.

0 comments on commit f355d52

Please sign in to comment.