summaryrefslogtreecommitdiffhomepage
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/actions.spec.js41
-rw-r--r--test/mocks/ipc.js37
-rw-r--r--test/mocks/redux.js (renamed from test/mocks/backend.js)32
-rw-r--r--test/routing.spec.js12
4 files changed, 66 insertions, 56 deletions
diff --git a/test/actions.spec.js b/test/actions.spec.js
index d8f8bfbc26..e1420e92d2 100644
--- a/test/actions.spec.js
+++ b/test/actions.spec.js
@@ -1,6 +1,9 @@
+// @flow
+
import { expect } from 'chai';
-import { filterMinorActions, mockBackend, mockState, mockStore } from './mocks/backend';
+import { filterMinorActions, mockState, mockStore } from './mocks/redux';
import Backend from '../app/lib/backend';
+import { newMockIpc } from './mocks/ipc';
import userActions from '../app/actions/user';
import connectActions from '../app/actions/connect';
import mapBackendEventsToReduxActions from '../app/lib/backend-redux-actions';
@@ -15,12 +18,15 @@ describe('actions', function() {
{ type: 'USER_LOGIN_CHANGE', payload: { paidUntil: '2013-01-01T00:00:00.000Z', status: 'ok', error: undefined } }
];
const store = mockStore(mockState());
- const backend = mockBackend({
- users: {
- 1: {
- paid_until: '2013-01-01T00:00:00.000Z',
- }}
- });
+ const mockIpc = newMockIpc();
+ mockIpc.getAccountData = () => {
+ return new Promise(r => r({
+ paid_until: '2013-01-01T00:00:00.000Z',
+ }));
+ };
+
+ const backend = new Backend(mockIpc);
+
mapBackendEventsToReduxActions(backend, store);
backend.once(Backend.EventType.login, () => {
@@ -38,7 +44,8 @@ describe('actions', function() {
];
const store = mockStore(mockState());
- const backend = mockBackend();
+ const mockIpc = newMockIpc();
+ const backend = new Backend(mockIpc);
mapBackendEventsToReduxActions(backend, store);
backend.once(Backend.EventType.logout, () => {
@@ -58,13 +65,13 @@ describe('actions', function() {
];
const store = mockStore(mockState());
- const backend = mockBackend({
- users: {
- '1': {
- paid_until: '2038-01-01T00:00:00.000Z',
- status: LoginState.ok
- }
- }});
+ const mockIpc = newMockIpc();
+ const backend = new Backend(mockIpc);
+ mockIpc.getAccountData = () => {
+ return new Promise(r => r({
+ paid_until: '2038-01-01T00:00:00.000Z',
+ }));
+ };
mapBackendEventsToReduxActions(backend, store);
backend.once(Backend.EventType.connect, () => {
@@ -102,7 +109,7 @@ describe('actions', function() {
});
const store = mockStore(state);
- const backend = mockBackend();
+ const backend = new Backend(newMockIpc());
mapBackendEventsToReduxActions(backend, store);
backend.once(Backend.EventType.disconnect, () => {
@@ -134,7 +141,7 @@ describe('actions', function() {
});
const store = mockStore(state);
- const backend = mockBackend();
+ const backend = new Backend(newMockIpc());
mapBackendEventsToReduxActions(backend, store);
backend.once(Backend.EventType.disconnect, () => {
diff --git a/test/mocks/ipc.js b/test/mocks/ipc.js
new file mode 100644
index 0000000000..bb1a872454
--- /dev/null
+++ b/test/mocks/ipc.js
@@ -0,0 +1,37 @@
+// @flow
+import type { IpcFacade } from '../../app/lib/ipc-facade';
+
+export function newMockIpc() {
+ return Object.assign({}, mockIpc);
+}
+
+const mockIpc: IpcFacade = {
+
+ getAccountData: () => {
+ return new Promise(r => r({
+ paid_until: '',
+ }));
+ },
+ setAccount: () => {
+ return new Promise(r => r());
+ },
+ setCountry: () => {
+ return new Promise(r => r());
+ },
+ connect: () => {
+ return new Promise(r => r());
+ },
+ disconnect: () => {
+ return new Promise(r => r());
+ },
+ getIp: () => {
+ return new Promise(r => r('1.2.3.4'));
+ },
+ getLocation: () => {
+ return new Promise(r => r({
+ city: '',
+ country: '',
+ latlong: [],
+ }));
+ },
+};
diff --git a/test/mocks/backend.js b/test/mocks/redux.js
index f665df8ee7..6855274296 100644
--- a/test/mocks/backend.js
+++ b/test/mocks/redux.js
@@ -1,7 +1,5 @@
import configureMockStore from 'redux-mock-store';
import thunk from 'redux-thunk';
-import Backend from '../../app/lib/backend';
-import Ipc from '../../app/lib/ipc';
import { defaultServer } from '../../app/config';
import { LoginState, ConnectionState } from '../../app/enums';
@@ -30,36 +28,6 @@ export const mockState = () => {
};
};
-export const mockBackend = (backendData) => {
- return new Backend(mockIpc(backendData));
-};
-
-const mockIpc = (backendData) => {
- const ipc = new Ipc();
- ipc.send = (action, data) => {
- return new Promise((resolve, reject) => {
-
- switch (action) {
- case 'get_account_data': {
- const accountNumber = data;
- return resolve(backendData.users[accountNumber]);
- }
- case 'set_account':
- case 'set_country':
- case 'connect':
- case 'disconnect':
- return resolve();
-
- case 'event_subscribe':
- return resolve();
- }
-
- reject('Unknown action: ' + action);
- });
- };
- return ipc;
-};
-
export const filterMinorActions = (actions) => {
return actions.filter((action) => {
if(action.type === 'CONNECTION_CHANGE' && action.payload.clientIp) {
diff --git a/test/routing.spec.js b/test/routing.spec.js
index ad0fa16322..2ce33e73c2 100644
--- a/test/routing.spec.js
+++ b/test/routing.spec.js
@@ -1,9 +1,11 @@
import { expect } from 'chai';
-import { filterMinorActions, mockBackend, mockState, mockStore } from './mocks/backend';
+import { filterMinorActions, mockState, mockStore } from './mocks/redux';
import userActions from '../app/actions/user';
import mapBackendEventsToRouter from '../app/lib/backend-routing';
import { LoginState } from '../app/enums';
+import Backend from '../app/lib/backend';
+import { newMockIpc } from './mocks/ipc';
describe('routing', function() {
this.timeout(10000);
@@ -21,7 +23,7 @@ describe('routing', function() {
});
const store = mockStore(state);
- const backend = mockBackend();
+ const backend = new Backend(newMockIpc());
mapBackendEventsToRouter(backend, store);
store.dispatch(userActions.logout(backend));
@@ -38,11 +40,7 @@ describe('routing', function() {
];
const store = mockStore(mockState());
- const backend = mockBackend({
- users: {
- '1': { status: LoginState.none },
- }
- });
+ const backend = new Backend(newMockIpc());
mapBackendEventsToRouter(backend, store);
store.subscribe(() => {