1
0
mirror of https://github.com/oceanprotocol/commons.git synced 2023-03-15 18:03:00 +01:00

Merge pull request #148 from oceanprotocol/feature/dont-re-agreement

Reuse agreements on consume flow
This commit is contained in:
Matthias Kretschmann 2019-05-31 13:29:09 +02:00 committed by GitHub
commit 2d512f341e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
14 changed files with 93 additions and 103 deletions

View File

@ -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

View File

@ -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(),

View File

@ -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",

View File

@ -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",

View File

@ -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(<App />)
const { container } = render(
<User.Provider value={userMockConnected}>
<App />
</User.Provider>
)
expect(container.firstChild).toBeInTheDocument()
})

View File

@ -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(
<User.Provider value={userMockConnected}>
<Router>
<Routes />
</Router>
</User.Provider>
)
expect(container.firstChild).toBeInTheDocument()
})

View File

@ -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(
<User.Provider value={userMockConnected}>
<BrowserRouter>
<AssetsLatest />
</BrowserRouter>
</User.Provider>
)
expect(container.firstChild).toBeInTheDocument()
})

View File

@ -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(
<User.Provider value={userMockConnected}>
<BrowserRouter>
<ChannelTeaser channel="ai-for-good" />
</BrowserRouter>
</User.Provider>
)
expect(container.firstChild).toBeInTheDocument()
})

View File

@ -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(
<User.Provider value={contextConnectedMock}>
<User.Provider value={userMockConnected}>
<AssetFile file={file} ddo={ddo} />
</User.Provider>
)

View File

@ -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
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?`

View File

@ -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(
<User.Provider
value={{
isLogged: false,
isLoading: false,
isWeb3: false,
isOceanNetwork: false,
account: '',
web3: {},
ocean: {
aquarius: {
queryMetadata: () => {
return {
results: [],
totalResults: 1,
totalPages: 1
}
}
}
},
balance: { eth: 0, ocn: 0 },
network: '',
requestFromFaucet: () => {},
unlockAccounts: () => {},
message: ''
}}
>
<User.Provider value={userMockConnected}>
<Channel
match={{
params: { channel: 'ai-for-good' }

View File

@ -2,13 +2,17 @@ import React from 'react'
import { BrowserRouter as Router } from 'react-router-dom'
import { render } from 'react-testing-library'
import Channels from './Channels'
import { User } from '../context'
import { userMockConnected } from '../../__mocks__/user-mock'
describe('Channels', () => {
it('renders without crashing', () => {
const { container } = render(
<User.Provider value={userMockConnected}>
<Router>
<Channels />
</Router>
</User.Provider>
)
expect(container.firstChild).toBeInTheDocument()
})

View File

@ -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(
<User.Provider
value={{
isLogged: false,
isLoading: false,
isWeb3: false,
isOceanNetwork: false,
account: '',
web3: {},
ocean: {
aquarius: {
queryMetadata: () => {
return {
results: [],
totalResults: 1,
totalPages: 1
}
}
}
},
balance: { eth: 0, ocn: 0 },
network: '',
requestFromFaucet: () => {},
unlockAccounts: () => {},
message: ''
}}
>
<User.Provider value={userMockConnected}>
<Router>
<Search
location={{

View File

@ -19,7 +19,7 @@
},
{
"name": "squid-js",
"version": "~0.5.11"
"version": "~0.5.12"
},
{
"name": "faucet",