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 6b61145..8124629 100644
--- a/client/package-lock.json
+++ b/client/package-lock.json
@@ -1296,9 +1296,9 @@
"integrity": "sha512-nOpbSE/BG+tQBfLXZ/EqSOvUPzOuot84vHxjAfEU8K3v4eOnqFJVo+oyB7KlcF87wBJXDmi/Ir9qHY4c0Saipg=="
},
"@oceanprotocol/squid": {
- "version": "0.5.11",
- "resolved": "https://registry.npmjs.org/@oceanprotocol/squid/-/squid-0.5.11.tgz",
- "integrity": "sha512-vgwu0ibLPAi97+i9hWCRdBOG+RChm1dkvHNdLE6T0dA3Xw6gEbdAmOZ/iWYoBxYiYr8DXyjgOdChU6kb7jAepQ==",
+ "version": "0.5.12",
+ "resolved": "https://registry.npmjs.org/@oceanprotocol/squid/-/squid-0.5.12.tgz",
+ "integrity": "sha512-RhP0wK4nA9ro/HQl3SohJ21XknxD1PtOCY+gQS3iUyyAabcGKVgMrpcuKKPi7SJLMBpUlV5O1V+4qPozCQZbWg==",
"requires": {
"@oceanprotocol/keeper-contracts": "^0.9.7",
"bignumber.js": "^8.1.1",
diff --git a/client/package.json b/client/package.json
index 1b1afb6..9a94407 100644
--- a/client/package.json
+++ b/client/package.json
@@ -13,7 +13,7 @@
},
"dependencies": {
"@oceanprotocol/art": "^2.2.0",
- "@oceanprotocol/squid": "^0.5.11",
+ "@oceanprotocol/squid": "^0.5.12",
"@oceanprotocol/typographies": "^0.1.0",
"@sindresorhus/slugify": "^0.9.1",
"axios": "^0.18.0",
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 a26c4cd..263f274 100644
--- a/client/src/components/templates/Asset/AssetFile.tsx
+++ b/client/src/components/templates/Asset/AssetFile.tsx
@@ -59,9 +59,22 @@ export default class AssetFile extends PureComponent<
const accounts = await ocean.accounts.list()
const service = ddo.findServiceByType('Access')
- const agreementId = await ocean.assets
- .order(ddo.id, service.serviceDefinitionId, accounts[0])
- .next((step: number) => this.setState({ step }))
+ 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)
+ } else {
+ agreementId = await ocean.assets
+ .order(ddo.id, service.serviceDefinitionId, accounts[0])
+ .next((step: number) => this.setState({ step }))
+ }
// manually add another step here for better UX
this.setState({ step: 4 })
@@ -81,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: ''
- }}
- >
+