From 09c2f9f81864496159326b6608d1aac68d0fbdd2 Mon Sep 17 00:00:00 2001 From: Matthias Kretschmann Date: Wed, 29 Jan 2020 14:38:44 +0100 Subject: [PATCH] test fixes --- integration/utils/ddo-metadata-generator.ts | 2 +- src/ocean/OceanAgreements.ts | 3 ++- src/ocean/utils/ServiceUtils.ts | 12 +++++++----- test/{testdata => __fixtures__}/ddo.json | 0 test/{mocks => __mocks__}/Aquarius.mock.ts | 0 test/{mocks => __mocks__}/Brizo.mock.ts | 0 test/{mocks => __mocks__}/ContractBase.Mock.ts | 0 test/{mocks => __mocks__}/SecretStore.mock.ts | 0 .../{mocks => __mocks__}/WebServiceConnector.mock.ts | 0 test/ddo/DDO.test.ts | 2 +- test/keeper/ContractBase.test.ts | 2 +- 11 files changed, 12 insertions(+), 9 deletions(-) rename test/{testdata => __fixtures__}/ddo.json (100%) rename test/{mocks => __mocks__}/Aquarius.mock.ts (100%) rename test/{mocks => __mocks__}/Brizo.mock.ts (100%) rename test/{mocks => __mocks__}/ContractBase.Mock.ts (100%) rename test/{mocks => __mocks__}/SecretStore.mock.ts (100%) rename test/{mocks => __mocks__}/WebServiceConnector.mock.ts (100%) diff --git a/integration/utils/ddo-metadata-generator.ts b/integration/utils/ddo-metadata-generator.ts index 9898897..66e4299 100644 --- a/integration/utils/ddo-metadata-generator.ts +++ b/integration/utils/ddo-metadata-generator.ts @@ -1,6 +1,6 @@ import { MetaData, MetaDataAlgorithm } from '../../src' // @oceanprotocol/squid import { ServiceType } from '../../src/ddo/Service' -import ddoExample from '../../test/testdata/ddo.json' +import ddoExample from '../../test/__fixtures__/ddo.json' const metadata: Partial = { main: { diff --git a/src/ocean/OceanAgreements.ts b/src/ocean/OceanAgreements.ts index 8cf8247..c853248 100644 --- a/src/ocean/OceanAgreements.ts +++ b/src/ocean/OceanAgreements.ts @@ -7,6 +7,7 @@ import { AgreementConditionsStatus } from '../keeper/contracts/templates/Agreeme import { ConditionState } from '../keeper/contracts/conditions/Condition.abstract' import { OceanAgreementsConditions } from './OceanAgreementsConditions' +import { Service } from '../ddo/Service' export interface AgreementPrepareResult { agreementId: string @@ -121,7 +122,7 @@ export class OceanAgreements extends Instantiable { ) { const d: DID = DID.parse(did) const ddo = await this.ocean.aquarius.retrieveDDO(d) - const service = ddo.findServiceById(index) + const service: Service = ddo.findServiceById(index) const templateName = service.attributes.serviceAgreementTemplate.contractName return this.ocean.keeper .getTemplateByName(templateName) diff --git a/src/ocean/utils/ServiceUtils.ts b/src/ocean/utils/ServiceUtils.ts index b46f1c1..f499757 100644 --- a/src/ocean/utils/ServiceUtils.ts +++ b/src/ocean/utils/ServiceUtils.ts @@ -3,7 +3,7 @@ import Account from '../Account' import { zeroX, Logger, generateId } from '../../utils' import { Ocean } from '../../squid' import { Condition } from '../../keeper/contracts/conditions' -import { ServiceType } from '../../ddo/Service' +import { ServiceType, Service } from '../../ddo/Service' export enum OrderProgressStep { CreatingAgreement, @@ -32,16 +32,18 @@ export class ServiceUtils { const { keeper, agreements } = this.ocean const agreementId = zeroX(generateId()) - const { index, attributes } = ddo.findServiceByType(type) + const service: Service = ddo.findServiceByType(type) const metadata = ddo.findServiceByType('metadata') - const templateName = attributes.serviceAgreementTemplate.contractName + const templateName = service.attributes.serviceAgreementTemplate.contractName const template = keeper.getTemplateByName(templateName) // use price from compute service, // otherwise always take the price from metadata const price = - type === 'compute' ? attributes.main.price : metadata.attributes.main.price + type === 'compute' + ? service.attributes.main.price + : metadata.attributes.main.price // eslint-disable-next-line no-async-promise-executor const paymentFlow = new Promise(async (resolve, reject) => { @@ -94,7 +96,7 @@ export class ServiceUtils { await agreements.create( ddo.id, agreementId, - index, + service.index, undefined, consumerAccount, _provider, diff --git a/test/testdata/ddo.json b/test/__fixtures__/ddo.json similarity index 100% rename from test/testdata/ddo.json rename to test/__fixtures__/ddo.json diff --git a/test/mocks/Aquarius.mock.ts b/test/__mocks__/Aquarius.mock.ts similarity index 100% rename from test/mocks/Aquarius.mock.ts rename to test/__mocks__/Aquarius.mock.ts diff --git a/test/mocks/Brizo.mock.ts b/test/__mocks__/Brizo.mock.ts similarity index 100% rename from test/mocks/Brizo.mock.ts rename to test/__mocks__/Brizo.mock.ts diff --git a/test/mocks/ContractBase.Mock.ts b/test/__mocks__/ContractBase.Mock.ts similarity index 100% rename from test/mocks/ContractBase.Mock.ts rename to test/__mocks__/ContractBase.Mock.ts diff --git a/test/mocks/SecretStore.mock.ts b/test/__mocks__/SecretStore.mock.ts similarity index 100% rename from test/mocks/SecretStore.mock.ts rename to test/__mocks__/SecretStore.mock.ts diff --git a/test/mocks/WebServiceConnector.mock.ts b/test/__mocks__/WebServiceConnector.mock.ts similarity index 100% rename from test/mocks/WebServiceConnector.mock.ts rename to test/__mocks__/WebServiceConnector.mock.ts diff --git a/test/ddo/DDO.test.ts b/test/ddo/DDO.test.ts index 3747834..001d419 100644 --- a/test/ddo/DDO.test.ts +++ b/test/ddo/DDO.test.ts @@ -7,7 +7,7 @@ import { Ocean } from '../../src/ocean/Ocean' import config from '../config' import TestContractHandler from '../keeper/TestContractHandler' -import * as jsonDDO from '../testdata/ddo.json' +import * as jsonDDO from '../__fixtures__/ddo.json' use(spies) diff --git a/test/keeper/ContractBase.test.ts b/test/keeper/ContractBase.test.ts index 53bc69b..e70afa8 100644 --- a/test/keeper/ContractBase.test.ts +++ b/test/keeper/ContractBase.test.ts @@ -2,7 +2,7 @@ import { assert } from 'chai' import Account from '../../src/ocean/Account' import { Ocean } from '../../src/ocean/Ocean' import config from '../config' -import ContractBaseMock from '../mocks/ContractBase.Mock' +import ContractBaseMock from '../__mocks__/ContractBase.Mock' import TestContractHandler from './TestContractHandler' const wrappedContract = new ContractBaseMock('OceanToken')