summaryrefslogtreecommitdiffhomepage
path: root/test/mocks
diff options
context:
space:
mode:
Diffstat (limited to 'test/mocks')
-rw-r--r--test/mocks/ipc.js98
-rw-r--r--test/mocks/redux.js4
2 files changed, 102 insertions, 0 deletions
diff --git a/test/mocks/ipc.js b/test/mocks/ipc.js
new file mode 100644
index 0000000000..ede4bd37b7
--- /dev/null
+++ b/test/mocks/ipc.js
@@ -0,0 +1,98 @@
+// @flow
+import type { IpcFacade, BackendState } from '../../app/lib/ipc-facade';
+
+interface MockIpc {
+ sendNewState: (BackendState) => void;
+ killWebSocket: () => void;
+ -getAccountData: *;
+ -connect: *;
+ -getAccount: *;
+ -authenticate: *;
+}
+
+export function newMockIpc() {
+
+ const stateListeners = [];
+ const connectionCloseListeners = [];
+
+ const mockIpc: IpcFacade & MockIpc = {
+
+ setConnectionString: (_str: string) => {},
+
+ getAccountData: (accountToken) => Promise.resolve({
+ accountToken: accountToken,
+ expiry: '',
+ }),
+
+ getAccount: () => Promise.resolve('1111'),
+
+ setAccount: () => Promise.resolve(),
+
+ updateRelaySettings: () => Promise.resolve(),
+
+ getRelaySettings: () => Promise.resolve({
+ custom_tunnel_endpoint: {
+ host: 'www.example.com',
+ tunnel: {
+ openvpn: {
+ port: 1301,
+ protocol: 'udp',
+ }
+ }
+ },
+ }),
+
+ getRelayLocations: () => Promise.resolve({
+ countries: [],
+ }),
+
+ connect: () => Promise.resolve(),
+
+ disconnect: () => Promise.resolve(),
+
+ shutdown: () => Promise.resolve(),
+
+ getPublicIp: () => Promise.resolve('1.2.3.4'),
+
+ getLocation: () => Promise.resolve({
+ country: '',
+ country_code: '',
+ city: '',
+ city_code: '',
+ position: [0, 0],
+ }),
+
+ getState: () => Promise.resolve({
+ state: 'unsecured',
+ target_state:'unsecured',
+ }),
+
+ registerStateListener: (listener: (BackendState) => void) => {
+ stateListeners.push(listener);
+ },
+
+ sendNewState: (state: BackendState) => {
+ for(const l of stateListeners) {
+ l(state);
+ }
+ },
+
+ setCloseConnectionHandler: (listener: () => void) => {
+ connectionCloseListeners.push(listener);
+ },
+
+ authenticate: (_secret: string) => Promise.resolve(),
+
+ getAccountHistory: () => Promise.resolve([]),
+
+ removeAccountFromHistory: (_accountToken) => Promise.resolve(),
+
+ killWebSocket: () => {
+ for(const l of connectionCloseListeners) {
+ l();
+ }
+ }
+ };
+
+ return mockIpc;
+}
diff --git a/test/mocks/redux.js b/test/mocks/redux.js
new file mode 100644
index 0000000000..a652009645
--- /dev/null
+++ b/test/mocks/redux.js
@@ -0,0 +1,4 @@
+import configureMockStore from 'redux-mock-store';
+import thunk from 'redux-thunk';
+
+export const mockStore = configureMockStore([ thunk ]);