Skip to content

Commit aae881e

Browse files
committed
Fixes tests
1 parent db3c888 commit aae881e

File tree

12 files changed

+131
-96
lines changed

12 files changed

+131
-96
lines changed

.eslintrc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,6 @@
8787
"no-loop-func": 2, // http://eslint.org/docs/rules/no-loop-func
8888
"no-multi-str": 2, // http://eslint.org/docs/rules/no-multi-str
8989
"no-native-reassign": 2, // http://eslint.org/docs/rules/no-native-reassign
90-
"no-new": 2, // http://eslint.org/docs/rules/no-new
9190
"no-new-func": 2, // http://eslint.org/docs/rules/no-new-func
9291
"no-new-wrappers": 2, // http://eslint.org/docs/rules/no-new-wrappers
9392
"no-octal": 2, // http://eslint.org/docs/rules/no-octal

src/common/config.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
import { remote, app as mainApp } from 'electron';
1+
// import { remote, app as mainApp } from 'electron';
22
import constants from './constants.js';
3-
const app = remote ? remote.app : mainApp;
3+
// const app = remote ? remote.app : mainApp;
44

55
export default {
6-
version: constants.DEV ? 'DEV' : app.getVersion(),
7-
userData: app.getPath('userData'),
6+
version: app => constants.DEV ? 'DEV' : app.getVersion(),
7+
userData: app => app.getPath('userData'),
88

99
maxLogEntries: 100000,
1010
proxyPort: 1338,

src/common/service/proxy.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
import uniqid from 'uniqid';
22

33
export default class Proxy {
4-
constructor(newRequest, requestCompleted, config, urlMapper, createHoxy) {
5-
this._requests = [];
4+
constructor(newRequest, requestCompleted, urlMapper, createHoxy) {
65
this._urlMapper = urlMapper;
7-
this._config = config;
86
this._newRequest = newRequest;
97
this._requestCompleted = requestCompleted;
108
this._isCachingEnabled = false;

src/common/service/sentry.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
import config from '../config.js';
22
import constants from '../constants.js';
33

4-
export default function init(Sentry) {
4+
export default function init(app, Sentry) {
55
if (constants.DEV) {
66
return;
77
}
88

99
const { dsn, host } = config.sentry;
1010
Sentry.init({
1111
dsn: `https://${dsn}@${host}`,
12-
release: config.version
12+
release: config.version(app)
1313
});
1414
}

src/main/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,14 @@ import createUrlMapper from './url-mapper.js';
1212
import createProxy from './proxy.js';
1313
import autoUpdater from './auto-update.js';
1414

15-
sentryInit(Sentry);
15+
sentryInit(app, Sentry);
1616
// Keep a global reference of the window object, if you don't, the window will
1717
// be closed automatically when the javascript object is GCed.
1818
let mainWindow = null;
1919

2020
console.log('Loading URL mappings...'); // eslint-disable-line no-console
2121
const urlMapper = createUrlMapper({
22-
filename: `${config.userData}/data.nedb`,
22+
filename: `${config.userData(app)}/data.nedb`,
2323
autoload: true
2424
});
2525

src/main/proxy.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import hoxy from 'hoxy';
22
import fs from 'fs';
33
import EventEmitter from 'events';
4+
import {remote} from 'electron';
45

56
import constants from '../common/constants.js';
67
import appConfig from '../common/config.js';
@@ -18,18 +19,16 @@ class ProxyHandler extends EventEmitter {
1819
this.proxy = new Proxy(
1920
this.onNewRequest_.bind(this),
2021
this.onRequestCompleted_.bind(this),
21-
config,
2222
urlMapper,
23-
this.createHoxy.bind(this),
24-
this.isCaching.bind(this)
23+
this.createHoxy.bind(this)
2524
);
2625
}
2726

2827
createHoxy() {
2928
const opts = {};
3029
try {
31-
const key = fs.readFileSync(`${appConfig.userData}/root-ca.key.pem`);
32-
const cert = fs.readFileSync(`${appConfig.userData}/root-ca.crt.pem`);
30+
const key = fs.readFileSync(`${appConfig.userData(remote.app)}/root-ca.key.pem`);
31+
const cert = fs.readFileSync(`${appConfig.userData(remote.app)}/root-ca.crt.pem`);
3332
opts.certAuthority = {key, cert};
3433
} catch (e) {
3534
const [reason] = e.message.split('\n');

src/renderer/component/footer/update-status.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { shell } from 'electron';
1+
import { remote, shell } from 'electron';
22

33
import React from 'react';
44
import PropTypes from 'prop-types';
@@ -16,8 +16,8 @@ const openChangelog = e => launchURL(e, 'https://github.com/james-proxy/james/bl
1616
const openIssues = e => launchURL(e, 'https://github.com/james-proxy/james/issues');
1717

1818
const statusMap = {
19-
[constants.UPDATE_OK]: () => ({
20-
message: `v${config.version}`,
19+
[constants.UPDATE_OK]: (info, app) => ({
20+
message: `v${config.version(app)}`,
2121
icon: '',
2222
title: 'James is up to date',
2323
onClick: openChangelog
@@ -52,7 +52,7 @@ const statusMap = {
5252
};
5353

5454
const UpdateStatus = ({status, info}) => {
55-
const { message, icon, title, onClick } = statusMap[status](info);
55+
const { message, icon, title, onClick } = statusMap[status](info, remote.app);
5656
const classes = `update-status ${status} ${onClick ? 'has-action' : ''}`;
5757

5858
return <div className={classes} title={title} onClick={onClick}>

src/renderer/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ if (!constants.DEV) { // fix for loading async bundles (see electron-userland/el
44
__webpack_public_path__ = `file:///${process.resourcesPath}/app.asar/`; // eslint-disable-line camelcase
55
}
66

7-
import { ipcRenderer as ipc } from 'electron';
7+
import { remote, ipcRenderer as ipc } from 'electron';
88
import React from 'react';
99
import ReactDOM from 'react-dom';
1010
import { Provider } from 'react-redux';
@@ -28,7 +28,7 @@ import App from './containers/app';
2828

2929
import './resources/style/main.scss';
3030

31-
sentryInit(Sentry);
31+
sentryInit(remote.app, Sentry);
3232

3333
const history = createHistory();
3434
const store = setupStore(history);

src/renderer/reducers/requests.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import { combineReducers } from 'redux';
22
import { createSelector } from 'reselect';
33

4-
import config from 'common/config.js';
4+
import config from '../../common/config.js';
55
import * as actions from '../../common/actions/requests.js';
6-
import * as proxyActions from 'common/actions/proxy.js';
6+
import * as proxyActions from '../../common/actions/proxy.js';
77

88
const initialState = {
99
filter: null,
@@ -42,7 +42,7 @@ function data(state = initialState.data, action) {
4242
.slice(0, config.maxLogEntries);
4343
case actions.COMPLETE_REQUEST:
4444
return state.map(existingContainer => {
45-
if (existingContainer.request.id !== action.requestContainer.id) {
45+
if (existingContainer.id !== action.requestContainer.id) {
4646
return existingContainer;
4747
}
4848
return action.requestContainer;

test/unit/actions/requests.js

Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,7 @@ import assert from 'assert';
22

33
import * as actions from '../../../src/common/actions/requests.js';
44

5-
const request = {
6-
request: {},
7-
response: {},
8-
id: ''
9-
};
5+
const requestId = '';
106

117
describe('request actions', () => {
128
it('should create actions to set the request filter', () => {
@@ -22,41 +18,32 @@ describe('request actions', () => {
2218
it('should create an action to clear the active request', () => {
2319
const expectedAction = {
2420
type: actions.SET_ACTIVE_REQUEST,
25-
request: null
21+
requestId: null
2622
};
2723
assert.deepEqual(actions.setActiveRequest(), expectedAction);
2824
});
2925

3026
it('should create an action to set the active request', () => {
3127
const expectedAction = {
3228
type: actions.SET_ACTIVE_REQUEST,
33-
request
29+
requestId
3430
};
35-
assert.deepEqual(actions.setActiveRequest(request), expectedAction);
31+
assert.deepEqual(actions.setActiveRequest(requestId), expectedAction);
3632
});
3733

3834
it('should create an action to clear the active context', () => {
3935
const expectedAction = {
4036
type: actions.SET_CONTEXT_REQUEST,
41-
request: null
37+
requestId: null
4238
};
4339
assert.deepEqual(actions.setContextRequest(), expectedAction);
4440
});
4541

4642
it('should create an action to set the active context', () => {
4743
const expectedAction = {
4844
type: actions.SET_CONTEXT_REQUEST,
49-
request
45+
requestId
5046
};
51-
assert.deepEqual(actions.setContextRequest(request), expectedAction);
52-
});
53-
54-
it('should create an action to sync url mappings', () => {
55-
const requestData = {};
56-
const expectedAction = {
57-
type: actions.SYNC_REQUESTS,
58-
requestData
59-
};
60-
assert.deepEqual(actions.syncRequests({requestData}), expectedAction);
47+
assert.deepEqual(actions.setContextRequest(requestId), expectedAction);
6148
});
6249
});

0 commit comments

Comments
 (0)