From 1e6b334cdca79e93a585d8c23f6551142d7bf1c0 Mon Sep 17 00:00:00 2001 From: Matthias Kretschmann Date: Fri, 31 May 2019 12:56:13 +0200 Subject: [PATCH] formatting and test tweaks --- client/__mocks__/ocean-mock.ts | 25 ++++++ client/__mocks__/user-mock.ts | 14 +--- client/package-lock.json | 84 ++++++++++++++----- client/src/App.test.tsx | 8 +- client/src/Routes.test.tsx | 10 ++- .../organisms/AssetsLatest.test.tsx | 12 ++- .../organisms/ChannelTeaser.test.tsx | 10 ++- .../templates/Asset/AssetFile.test.tsx | 20 +---- .../components/templates/Asset/AssetFile.tsx | 17 ++-- .../src/components/templates/Channel.test.tsx | 28 +------ client/src/routes/Channels.test.tsx | 10 ++- client/src/routes/Search.test.tsx | 28 +------ server/src/routes/UrlCheckRouter.ts | 2 +- 13 files changed, 144 insertions(+), 124 deletions(-) create mode 100644 client/__mocks__/ocean-mock.ts diff --git a/client/__mocks__/ocean-mock.ts b/client/__mocks__/ocean-mock.ts new file mode 100644 index 0000000..af44f70 --- /dev/null +++ b/client/__mocks__/ocean-mock.ts @@ -0,0 +1,25 @@ +const oceanMock = { + ocean: { + accounts: { + list: () => ['xxx', 'xxx'] + }, + aquarius: { + queryMetadata: () => { + return { + results: [], + totalResults: 1, + totalPages: 1 + } + } + }, + keeper: { + conditions: { + accessSecretStoreCondition: { + getGrantedDidByConsumer: jest.fn() + } + } + } + } +} + +export default oceanMock diff --git a/client/__mocks__/user-mock.ts b/client/__mocks__/user-mock.ts index 5cda7ea..eabdfd5 100644 --- a/client/__mocks__/user-mock.ts +++ b/client/__mocks__/user-mock.ts @@ -1,3 +1,5 @@ +import oceanMock from './ocean-mock' + const userMock = { isLogged: false, isLoading: false, @@ -5,11 +7,7 @@ const userMock = { isOceanNetwork: false, account: '', web3: {}, - ocean: { - aquarius: { - queryMetadata: jest.fn() - } - }, + ...oceanMock, balance: { eth: 0, ocn: 0 }, network: '', requestFromFaucet: jest.fn(), @@ -24,11 +22,7 @@ const userMockConnected = { isOceanNetwork: true, account: '0xxxxxx', web3: {}, - ocean: { - aquarius: { - queryMetadata: jest.fn() - } - }, + ...oceanMock, balance: { eth: 0, ocn: 0 }, network: '', requestFromFaucet: jest.fn(), diff --git a/client/package-lock.json b/client/package-lock.json index f3465bb..5e20e97 100644 --- a/client/package-lock.json +++ b/client/package-lock.json @@ -3487,7 +3487,8 @@ "version": "2.1.1", "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-2.1.1.tgz", "integrity": "sha1-w7M6te42DYbg5ijwRorn7yfWVN8=", - "dev": true + "dev": true, + "optional": true }, "aproba": { "version": "1.2.0", @@ -3511,13 +3512,15 @@ "version": "1.0.0", "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.0.tgz", "integrity": "sha1-ibTRmasr7kneFk6gK4nORi1xt2c=", - "dev": true + "dev": true, + "optional": true }, "brace-expansion": { "version": "1.1.11", "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz", "integrity": "sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==", "dev": true, + "optional": true, "requires": { "balanced-match": "^1.0.0", "concat-map": "0.0.1" @@ -3534,19 +3537,22 @@ "version": "1.1.0", "resolved": "https://registry.npmjs.org/code-point-at/-/code-point-at-1.1.0.tgz", "integrity": "sha1-DQcLTQQ6W+ozovGkDi7bPZpMz3c=", - "dev": true + "dev": true, + "optional": true }, "concat-map": { "version": "0.0.1", "resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz", "integrity": "sha1-2Klr13/Wjfd5OnMDajug1UBdR3s=", - "dev": true + "dev": true, + "optional": true }, "console-control-strings": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/console-control-strings/-/console-control-strings-1.1.0.tgz", "integrity": "sha1-PXz0Rk22RG6mRL9LOVB/mFEAjo4=", - "dev": true + "dev": true, + "optional": true }, "core-util-is": { "version": "1.0.2", @@ -3677,7 +3683,8 @@ "version": "2.0.3", "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.3.tgz", "integrity": "sha1-Yzwsg+PaQqUC9SRmAiSA9CCCYd4=", - "dev": true + "dev": true, + "optional": true }, "ini": { "version": "1.3.5", @@ -3691,6 +3698,7 @@ "resolved": "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-1.0.0.tgz", "integrity": "sha1-754xOG8DGn8NZDr4L95QxFfvAMs=", "dev": true, + "optional": true, "requires": { "number-is-nan": "^1.0.0" } @@ -3707,6 +3715,7 @@ "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.0.4.tgz", "integrity": "sha512-yJHVQEhyqPLUTgt9B83PXu6W3rx4MvvHvSUvToogpwoGDOUQ+yDrR0HRot+yOCdCO7u4hX3pWft6kWBBcqh0UA==", "dev": true, + "optional": true, "requires": { "brace-expansion": "^1.1.7" } @@ -3715,13 +3724,15 @@ "version": "0.0.8", "resolved": "https://registry.npmjs.org/minimist/-/minimist-0.0.8.tgz", "integrity": "sha1-hX/Kv8M5fSYluCKCYuhqp6ARsF0=", - "dev": true + "dev": true, + "optional": true }, "minipass": { "version": "2.3.5", "resolved": "https://registry.npmjs.org/minipass/-/minipass-2.3.5.tgz", "integrity": "sha512-Gi1W4k059gyRbyVUZQ4mEqLm0YIUiGYfvxhF6SIlk3ui1WVxMTGfGdQ2SInh3PDrRTVvPKgULkpJtT4RH10+VA==", "dev": true, + "optional": true, "requires": { "safe-buffer": "^5.1.2", "yallist": "^3.0.0" @@ -3742,6 +3753,7 @@ "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.5.1.tgz", "integrity": "sha1-MAV0OOrGz3+MR2fzhkjWaX11yQM=", "dev": true, + "optional": true, "requires": { "minimist": "0.0.8" } @@ -3830,7 +3842,8 @@ "version": "1.0.1", "resolved": "https://registry.npmjs.org/number-is-nan/-/number-is-nan-1.0.1.tgz", "integrity": "sha1-CXtgK1NCKlIsGvuHkDGDNpQaAR0=", - "dev": true + "dev": true, + "optional": true }, "object-assign": { "version": "4.1.1", @@ -3844,6 +3857,7 @@ "resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz", "integrity": "sha1-WDsap3WWHUsROsF9nFC6753Xa9E=", "dev": true, + "optional": true, "requires": { "wrappy": "1" } @@ -3939,7 +3953,8 @@ "version": "5.1.2", "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.2.tgz", "integrity": "sha512-Gd2UZBJDkXlY7GbJxfsE8/nvKkUEU1G38c1siN6QP6a9PT9MmHB8GnpscSmMJSoF8LOIrt8ud/wPtojys4G6+g==", - "dev": true + "dev": true, + "optional": true }, "safer-buffer": { "version": "2.1.2", @@ -3981,6 +3996,7 @@ "resolved": "https://registry.npmjs.org/string-width/-/string-width-1.0.2.tgz", "integrity": "sha1-EYvfW4zcUaKn5w0hHgfisLmxB9M=", "dev": true, + "optional": true, "requires": { "code-point-at": "^1.0.0", "is-fullwidth-code-point": "^1.0.0", @@ -4002,6 +4018,7 @@ "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-3.0.1.tgz", "integrity": "sha1-ajhfuIU9lS1f8F0Oiq+UJ43GPc8=", "dev": true, + "optional": true, "requires": { "ansi-regex": "^2.0.0" } @@ -4050,13 +4067,15 @@ "version": "1.0.2", "resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz", "integrity": "sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8=", - "dev": true + "dev": true, + "optional": true }, "yallist": { "version": "3.0.3", "resolved": "https://registry.npmjs.org/yallist/-/yallist-3.0.3.tgz", "integrity": "sha512-S+Zk8DEWE6oKpV+vI3qWkaK+jSbIK86pCwe2IF/xwIpQ8jEuxpw9NyaGjmp9+BoJv5FV2piqCDcoCtStppiq2A==", - "dev": true + "dev": true, + "optional": true } } }, @@ -8745,7 +8764,8 @@ "version": "2.1.1", "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-2.1.1.tgz", "integrity": "sha1-w7M6te42DYbg5ijwRorn7yfWVN8=", - "dev": true + "dev": true, + "optional": true }, "aproba": { "version": "1.2.0", @@ -8769,13 +8789,15 @@ "version": "1.0.0", "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.0.tgz", "integrity": "sha1-ibTRmasr7kneFk6gK4nORi1xt2c=", - "dev": true + "dev": true, + "optional": true }, "brace-expansion": { "version": "1.1.11", "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz", "integrity": "sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==", "dev": true, + "optional": true, "requires": { "balanced-match": "^1.0.0", "concat-map": "0.0.1" @@ -8792,19 +8814,22 @@ "version": "1.1.0", "resolved": "https://registry.npmjs.org/code-point-at/-/code-point-at-1.1.0.tgz", "integrity": "sha1-DQcLTQQ6W+ozovGkDi7bPZpMz3c=", - "dev": true + "dev": true, + "optional": true }, "concat-map": { "version": "0.0.1", "resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz", "integrity": "sha1-2Klr13/Wjfd5OnMDajug1UBdR3s=", - "dev": true + "dev": true, + "optional": true }, "console-control-strings": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/console-control-strings/-/console-control-strings-1.1.0.tgz", "integrity": "sha1-PXz0Rk22RG6mRL9LOVB/mFEAjo4=", - "dev": true + "dev": true, + "optional": true }, "core-util-is": { "version": "1.0.2", @@ -8935,7 +8960,8 @@ "version": "2.0.3", "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.3.tgz", "integrity": "sha1-Yzwsg+PaQqUC9SRmAiSA9CCCYd4=", - "dev": true + "dev": true, + "optional": true }, "ini": { "version": "1.3.5", @@ -8949,6 +8975,7 @@ "resolved": "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-1.0.0.tgz", "integrity": "sha1-754xOG8DGn8NZDr4L95QxFfvAMs=", "dev": true, + "optional": true, "requires": { "number-is-nan": "^1.0.0" } @@ -8965,6 +8992,7 @@ "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.0.4.tgz", "integrity": "sha512-yJHVQEhyqPLUTgt9B83PXu6W3rx4MvvHvSUvToogpwoGDOUQ+yDrR0HRot+yOCdCO7u4hX3pWft6kWBBcqh0UA==", "dev": true, + "optional": true, "requires": { "brace-expansion": "^1.1.7" } @@ -8973,13 +9001,15 @@ "version": "0.0.8", "resolved": "https://registry.npmjs.org/minimist/-/minimist-0.0.8.tgz", "integrity": "sha1-hX/Kv8M5fSYluCKCYuhqp6ARsF0=", - "dev": true + "dev": true, + "optional": true }, "minipass": { "version": "2.3.5", "resolved": "https://registry.npmjs.org/minipass/-/minipass-2.3.5.tgz", "integrity": "sha512-Gi1W4k059gyRbyVUZQ4mEqLm0YIUiGYfvxhF6SIlk3ui1WVxMTGfGdQ2SInh3PDrRTVvPKgULkpJtT4RH10+VA==", "dev": true, + "optional": true, "requires": { "safe-buffer": "^5.1.2", "yallist": "^3.0.0" @@ -9000,6 +9030,7 @@ "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.5.1.tgz", "integrity": "sha1-MAV0OOrGz3+MR2fzhkjWaX11yQM=", "dev": true, + "optional": true, "requires": { "minimist": "0.0.8" } @@ -9088,7 +9119,8 @@ "version": "1.0.1", "resolved": "https://registry.npmjs.org/number-is-nan/-/number-is-nan-1.0.1.tgz", "integrity": "sha1-CXtgK1NCKlIsGvuHkDGDNpQaAR0=", - "dev": true + "dev": true, + "optional": true }, "object-assign": { "version": "4.1.1", @@ -9102,6 +9134,7 @@ "resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz", "integrity": "sha1-WDsap3WWHUsROsF9nFC6753Xa9E=", "dev": true, + "optional": true, "requires": { "wrappy": "1" } @@ -9197,7 +9230,8 @@ "version": "5.1.2", "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.2.tgz", "integrity": "sha512-Gd2UZBJDkXlY7GbJxfsE8/nvKkUEU1G38c1siN6QP6a9PT9MmHB8GnpscSmMJSoF8LOIrt8ud/wPtojys4G6+g==", - "dev": true + "dev": true, + "optional": true }, "safer-buffer": { "version": "2.1.2", @@ -9239,6 +9273,7 @@ "resolved": "https://registry.npmjs.org/string-width/-/string-width-1.0.2.tgz", "integrity": "sha1-EYvfW4zcUaKn5w0hHgfisLmxB9M=", "dev": true, + "optional": true, "requires": { "code-point-at": "^1.0.0", "is-fullwidth-code-point": "^1.0.0", @@ -9260,6 +9295,7 @@ "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-3.0.1.tgz", "integrity": "sha1-ajhfuIU9lS1f8F0Oiq+UJ43GPc8=", "dev": true, + "optional": true, "requires": { "ansi-regex": "^2.0.0" } @@ -9308,13 +9344,15 @@ "version": "1.0.2", "resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz", "integrity": "sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8=", - "dev": true + "dev": true, + "optional": true }, "yallist": { "version": "3.0.3", "resolved": "https://registry.npmjs.org/yallist/-/yallist-3.0.3.tgz", "integrity": "sha512-S+Zk8DEWE6oKpV+vI3qWkaK+jSbIK86pCwe2IF/xwIpQ8jEuxpw9NyaGjmp9+BoJv5FV2piqCDcoCtStppiq2A==", - "dev": true + "dev": true, + "optional": true } } } @@ -16507,7 +16545,7 @@ "requires": { "underscore": "1.8.3", "web3-core-helpers": "1.0.0-beta.37", - "websocket": "git://github.com/frozeman/WebSocket-Node.git#6c72925e3f8aaaea8dc8450f97627e85263999f2" + "websocket": "git://github.com/frozeman/WebSocket-Node.git#browserifyCompatible" } }, "web3-shh": { diff --git a/client/src/App.test.tsx b/client/src/App.test.tsx index 8c85a79..0f22fcd 100644 --- a/client/src/App.test.tsx +++ b/client/src/App.test.tsx @@ -2,7 +2,7 @@ import React from 'react' import { render } from 'react-testing-library' import App from './App' import { User } from './context' -import { userMock } from '../__mocks__/user-mock' +import { userMock, userMockConnected } from '../__mocks__/user-mock' describe('App', () => { it('should be able to run tests', () => { @@ -10,7 +10,11 @@ describe('App', () => { }) it('renders without crashing', () => { - const { container } = render() + const { container } = render( + + + + ) expect(container.firstChild).toBeInTheDocument() }) diff --git a/client/src/Routes.test.tsx b/client/src/Routes.test.tsx index 5ae671b..43c63e8 100644 --- a/client/src/Routes.test.tsx +++ b/client/src/Routes.test.tsx @@ -2,13 +2,17 @@ import React from 'react' import { BrowserRouter as Router } from 'react-router-dom' import { render } from 'react-testing-library' import Routes from './Routes' +import { User } from './context' +import { userMockConnected } from '../__mocks__/user-mock' describe('Routes', () => { it('renders without crashing', () => { const { container } = render( - - - + + + + + ) expect(container.firstChild).toBeInTheDocument() }) diff --git a/client/src/components/organisms/AssetsLatest.test.tsx b/client/src/components/organisms/AssetsLatest.test.tsx index 978045b..69aacd7 100644 --- a/client/src/components/organisms/AssetsLatest.test.tsx +++ b/client/src/components/organisms/AssetsLatest.test.tsx @@ -1,14 +1,18 @@ import React from 'react' +import { BrowserRouter } from 'react-router-dom' import { render } from 'react-testing-library' import AssetsLatest from './AssetsLatest' -import { BrowserRouter } from 'react-router-dom' +import { User } from '../../context' +import { userMockConnected } from '../../../__mocks__/user-mock' describe('AssetsLatest', () => { it('renders without crashing', () => { const { container } = render( - - - + + + + + ) expect(container.firstChild).toBeInTheDocument() }) diff --git a/client/src/components/organisms/ChannelTeaser.test.tsx b/client/src/components/organisms/ChannelTeaser.test.tsx index c270a41..c92dce3 100644 --- a/client/src/components/organisms/ChannelTeaser.test.tsx +++ b/client/src/components/organisms/ChannelTeaser.test.tsx @@ -2,13 +2,17 @@ import React from 'react' import { render } from 'react-testing-library' import ChannelTeaser from './ChannelTeaser' import { BrowserRouter } from 'react-router-dom' +import { User } from '../../context' +import { userMockConnected } from '../../../__mocks__/user-mock' describe('ChannelTeaser', () => { it('renders without crashing', () => { const { container } = render( - - - + + + + + ) expect(container.firstChild).toBeInTheDocument() }) diff --git a/client/src/components/templates/Asset/AssetFile.test.tsx b/client/src/components/templates/Asset/AssetFile.test.tsx index c34abc4..a4e2307 100644 --- a/client/src/components/templates/Asset/AssetFile.test.tsx +++ b/client/src/components/templates/Asset/AssetFile.test.tsx @@ -7,6 +7,7 @@ import { StateMock } from '@react-mock/state' import ReactGA from 'react-ga' import { User } from '../../../context' import AssetFile, { messages } from './AssetFile' +import { userMockConnected } from '../../../../__mocks__/user-mock' const file = { index: 0, @@ -15,22 +16,7 @@ const file = { contentLength: 100 } -const ddo = ({ id: 'xxx' } as any) as DDO - -const contextConnectedMock = { - isLogged: true, - isLoading: false, - isWeb3: true, - isOceanNetwork: true, - account: '', - web3: {}, - ocean: {}, - balance: { eth: 0, ocn: 0 }, - network: '', - requestFromFaucet: () => {}, - unlockAccounts: () => {}, - message: '' -} +const ddo = ({ id: 'xxx', findServiceByType: jest.fn() } as any) as DDO ReactGA.initialize('foo', { testMode: true }) @@ -47,7 +33,7 @@ describe('AssetFile', () => { it('button to be enabled when connected', async () => { const { getByText } = render( - + ) diff --git a/client/src/components/templates/Asset/AssetFile.tsx b/client/src/components/templates/Asset/AssetFile.tsx index 5fd7ca7..263f274 100644 --- a/client/src/components/templates/Asset/AssetFile.tsx +++ b/client/src/components/templates/Asset/AssetFile.tsx @@ -59,16 +59,21 @@ export default class AssetFile extends PureComponent< const accounts = await ocean.accounts.list() const service = ddo.findServiceByType('Access') - const agreements = await ocean.keeper.conditions.accessSecretStoreCondition.getGrantedDidByConsumer(accounts[0].id) - const agreement = agreements.find((element: any) => {return element.did === ddo.id}) + const agreements = await ocean.keeper.conditions.accessSecretStoreCondition.getGrantedDidByConsumer( + accounts[0].id + ) + const agreement = agreements.find((element: any) => { + return element.did === ddo.id + }) let agreementId + if (agreement) { - agreementId = agreement.agreementId + ;({ agreementId } = agreement) } else { agreementId = await ocean.assets - .order(ddo.id, service.serviceDefinitionId, accounts[0]) - .next((step: number) => this.setState({ step })) + .order(ddo.id, service.serviceDefinitionId, accounts[0]) + .next((step: number) => this.setState({ step })) } // manually add another step here for better UX @@ -89,7 +94,7 @@ export default class AssetFile extends PureComponent< }) this.setState({ isLoading: false }) } catch (error) { - Logger.log('error', error.message) + Logger.error('error', error.message) this.setState({ isLoading: false, error: `${error.message}. Sorry about that, can you try again?` diff --git a/client/src/components/templates/Channel.test.tsx b/client/src/components/templates/Channel.test.tsx index c16c84b..cad7808 100644 --- a/client/src/components/templates/Channel.test.tsx +++ b/client/src/components/templates/Channel.test.tsx @@ -3,38 +3,14 @@ import { render } from 'react-testing-library' import Channel from './Channel' import { User } from '../../context' import { createMemoryHistory } from 'history' +import { userMockConnected } from '../../../__mocks__/user-mock' describe('Channel', () => { it('renders without crashing', () => { const history = createMemoryHistory() const { container } = render( - { - return { - results: [], - totalResults: 1, - totalPages: 1 - } - } - } - }, - balance: { eth: 0, ocn: 0 }, - network: '', - requestFromFaucet: () => {}, - unlockAccounts: () => {}, - message: '' - }} - > + { it('renders without crashing', () => { const { container } = render( - - - + + + + + ) expect(container.firstChild).toBeInTheDocument() }) diff --git a/client/src/routes/Search.test.tsx b/client/src/routes/Search.test.tsx index cf2819c..584ab94 100644 --- a/client/src/routes/Search.test.tsx +++ b/client/src/routes/Search.test.tsx @@ -4,38 +4,14 @@ import Search from './Search' import { User } from '../context' import { createMemoryHistory } from 'history' import { BrowserRouter as Router } from 'react-router-dom' +import { userMockConnected } from '../../__mocks__/user-mock' describe('Search', () => { it('renders without crashing', () => { const history = createMemoryHistory() const { container } = render( - { - return { - results: [], - totalResults: 1, - totalPages: 1 - } - } - } - }, - balance: { eth: 0, ocn: 0 }, - network: '', - requestFromFaucet: () => {}, - unlockAccounts: () => {}, - message: '' - }} - > +