diff --git a/src/experimental/new-api/deployment.ts b/src/experimental/new-api/deployment.ts index 5aa2681a8..d51854f9e 100644 --- a/src/experimental/new-api/deployment.ts +++ b/src/experimental/new-api/deployment.ts @@ -171,7 +171,7 @@ export class Deployment { const proposalSubscription = this.modules.market .startCollectingProposals({ - demandSpecification: demandSpecification, + demandSpecification, bufferSize: 10, }) .subscribe({ diff --git a/src/golem-network.ts b/src/golem-network.ts index 4789f4579..88b213b83 100644 --- a/src/golem-network.ts +++ b/src/golem-network.ts @@ -241,7 +241,7 @@ export class GolemNetwork { const proposalSubscription = this.market .startCollectingProposals({ - demandSpecification: demandSpecification, + demandSpecification, }) .subscribe((proposalsBatch) => proposalsBatch.forEach((proposal) => proposalPool.add(proposal))); diff --git a/src/market/demand.ts b/src/market/demand.ts index 445310e99..fe2b4e6f9 100644 --- a/src/market/demand.ts +++ b/src/market/demand.ts @@ -1,7 +1,7 @@ import { ActivityDemandDirectorConfigOptions } from "./demand/options"; import { BasicDemandDirectorConfigOptions } from "./demand/directors/basic-demand-director-config"; import { PaymentDemandDirectorConfigOptions } from "./demand/directors/payment-demand-director-config"; -import { DemandBodyPrototype } from "./demand/demand-details-builder"; +import { DemandBodyPrototype } from "./demand/demand-body-builder"; /** * This type represents a set of *parameters* that the SDK can set to particular *properties* and *constraints* diff --git a/src/market/demand/demand-details-builder.ts b/src/market/demand/demand-body-builder.ts similarity index 99% rename from src/market/demand/demand-details-builder.ts rename to src/market/demand/demand-body-builder.ts index dbb5004bd..dfafcf1a6 100644 --- a/src/market/demand/demand-details-builder.ts +++ b/src/market/demand/demand-body-builder.ts @@ -53,7 +53,7 @@ export enum ComparisonOperator { * * Demand -> DemandSpecification -> DemandPrototype -> DemandDTO */ -export class DemandDetailsBuilder { +export class DemandBodyBuilder { private properties: Array = []; private constraints: Array = []; diff --git a/src/market/demand/directors/activity-demand-director.test.ts b/src/market/demand/directors/activity-demand-director.test.ts index 4f2ec21ee..8fe2b083e 100644 --- a/src/market/demand/directors/activity-demand-director.test.ts +++ b/src/market/demand/directors/activity-demand-director.test.ts @@ -1,10 +1,10 @@ -import { DemandDetailsBuilder } from "../demand-details-builder"; +import { DemandBodyBuilder } from "../demand-body-builder"; import { ActivityDemandDirector } from "./activity-demand-director"; import { ActivityDemandDirectorConfig } from "./activity-demand-director-config"; describe("ActivityDemandDirector", () => { test("should create properties with task_package and package_format", async () => { - const builder = new DemandDetailsBuilder(); + const builder = new DemandBodyBuilder(); const director = new ActivityDemandDirector( new ActivityDemandDirectorConfig({ @@ -28,7 +28,7 @@ describe("ActivityDemandDirector", () => { }); test("should create package with manifest decorations", async () => { - const builder = new DemandDetailsBuilder(); + const builder = new DemandBodyBuilder(); const manifest = "XNBdCI6ICIyMTAwLTAxLTAxVDAwOjAxOjAwLjAwMDAwMFoiLAogICJtZXRhZGF0YSI6IHsKICAgICJuYW1lI="; const manifestSig = "GzbdJDaW6FTajVYCKKZZvwpwVNBK3o40r/okna87wV9CVWW0+WUFwe="; diff --git a/src/market/demand/directors/activity-demand-director.ts b/src/market/demand/directors/activity-demand-director.ts index 706ea3446..c89256e16 100644 --- a/src/market/demand/directors/activity-demand-director.ts +++ b/src/market/demand/directors/activity-demand-director.ts @@ -1,5 +1,5 @@ import { ActivityDemandDirectorConfig } from "./activity-demand-director-config"; -import { ComparisonOperator, DemandDetailsBuilder } from "../demand-details-builder"; +import { ComparisonOperator, DemandBodyBuilder } from "../demand-body-builder"; import { GolemError, GolemPlatformError } from "../../../shared/error/golem-error"; import { IDemandDirector } from "../../market.module"; import { EnvUtils } from "../../../shared/utils"; @@ -7,7 +7,7 @@ import { EnvUtils } from "../../../shared/utils"; export class ActivityDemandDirector implements IDemandDirector { constructor(private config: ActivityDemandDirectorConfig) {} - public async apply(builder: DemandDetailsBuilder) { + public async apply(builder: DemandBodyBuilder) { builder .addProperty("golem.srv.comp.vm.package_format", this.config.packageFormat) .addConstraint("golem.runtime.name", this.config.engine); @@ -75,7 +75,7 @@ export class ActivityDemandDirector implements IDemandDirector { } } - private addManifestDecorations(builder: DemandDetailsBuilder): void { + private addManifestDecorations(builder: DemandBodyBuilder): void { if (!this.config.manifest) return; builder.addProperty("golem.srv.comp.payload", this.config.manifest); if (this.config.manifestSig) builder.addProperty("golem.srv.comp.payload.sig", this.config.manifestSig); diff --git a/src/market/demand/directors/basic-demand-director.ts b/src/market/demand/directors/basic-demand-director.ts index cec05f1df..f6a8208d0 100644 --- a/src/market/demand/directors/basic-demand-director.ts +++ b/src/market/demand/directors/basic-demand-director.ts @@ -1,11 +1,11 @@ -import { DemandDetailsBuilder } from "../demand-details-builder"; +import { DemandBodyBuilder } from "../demand-body-builder"; import { IDemandDirector } from "../../market.module"; import { BasicDemandDirectorConfig } from "./basic-demand-director-config"; export class BasicDemandDirector implements IDemandDirector { constructor(private config: BasicDemandDirectorConfig = new BasicDemandDirectorConfig()) {} - apply(builder: DemandDetailsBuilder) { + apply(builder: DemandBodyBuilder) { builder .addProperty("golem.srv.caps.multi-activity", true) .addProperty("golem.srv.comp.expiration", Date.now() + this.config.expirationSec * 1000) diff --git a/src/market/demand/directors/payment-demand-director.ts b/src/market/demand/directors/payment-demand-director.ts index 621b0d03f..d621af625 100644 --- a/src/market/demand/directors/payment-demand-director.ts +++ b/src/market/demand/directors/payment-demand-director.ts @@ -1,5 +1,5 @@ import { PayerDetails } from "../../../payment/PayerDetails"; -import { ComparisonOperator, DemandDetailsBuilder } from "../demand-details-builder"; +import { ComparisonOperator, DemandBodyBuilder } from "../demand-body-builder"; import { IDemandDirector } from "../../market.module"; import { PaymentDemandDirectorConfig } from "./payment-demand-director-config"; @@ -9,7 +9,7 @@ export class PaymentDemandDirector implements IDemandDirector { private config: PaymentDemandDirectorConfig = new PaymentDemandDirectorConfig(), ) {} - apply(builder: DemandDetailsBuilder) { + apply(builder: DemandBodyBuilder) { // Configure mid-agreement payments builder .addProperty("golem.com.scheme.payu.debit-note.interval-sec?", this.config.midAgreementDebitNoteIntervalSec) diff --git a/src/market/market.module.test.ts b/src/market/market.module.test.ts index 91126ee5e..53ce4dd65 100644 --- a/src/market/market.module.test.ts +++ b/src/market/market.module.test.ts @@ -68,24 +68,54 @@ describe("Market module", () => { "(golem.inf.cpu.threads>=1)", "(golem.com.payment.platform.erc20-holesky-tglm.address=*)", "(golem.com.payment.protocol.version>1)", - ].join("\n\t"); + ]; - const expectedProperties = { - "golem.srv.comp.vm.package_format": "gvmkit-squash", - "golem.srv.comp.task_package": "hash:sha3:AAAAHASHAAAA:https://custom.image.url/", - "golem.com.payment.platform.erc20-holesky-tglm.address": "0x123", - "golem.com.payment.protocol.version": "2", - "golem.srv.caps.multi-activity": true, - "golem.srv.comp.expiration": Date.now() + 42 * 1000, - "golem.node.debug.subnet": "public", - "golem.com.payment.debit-notes.accept-timeout?": 42, - "golem.com.scheme.payu.debit-note.interval-sec?": 42, - "golem.com.scheme.payu.payment-timeout-sec?": 42, - }; + const expectedProperties = [ + { + key: "golem.srv.caps.multi-activity", + value: true, + }, + { + key: "golem.srv.comp.expiration", + value: Date.now() + 42 * 1000, + }, + { + key: "golem.node.debug.subnet", + value: "public", + }, + { + key: "golem.srv.comp.vm.package_format", + value: "gvmkit-squash", + }, + { + key: "golem.srv.comp.task_package", + value: "hash:sha3:AAAAHASHAAAA:https://custom.image.url/", + }, + { + key: "golem.com.scheme.payu.debit-note.interval-sec?", + value: 42, + }, + { + key: "golem.com.scheme.payu.payment-timeout-sec?", + value: 42, + }, + { + key: "golem.com.payment.debit-notes.accept-timeout?", + value: 42, + }, + { + key: "golem.com.payment.platform.erc20-holesky-tglm.address", + value: "0x123", + }, + { + key: "golem.com.payment.protocol.version", + value: "2", + }, + ]; expect(demandSpecification.paymentPlatform).toBe(payerDetails.getPaymentPlatform()); expect(demandSpecification.expirationSec).toBe(42); - expect(demandSpecification.prototype.constraints).toEqual(`(&${expectedConstraints})`); + expect(demandSpecification.prototype.constraints).toEqual(expect.arrayContaining(expectedConstraints)); expect(demandSpecification.prototype.properties).toEqual(expectedProperties); }); }); @@ -293,7 +323,7 @@ describe("Market module", () => { const draftProposals: ProposalNew[] = []; marketModule .startCollectingProposals({ - demandSpecification: demandSpecification, + demandSpecification, bufferSize: 1, proposalsBatchReleaseTimeoutMs: 10, }) @@ -390,7 +420,7 @@ describe("Market module", () => { const draftProposals: ProposalNew[] = []; marketModule .startCollectingProposals({ - demandSpecification: demandSpecification, + demandSpecification, bufferSize: 1, proposalsBatchReleaseTimeoutMs: 10, }) diff --git a/src/market/market.module.ts b/src/market/market.module.ts index c15b9123a..efd36180f 100644 --- a/src/market/market.module.ts +++ b/src/market/market.module.ts @@ -13,7 +13,7 @@ import { defaultLogger, Logger, YagnaApi } from "../shared/utils"; import { Allocation } from "../payment"; import { bufferTime, filter, map, Observable, OperatorFunction, switchMap, tap } from "rxjs"; import { IProposalRepository, ProposalFilterNew, ProposalNew } from "./proposal"; -import { DemandDetailsBuilder } from "./demand/demand-details-builder"; +import { DemandBodyBuilder } from "./demand/demand-body-builder"; import { IAgreementApi } from "../agreement/agreement"; import { BuildDemandOptions, DemandSpecification, IDemandRepository } from "./demand"; import { ProposalsBatch } from "./proposals_batch"; @@ -168,7 +168,7 @@ export interface MarketModule { * all the final demand request body properties in a more controlled and organized manner. */ export interface IDemandDirector { - apply(builder: DemandDetailsBuilder): Promise | void; + apply(builder: DemandBodyBuilder): Promise | void; } export class MarketModuleImpl implements MarketModule { @@ -206,7 +206,7 @@ export class MarketModuleImpl implements MarketModule { } async buildDemandDetails(options: BuildDemandOptions, payerDetails: PayerDetails): Promise { - const builder = new DemandDetailsBuilder(); + const builder = new DemandBodyBuilder(); // Instruct the builder what's required const basicConfig = new BasicDemandDirectorConfig(options.basic); diff --git a/src/market/proposal.ts b/src/market/proposal.ts index 2cfdb5931..169e67d6e 100644 --- a/src/market/proposal.ts +++ b/src/market/proposal.ts @@ -4,7 +4,7 @@ import { ProviderInfo } from "../agreement"; import { Demand } from "./demand"; import { withTimeout } from "../shared/utils/timeout"; import { EventEmitter } from "eventemitter3"; -import { DemandBodyPrototype, DemandPropertyValue } from "./demand/demand-details-builder"; +import { DemandBodyPrototype, DemandPropertyValue } from "./demand/demand-body-builder"; import { DemandRequestBody } from "../shared/yagna"; export type ProposalFilterNew = (proposal: ProposalNew) => boolean; diff --git a/src/shared/yagna/adapters/market-api-adapter.test.ts b/src/shared/yagna/adapters/market-api-adapter.test.ts index 8403ba3ee..01f625748 100644 --- a/src/shared/yagna/adapters/market-api-adapter.test.ts +++ b/src/shared/yagna/adapters/market-api-adapter.test.ts @@ -1,10 +1,11 @@ import { instance, when, verify, deepEqual, mock, reset, _, imock } from "@johanblumenberg/ts-mockito"; import * as YaTsClient from "ya-ts-client"; import { YagnaApi } from "../yagnaApi"; -import { MarketApiAdapter } from "./market-api-adapter"; +import { DemandRequestBody, MarketApiAdapter } from "./market-api-adapter"; import { Demand, DemandSpecification, ProposalNew } from "../../../market"; import { take, takeUntil, timer } from "rxjs"; import { Logger } from "../../utils"; +import { DemandBodyPrototype } from "../../../market/demand/demand-body-builder"; const mockMarket = mock(YaTsClient.MarketApi.RequestorService); const mockYagna = mock(YagnaApi); @@ -19,43 +20,46 @@ beforeEach(() => { }); describe("Market Api Adapter", () => { + const samplePrototype: DemandBodyPrototype = { + constraints: ["constraints"], + properties: [ + { + key: "property-key-1", + value: "property-value-1", + }, + { + key: "property-key-2", + value: "property-value-2", + }, + ], + }; + + const expectedBody: DemandRequestBody = { + constraints: "constraints", + properties: { + "property-key-1": "property-value-1", + "property-key-2": "property-value-2", + }, + }; + describe("publishDemandSpecification()", () => { it("should publish a demand", async () => { - const specification = new DemandSpecification( - { - constraints: "constraints", - properties: { - "property-key-1": "property-value-1", - "property-key-2": "property-value-2", - }, - }, - "my-selected-payment-platform", - 60 * 60 * 1000, - ); + const specification = new DemandSpecification(samplePrototype, "my-selected-payment-platform", 60 * 60 * 1000); - when(mockMarket.subscribeDemand(deepEqual(specification.prototype))).thenResolve("demand-id"); + when(mockMarket.subscribeDemand(deepEqual(expectedBody))).thenResolve("demand-id"); const demand = await api.publishDemandSpecification(specification); - verify(mockMarket.subscribeDemand(deepEqual(specification.prototype))).once(); + verify(mockMarket.subscribeDemand(deepEqual(expectedBody))).once(); expect(demand).toBeInstanceOf(Demand); expect(demand.id).toBe("demand-id"); expect(demand.details).toBe(specification); }); + it("should throw an error if the demand is not published", async () => { - const specification = new DemandSpecification( - { - constraints: "constraints", - properties: { - "property-key-1": "property-value-1", - "property-key-2": "property-value-2", - }, - }, - "my-selected-payment-platform", - 60 * 60 * 1000, - ); + const specification = new DemandSpecification(samplePrototype, "my-selected-payment-platform", 60 * 60 * 1000); - when(mockMarket.subscribeDemand(deepEqual(specification.prototype))).thenResolve({ + when(mockMarket.subscribeDemand(deepEqual(expectedBody))).thenResolve({ message: "error publishing demand", }); @@ -69,17 +73,7 @@ describe("Market Api Adapter", () => { it("should unpublish a demand", async () => { const demand = new Demand( "demand-id", - new DemandSpecification( - { - constraints: "constraints", - properties: { - "property-key-1": "property-value-1", - "property-key-2": "property-value-2", - }, - }, - "my-selected-payment-platform", - 60 * 60 * 1000, - ), + new DemandSpecification(samplePrototype, "my-selected-payment-platform", 60 * 60 * 1000), ); when(mockMarket.unsubscribeDemand("demand-id")).thenResolve({}); @@ -92,17 +86,7 @@ describe("Market Api Adapter", () => { it("should throw an error if the demand is not unpublished", async () => { const demand = new Demand( "demand-id", - new DemandSpecification( - { - constraints: "constraints", - properties: { - "property-key-1": "property-value-1", - "property-key-2": "property-value-2", - }, - }, - "my-selected-payment-platform", - 60 * 60 * 1000, - ), + new DemandSpecification(samplePrototype, "my-selected-payment-platform", 60 * 60 * 1000), ); when(mockMarket.unsubscribeDemand("demand-id")).thenResolve({ @@ -117,20 +101,11 @@ describe("Market Api Adapter", () => { describe("counterProposal()", () => { it("should negotiate a proposal with the selected payment platform", async () => { - const specification = new DemandSpecification( - { - constraints: "constraints", - properties: { - "property-key-1": "property-value-1", - "property-key-2": "property-value-2", - }, - }, - "my-selected-payment-platform", - 60 * 60 * 1000, - ); + const specification = new DemandSpecification(samplePrototype, "my-selected-payment-platform", 60 * 60 * 1000); + const receivedProposal = new ProposalNew( { - ...specification.prototype, + ...expectedBody, proposalId: "proposal-id", timestamp: "0000-00-00", issuerId: "issuer-id", @@ -142,7 +117,7 @@ describe("Market Api Adapter", () => { when(mockMarket.counterProposalDemand(_, _, _)).thenResolve("counter-id"); when(mockMarket.getProposalOffer("demand-id", "counter-id")).thenResolve({ - ...specification.prototype, + ...expectedBody, proposalId: "counter-id", timestamp: "0000-00-00", issuerId: "issuer-id", @@ -170,20 +145,10 @@ describe("Market Api Adapter", () => { expect(counterProposal.demand).toBe(receivedProposal.demand); }); it("should throw an error if the counter proposal fails", async () => { - const specification = new DemandSpecification( - { - constraints: "constraints", - properties: { - "property-key-1": "property-value-1", - "property-key-2": "property-value-2", - }, - }, - "my-selected-payment-platform", - 60 * 60 * 1000, - ); + const specification = new DemandSpecification(samplePrototype, "my-selected-payment-platform", 60 * 60 * 1000); const receivedProposal = new ProposalNew( { - ...specification.prototype, + ...expectedBody, proposalId: "proposal-id", timestamp: "0000-00-00", issuerId: "issuer-id", diff --git a/src/shared/yagna/adapters/market-api-adapter.ts b/src/shared/yagna/adapters/market-api-adapter.ts index b5e3c37ff..d954d23a6 100644 --- a/src/shared/yagna/adapters/market-api-adapter.ts +++ b/src/shared/yagna/adapters/market-api-adapter.ts @@ -4,7 +4,7 @@ import { YagnaApi } from "../yagnaApi"; import YaTsClient from "ya-ts-client"; import { GolemInternalError } from "../../error/golem-error"; import { Logger } from "../../utils"; -import { DemandBodyPrototype, DemandPropertyValue } from "../../../market/demand/demand-details-builder"; +import { DemandBodyPrototype, DemandPropertyValue } from "../../../market/demand/demand-body-builder"; /** * A bit more user-friendly type definition of DemandOfferBaseDTO from ya-ts-client diff --git a/tests/unit/decorations_builder.test.ts b/tests/unit/decorations_builder.test.ts index 1d52bd017..ecff29aa6 100644 --- a/tests/unit/decorations_builder.test.ts +++ b/tests/unit/decorations_builder.test.ts @@ -1,60 +1,60 @@ -import { ComparisonOperator, DemandDetailsBuilder } from "../../src/market/demand/demand-details-builder"; +import { ComparisonOperator, DemandBodyBuilder } from "../../src/market/demand/demand-body-builder"; import { GolemInternalError } from "../../src/shared/error/golem-error"; describe("#DecorationsBuilder()", () => { describe("addProperty()", () => { it("should allow to add property", () => { - const decorationsBuilder = new DemandDetailsBuilder(); - decorationsBuilder.addProperty("key", "value"); - expect(decorationsBuilder.getProduct().properties.length).toEqual(1); + const builder = new DemandBodyBuilder(); + builder.addProperty("key", "value"); + expect(builder.getProduct().properties.length).toEqual(1); }); it("should replace already existing property", () => { - const decorationsBuilder = new DemandDetailsBuilder(); - decorationsBuilder.addProperty("key", "value").addProperty("key", "value2"); - expect(decorationsBuilder.getProduct().properties.length).toEqual(1); - expect(decorationsBuilder.getProduct().properties[0].value).toEqual("value2"); + const builder = new DemandBodyBuilder(); + builder.addProperty("key", "value").addProperty("key", "value2"); + expect(builder.getProduct().properties.length).toEqual(1); + expect(builder.getProduct().properties[0].value).toEqual("value2"); }); it("should provide fluent API", () => { - const decorationsBuilder = new DemandDetailsBuilder(); - const flAPI = decorationsBuilder.addProperty("key", "value"); - expect(flAPI).toBeInstanceOf(DemandDetailsBuilder); + const builder = new DemandBodyBuilder(); + const flAPI = builder.addProperty("key", "value"); + expect(flAPI).toBeInstanceOf(DemandBodyBuilder); }); }); describe("addConstraint()", () => { it("should allow to add constrain", () => { - const decorationsBuilder = new DemandDetailsBuilder(); - decorationsBuilder.addConstraint("key", "value"); - expect(decorationsBuilder.getProduct().constraints.length).toEqual(1); + const builder = new DemandBodyBuilder(); + builder.addConstraint("key", "value"); + expect(builder.getProduct().constraints.length).toEqual(1); }); it("should allow to add constrain with >=", () => { - const decorationsBuilder = new DemandDetailsBuilder(); - decorationsBuilder.addConstraint("key", "value", ComparisonOperator.GtEq); - expect(decorationsBuilder.getProduct().constraints.length).toEqual(1); + const builder = new DemandBodyBuilder(); + builder.addConstraint("key", "value", ComparisonOperator.GtEq); + expect(builder.getProduct().constraints.length).toEqual(1); }); it("should allow to add constrain with <=", () => { - const decorationsBuilder = new DemandDetailsBuilder(); - decorationsBuilder.addConstraint("key", "value", ComparisonOperator.LtEq); - expect(decorationsBuilder.getProduct().constraints.length).toEqual(1); + const builder = new DemandBodyBuilder(); + builder.addConstraint("key", "value", ComparisonOperator.LtEq); + expect(builder.getProduct().constraints.length).toEqual(1); }); it("should allow to add constrain with >", () => { - const decorationsBuilder = new DemandDetailsBuilder(); - decorationsBuilder.addConstraint("key", "value", ComparisonOperator.Gt); - expect(decorationsBuilder.getProduct().constraints.length).toEqual(1); + const builder = new DemandBodyBuilder(); + builder.addConstraint("key", "value", ComparisonOperator.Gt); + expect(builder.getProduct().constraints.length).toEqual(1); }); it("should allow to add constrain with <", () => { - const decorationsBuilder = new DemandDetailsBuilder(); - decorationsBuilder.addConstraint("key", "value", ComparisonOperator.Lt); - expect(decorationsBuilder.getProduct().constraints.length).toEqual(1); + const builder = new DemandBodyBuilder(); + builder.addConstraint("key", "value", ComparisonOperator.Lt); + expect(builder.getProduct().constraints.length).toEqual(1); }); it("should allow to add constrain with =", () => { - const decorationsBuilder = new DemandDetailsBuilder(); - decorationsBuilder.addConstraint("key", "value", ComparisonOperator.Eq); - expect(decorationsBuilder.getProduct().constraints.length).toEqual(1); + const builder = new DemandBodyBuilder(); + builder.addConstraint("key", "value", ComparisonOperator.Eq); + expect(builder.getProduct().constraints.length).toEqual(1); }); it("should provide fluent API", () => { - const decorationsBuilder = new DemandDetailsBuilder(); - const flAPI = decorationsBuilder.addConstraint("key", "value"); - expect(flAPI).toBeInstanceOf(DemandDetailsBuilder); + const builder = new DemandBodyBuilder(); + const flAPI = builder.addConstraint("key", "value"); + expect(flAPI).toBeInstanceOf(DemandBodyBuilder); }); }); describe("addDecorations()", () => { @@ -69,9 +69,9 @@ describe("#DecorationsBuilder()", () => { ], properties: [], }; - const decorationsBuilder = new DemandDetailsBuilder(); - decorationsBuilder.mergePrototype(decoration); - expect(decorationsBuilder.getProduct().constraints.length).toEqual(5); + const builder = new DemandBodyBuilder(); + builder.mergePrototype(decoration); + expect(builder.getProduct().constraints.length).toEqual(5); }); it("should allow to add decorations", () => { @@ -79,19 +79,19 @@ describe("#DecorationsBuilder()", () => { properties: [{ key: "prop_key", value: "value" }], constraints: ["some_constraint=some_value"], }; - const decorationsBuilder = new DemandDetailsBuilder(); - decorationsBuilder.mergePrototype(decoration); - expect(decorationsBuilder.getProduct().constraints.length).toEqual(1); - expect(decorationsBuilder.getProduct().properties.length).toEqual(1); + const builder = new DemandBodyBuilder(); + builder.mergePrototype(decoration); + expect(builder.getProduct().constraints.length).toEqual(1); + expect(builder.getProduct().properties.length).toEqual(1); }); it("should provide fluent API", () => { const decoration = { properties: [{ key: "prop_key", value: "value" }], constraints: ["some_constraint=some_value"], }; - const decorationsBuilder = new DemandDetailsBuilder(); - const flAPI = decorationsBuilder.mergePrototype(decoration); - expect(flAPI).toBeInstanceOf(DemandDetailsBuilder); + const builder = new DemandBodyBuilder(); + const flAPI = builder.mergePrototype(decoration); + expect(flAPI).toBeInstanceOf(DemandBodyBuilder); }); it("should not allow to add invalid decorations", () => { @@ -99,16 +99,16 @@ describe("#DecorationsBuilder()", () => { properties: [{ key: "prop_key", value: "value" }], constraints: ["some_invalid_constraint"], }; - const decorationsBuilder = new DemandDetailsBuilder(); - expect(() => decorationsBuilder.mergePrototype(decoration)).toThrow( + const builder = new DemandBodyBuilder(); + expect(() => builder.mergePrototype(decoration)).toThrow( new GolemInternalError('Unable to parse constraint "some_invalid_constraint"'), ); }); }); describe("getDecorations()", () => { it("should return correct decoration", () => { - const decorationsBuilder = new DemandDetailsBuilder(); - decorationsBuilder + const builder = new DemandBodyBuilder(); + builder .addConstraint("key", "value", ComparisonOperator.Eq) .addConstraint("key", "value", ComparisonOperator.GtEq) .addConstraint("key", "value", ComparisonOperator.LtEq) @@ -117,10 +117,10 @@ describe("#DecorationsBuilder()", () => { .addProperty("key", "value") .addProperty("key2", "value"); - expect(decorationsBuilder.getProduct().constraints.length).toEqual(5); - expect(decorationsBuilder.getProduct().properties.length).toEqual(2); + expect(builder.getProduct().constraints.length).toEqual(5); + expect(builder.getProduct().properties.length).toEqual(2); - expect(decorationsBuilder.getProduct().constraints).toEqual([ + expect(builder.getProduct().constraints).toEqual([ "(key=value)", "(key>=value)", "(key<=value)", @@ -128,7 +128,7 @@ describe("#DecorationsBuilder()", () => { "(key