Untitled
unknown
javascript
2 years ago
25 kB
4
Indexable
Never
const { TestUtils } = require("usy_durom_commong01-test").Utils; const BusinessValidationHelper = require("./business-validations-test-helper"); const { TimeService } = require("usy_durom_commong01-time"); const TestData = require("./test-data/validate-auction-bid-test-data"); const CMD = "auctionBid/store"; let uri, awid, dtoIn, AuctionBidStoreValidator, AuctionBidValidators, MasterDataService, CcmService, MasterConfigurationService, TsDataService, AuctionBidStoreValidatorAuctionDaoGet, MasterDataAuctionParticipant, MasterConfigurationServiceMock, AuctionBidStoreValidatiorAuctionBidDaoGetOneByCriteriaMock; beforeAll(async () => { await TestUtils.setup(); uri = TestUtils.getCmdUri(CMD); awid = uri.getAwid(); AuctionBidStoreValidator = require("../../../app/components/business-validation/validators/auction-bid/store-validator"); AuctionBidValidators = require("../../../app/components/business-validation/validators/auction-bid"); CcmService = require("usy_durom_commong01-ccm").CcmService; MasterDataService = require("usy_durom_commong01-masterdata").MasterDataService; MasterConfigurationService = require("usy_durom_commong01-masterdata").MasterConfigurationService; TsDataService = require("usy_durom_commong01-time_series").TsDataService; }); beforeEach(async () => { dtoIn = TestData.dtoIn; jest.resetAllMocks(); AuctionBidStoreValidatorAuctionDaoGet = jest .spyOn(AuctionBidStoreValidator.auctionDao, "getOneByCriteria") .mockResolvedValue(TestData.auction); jest.spyOn(CcmService, "listMarketParticipant").mockResolvedValue(TestData.listMarketParticipant); MasterDataAuctionParticipant = jest .spyOn(MasterDataService, "getMasterDataAsObject") .mockResolvedValue(TestData.auctionParticipant); MasterConfigurationServiceMock = jest .spyOn(MasterConfigurationService, "get") .mockReturnValue("businessApplicationEIC"); AuctionBidStoreValidatiorAuctionBidDaoGetOneByCriteriaMock = jest .spyOn(AuctionBidStoreValidator.dao, "getOneByCriteria") .mockResolvedValue(TestData.auctionBid); jest.spyOn(AuctionBidStoreValidator.dao, "listByCriteria").mockResolvedValue(TestData.auctionBidList); jest.spyOn(TsDataService, "listData").mockResolvedValue(TestData.tsListData); }); afterAll(async () => { await TestUtils.teardown(); }); describe("Test of the AuctionBidValidators validateDomesticScheduleCommonMessage", () => { test("HDS", async () => { const response = await AuctionBidValidators.validateStore(uri, dtoIn, {}); assertAuctionBidAuctionDao(); assertCcmServiceListMarketParticipant(); assertAuctionParticipantMD(); assertTsDataServiceListData(); BusinessValidationHelper.assertAcceptedValidation(response.validation); }); it("fails with auctionDoesNotExist", async () => { AuctionBidStoreValidatorAuctionDaoGet.mockRestore(); jest.spyOn(AuctionBidStoreValidator.auctionDao, "getOneByCriteria").mockResolvedValue(undefined); const response = await AuctionBidValidators.validateStore(uri, dtoIn, {}); assertAuctionBidAuctionDao(); const expectedValidationMessageList = [ { code: "auctionDoesNotExist", title: "Auction does not exist.", message: "Auction does not exist.", }, ]; BusinessValidationHelper.assertFailedValidation(response.validation, expectedValidationMessageList); }); it("fails with notOpenBiddingGate", async () => { AuctionBidStoreValidatorAuctionDaoGet.mockRestore(); let auction = { ...TestData.auction }; auction.auctionState = "test"; jest.spyOn(AuctionBidStoreValidator.auctionDao, "getOneByCriteria").mockResolvedValue(auction); const response = await AuctionBidValidators.validateStore(uri, dtoIn, {}); const expectedValidationMessageList = [ { code: "notOpenBiddingGate", title: "Bidding Window not opened", message: "The bidding window is not open for the given auction.", }, ]; assertAuctionBidAuctionDao(); BusinessValidationHelper.assertFailedValidation(response.validation, expectedValidationMessageList); }); it("fails with marketParticipantIsNotAuctionParticipant", async () => { MasterDataAuctionParticipant.mockRestore(); jest.spyOn(MasterDataService, "getMasterDataAsObject").mockReturnValue(undefined); const response = await AuctionBidValidators.validateStore(uri, dtoIn, {}); let borderCode = TestData.auction.borderCode; let marketParticipantName = TestData.listMarketParticipant.itemList[1].name; const expectedValidationMessageList = [ { code: "marketParticipantIsNotAuctionParticipant", title: "Market Participant is not registered as Auction Participant for the Border", message: `The Market Participant ${marketParticipantName} is not registered as the Auction Participant for the Border ${borderCode}.`, params: { marketParticipantName, borderCode, }, }, ]; assertAuctionBidAuctionDao(); BusinessValidationHelper.assertFailedValidation(response.validation, expectedValidationMessageList); }); it("fails with marketParticipantIsNotAuthorizedToSubmitAuctionBids", async () => { MasterConfigurationServiceMock.mockRestore(); jest.spyOn(MasterConfigurationService, "get").mockResolvedValue(undefined); const response = await AuctionBidValidators.validateStore(uri, dtoIn, {}); let senderMarketParticipant = TestData.listMarketParticipant.itemList[0]; let senderEIC = senderMarketParticipant.eic; let marketParticipant = TestData.listMarketParticipant.itemList[1]; let { id: marketParticipantId, eic: marketParticipantEIC } = marketParticipant; const expectedValidationMessageList = [ { code: "marketParticipantIsNotAuthorizedToSubmitAuctionBids", title: "Sender is not authorized to submit bids for given Subject Party", message: `Sender ${senderMarketParticipant.name} (${senderEIC}) is not authorized to submit Auction Bids on behalf of Subject Party ${marketParticipantId} (${marketParticipantEIC}).`, params: { senderMarketParticipantEIC: senderEIC, marketParticipantEIC, marketParticipantId, }, }, ]; assertAuctionBidAuctionDao(); assertCcmServiceListMarketParticipant(); BusinessValidationHelper.assertFailedValidation(response.validation, expectedValidationMessageList); }); it("fails with documentCodeNotConsistent", async () => { AuctionBidStoreValidatiorAuctionBidDaoGetOneByCriteriaMock.mockRestore(); let auctionBid = TestData.auctionBidList; auctionBid.itemList[0].documentCode = "wrongDocumentCode"; jest.spyOn(AuctionBidStoreValidator.dao, "listByCriteria").mockResolvedValue(auctionBid); const response = await AuctionBidValidators.validateStore(uri, dtoIn, {}); let auctionCode = TestData.auction.code; const expectedValidationMessageList = [ { code: "documentCodeNotConsistent", title: "Document Code not consistent", message: `The Auction Bid document identification for the auction ${auctionCode} is not consistent with the one previously stored. The previously stored is ${auctionBid.itemList[0].documentCode}.`, params: { auction: auctionCode, previouslyStored: auctionBid.itemList[0].documentCode, }, }, ]; assertAuctionBidAuctionDao(); assertCcmServiceListMarketParticipant(); assertAuctionParticipantMD(); BusinessValidationHelper.assertFailedValidation(response.validation, expectedValidationMessageList); }); it("fails with bidTimeIntervalMustBeSubsequent", async () => { AuctionBidStoreValidatorAuctionDaoGet.mockRestore(); let auc = TestData.auction; auc.capacityContractTypeCode = "XX"; jest.spyOn(AuctionBidStoreValidator.auctionDao, "getOneByCriteria").mockResolvedValue(auc); let newDtoIn = JSON.parse(JSON.stringify(TestData.dtoIn)); newDtoIn.list[0].itemList[1] = { timeInterval: { from: "2021-11-18T00:00:00.000Z", to: "2021-11-18T01:00:00.000Z", }, requestedCapacity: 100, requestedPrice: 10.0, }; const response = await AuctionBidValidators.validateStore(uri, newDtoIn, {}); let bidIdentification = newDtoIn.list[0].bidIdentification; let code = newDtoIn.list[0].bidIdentification; const expectedValidationMessageList = [ { code: "bidTimeIntervalMustBeSubsequent", title: "Bid time series interval is not subsequent", message: `The bid with ID ${bidIdentification} must have subsequent time intervals.`, params: { bidIdentification, }, }, { code: "bidMustCoverWholeAuctionPeriod", title: "Bid Items do not cover the whole auction period", message: `The bid with ID ${code} must cover the whole auction period.`, params: { code, }, }, ]; assertAuctionBidAuctionDao(); assertCcmServiceListMarketParticipant(); assertAuctionParticipantMD(); BusinessValidationHelper.assertFailedValidation(response.validation, expectedValidationMessageList); }); it("fails with bidMustCoverWholeAuctionPeriod", async () => { let newDtoIn = JSON.parse(JSON.stringify(TestData.dtoIn)); newDtoIn.list[0].itemList[0] = { timeInterval: { from: "2020-03-15T01:00:00.000Z", to: "2020-03-15T02:00:00.000Z", }, requestedCapacity: 100, requestedPrice: 10.0, }; const response = await AuctionBidValidators.validateStore(uri, newDtoIn, {}); let code = newDtoIn.list[0].bidIdentification; const expectedValidationMessageList = [ { code: "bidMustCoverWholeAuctionPeriod", title: "Bid Items do not cover the whole auction period", message: `The bid with ID ${code} must cover the whole auction period.`, params: { code, }, }, ]; assertAuctionBidAuctionDao(); assertCcmServiceListMarketParticipant(); assertAuctionParticipantMD(); BusinessValidationHelper.assertFailedValidation(response.validation, expectedValidationMessageList); }); it("fails with resolutionHaveToBeP1Y", async () => { let newDtoIn = JSON.parse(JSON.stringify(TestData.dtoIn)); newDtoIn.list[0].resolution = "P1M"; const response = await AuctionBidValidators.validateStore(uri, newDtoIn, {}); const expectedValidationMessageList = [ { code: "resolutionHaveToBeP1Y", title: "Bid Resolution for the Yearly Auction must be P1Y", message: `Bid Resolution for the Yearly Auction must be P1Y`, }, ]; assertAuctionBidAuctionDao(); assertCcmServiceListMarketParticipant(); assertAuctionParticipantMD(); BusinessValidationHelper.assertFailedValidation(response.validation, expectedValidationMessageList); }); it("fails with resolutionHaveToBeP1M", async () => { AuctionBidStoreValidatorAuctionDaoGet.mockRestore(); let auction = { ...TestData.auction }; let timeInt = { from: "2022-06-30T22:00:00.000Z", to: "2022-07-31T22:00:00.000Z", }; auction.timeInterval = timeInt; auction.capacityContractTypeCode = "monthly"; jest.spyOn(AuctionBidStoreValidator.auctionDao, "getOneByCriteria").mockResolvedValue(auction); let newDtoIn = JSON.parse(JSON.stringify(TestData.dtoIn)); newDtoIn.list[0].itemList[0].timeInterval = timeInt; newDtoIn.list[0].itemList[1] = { timeInterval: { from: "2022-07-31T22:00:00.000Z", to: "2022-07-31T22:00:00.000Z", }, requestedCapacity: 100, requestedPrice: 10.0, }; const response = await AuctionBidValidators.validateStore(uri, newDtoIn, {}); const expectedValidationMessageList = [ { code: "resolutionHaveToBeP1M", title: "Bid Resolution for the Monthly Auction covering one calendar month must be P1M", message: `Bid Resolution for the Yearly Auction must be P1M`, }, ]; assertAuctionBidAuctionDao(); assertCcmServiceListMarketParticipant(); assertAuctionParticipantMD(timeInt); BusinessValidationHelper.assertFailedValidation(response.validation, expectedValidationMessageList); }); it("fails with resolutionHaveToBeP1D", async () => { AuctionBidStoreValidatorAuctionDaoGet.mockRestore(); let auction = { ...TestData.auction }; let timeInt = { from: "2022-06-30T22:00:00.000Z", to: "2022-07-01T22:00:00.000Z", }; auction.timeInterval = timeInt; auction.capacityContractTypeCode = "monthly"; jest.spyOn(AuctionBidStoreValidator.auctionDao, "getOneByCriteria").mockResolvedValue(auction); let newDtoIn = JSON.parse(JSON.stringify(TestData.dtoIn)); newDtoIn.list[0].itemList[0].timeInterval = timeInt; const response = await AuctionBidValidators.validateStore(uri, newDtoIn, {}); const expectedValidationMessageList = [ { code: "resolutionHaveToBeP1D", title: "Bid Resolution covering less than one month must be P1D", message: `Bid Resolution covering less than one month must be P1D.`, }, ]; assertAuctionBidAuctionDao(); assertCcmServiceListMarketParticipant(); assertAuctionParticipantMD(timeInt); BusinessValidationHelper.assertFailedValidation(response.validation, expectedValidationMessageList); }); it("fails with monthlyAuctionCoverMoreThanOneMonth", async () => { AuctionBidStoreValidatorAuctionDaoGet.mockRestore(); let auction = { ...TestData.auction }; let timeInt = { from: "2021-12-31T23:00:00.000Z", to: "2022-02-30T23:00:00.000Z", }; auction.timeInterval = timeInt; auction.capacityContractTypeCode = "monthly"; jest.spyOn(AuctionBidStoreValidator.auctionDao, "getOneByCriteria").mockResolvedValue(auction); let newDtoIn = JSON.parse(JSON.stringify(TestData.dtoIn)); newDtoIn.list[0].resolution = "P1M"; newDtoIn.list[0].itemList[0].timeInterval = timeInt; const response = await AuctionBidValidators.validateStore(uri, newDtoIn, {}); const expectedValidationMessageList = [ { code: "monthlyAuctionCoverMoreThanOneMonth", title: "Monthly Auction covering more than one calendar month.", message: "Monthly Auction covering more than one calendar month.", }, ]; assertAuctionBidAuctionDao(); assertCcmServiceListMarketParticipant(); assertAuctionParticipantMD(timeInt); BusinessValidationHelper.assertFailedValidation(response.validation, expectedValidationMessageList); }); it("fails with invalidTimeIntervalForResolutionPT60M", async () => { AuctionBidStoreValidatorAuctionDaoGet.mockRestore(); let auction = { ...TestData.auction }; let timeInt = { from: new Date("2021-11-17T22:00:00.000Z"), to: new Date("2021-11-17T22:15:00.000Z"), }; auction.timeInterval = timeInt; auction.capacityContractTypeCode = "dayAhead"; jest.spyOn(AuctionBidStoreValidator.auctionDao, "getOneByCriteria").mockResolvedValue(auction); let newDtoIn = JSON.parse(JSON.stringify(TestData.dtoIn)); newDtoIn.list[0].resolution = "PT60M"; newDtoIn.list[0].itemList[0].timeInterval = timeInt; const response = await AuctionBidValidators.validateStore(uri, newDtoIn, {}); const expectedValidationMessageList = [ { code: "invalidTimeIntervalForResolutionPT60M", title: `Bid resolution "PT60M" must cover 60 minutes`, message: `Bid resolution "PT60M" must cover 60 minutes.`, }, ]; assertAuctionBidAuctionDao(); assertCcmServiceListMarketParticipant(); assertAuctionParticipantMD(timeInt); BusinessValidationHelper.assertFailedValidation(response.validation, expectedValidationMessageList); }); it("fails with resolutionHaveToBePT60MorPT15M", async () => { AuctionBidStoreValidatorAuctionDaoGet.mockRestore(); let auction = { ...TestData.auction }; auction.capacityContractTypeCode = "dayAhead"; jest.spyOn(AuctionBidStoreValidator.auctionDao, "getOneByCriteria").mockResolvedValue(auction); let newDtoIn = JSON.parse(JSON.stringify(TestData.dtoIn)); newDtoIn.list[0].resolution = "PT15M"; const response = await AuctionBidValidators.validateStore(uri, newDtoIn, {}); const expectedValidationMessageList = [ { code: "resolutionHaveToBePT60MorPT15M", title: `Bid resolution of the Day-Ahead and Intraday Auctions must be PT60M or PT15M`, message: `Bid resolution of the Day-Ahead and Intraday Auctions must be PT60M or PT15M.`, }, ]; assertAuctionBidAuctionDao(); assertCcmServiceListMarketParticipant(); assertAuctionParticipantMD(); BusinessValidationHelper.assertFailedValidation(response.validation, expectedValidationMessageList); }); it("fails with maxNumberOfBidsExceeded", async () => { AuctionBidStoreValidatorAuctionDaoGet.mockRestore(); let auction = { ...TestData.auction }; let maxNumber = 0; auction.biddingConfiguration.maximumNumberOfBidsPerTrader = maxNumber; jest.spyOn(AuctionBidStoreValidator.auctionDao, "getOneByCriteria").mockResolvedValue(auction); const response = await AuctionBidValidators.validateStore(uri, dtoIn, {}); const expectedValidationMessageList = [ { code: "maxNumberOfBidsExceeded", title: `Maximum number of bids exceeded`, message: `The maximum number of bids per trader is ${maxNumber}`, params: { maxNumber, }, }, ]; assertAuctionBidAuctionDao(); assertCcmServiceListMarketParticipant(); assertAuctionParticipantMD(); BusinessValidationHelper.assertFailedValidation(response.validation, expectedValidationMessageList); }); it("fails with requestedCapacityNotAccordingToConfiguration", async () => { AuctionBidStoreValidatorAuctionDaoGet.mockRestore(); let auction = { ...TestData.auction }; auction.biddingConfiguration.minBidValue = 101; let { minBidValue, maxBidValue } = auction.biddingConfiguration; jest.spyOn(AuctionBidStoreValidator.auctionDao, "getOneByCriteria").mockResolvedValue(auction); let timeInterval = dtoIn.list[0].itemList[0].timeInterval; let from = TimeService.toFormattedDateString(timeInterval.from, "YYYY-MM-DD H:mm"); let to = TimeService.toFormattedDateString(timeInterval.to, "YYYY-MM-DD H:mm"); let bidIdentification = dtoIn.list[0].bidIdentification; const response = await AuctionBidValidators.validateStore(uri, dtoIn, {}); const expectedValidationMessageList = [ { code: "requestedCapacityNotAccordingToConfiguration", title: `Requested Capacity not according to Bidding Configuration`, message: `The Bid Requested Capacity for the Bid with ID ${bidIdentification} and time interval from ${from} - to ${to} must be in the range between ${minBidValue} MW and ${maxBidValue} MW.`, params: { bidIdentification, timeInterval: { from, to, }, // TODO CHECK IF CORRECT FORMAT timeInterval ( converted to format dd.mm.yyyy hh:mm - dd.mm.yyyy hh:mm), minBidValue, maxBidValue, }, }, ]; assertAuctionBidAuctionDao(); assertCcmServiceListMarketParticipant(); assertAuctionParticipantMD(); BusinessValidationHelper.assertFailedValidation(response.validation, expectedValidationMessageList); }); it("fails with requestedCapacityExceedsOfferedCapacity", async () => { AuctionBidStoreValidatorAuctionDaoGet.mockRestore(); let listDataMock = TestData.tsListData; listDataMock.tsList[0].tsId.tsDimensionValueIdList = [TestData.auction.id + ",home"]; jest.spyOn(TsDataService, "listData").mockResolvedValue(listDataMock); let auction = TestData.auction; let timeInt = { from: "2021-11-17T23:00:00.000Z", to: "2021-11-17T23:15:00.000Z", }; auction.timeInterval = timeInt; jest.spyOn(AuctionBidStoreValidator.auctionDao, "getOneByCriteria").mockResolvedValue(auction); let newDtoIn = JSON.parse(JSON.stringify(dtoIn)); newDtoIn.list[0].itemList[0].timeInterval = timeInt; const response = await AuctionBidValidators.validateStore(uri, newDtoIn, {}); let from = TimeService.toFormattedDateString(timeInt.from, "YYYY-MM-DD HH:mm"); let to = TimeService.toFormattedDateString(timeInt.to, "YYYY-MM-DD HH:mm"); let bidIdentification = dtoIn.list[0].bidIdentification; const expectedValidationMessageList = [ { code: "requestedCapacityExceedsOfferedCapacity", title: `Requested Capacity exceeds Offered Capacity`, message: `The Bid with ID ${bidIdentification} and time interval from ${from} - to ${to} exceeds the Offered Capacity.`, params: { bidIdentification, timeInterval: { from, to }, }, }, ]; assertAuctionBidAuctionDao(); assertCcmServiceListMarketParticipant(); assertAuctionParticipantMD(timeInt); assertTsDataServiceListData(timeInt); BusinessValidationHelper.assertFailedValidation(response.validation, expectedValidationMessageList); }); it("fails with requestedPriceNotAccordingToConfiguration", async () => { AuctionBidStoreValidatorAuctionDaoGet.mockRestore(); let auction = { ...TestData.auction }; auction.biddingConfiguration.minBidPrice = 11; jest.spyOn(AuctionBidStoreValidator.auctionDao, "getOneByCriteria").mockResolvedValue(auction); const response = await AuctionBidValidators.validateStore(uri, dtoIn, {}); let timeInt = dtoIn.list[0].itemList[0].timeInterval; let from = TimeService.toFormattedDateString(timeInt.from, "YYYY-MM-DD H:mm"); let to = TimeService.toFormattedDateString(timeInt.to, "YYYY-MM-DD H:mm"); let bidIdentification = dtoIn.list[0].bidIdentification; let { minBidPrice, maxBidPrice } = auction.biddingConfiguration; const expectedValidationMessageList = [ { code: "requestedPriceNotAccordingToConfiguration", title: `Requested Price not according to Bidding Configuration`, message: `The Bid Requested Capacity for the Bid with ID ${bidIdentification} and time interval from ${from} - to ${to} must be in the range between ${minBidPrice} and ${maxBidPrice}.`, params: { bidIdentification, timeInterval: { from, to }, minBidPrice, maxBidPrice, }, }, ]; assertAuctionBidAuctionDao(); assertCcmServiceListMarketParticipant(); assertAuctionParticipantMD(timeInt); assertTsDataServiceListData(timeInt); BusinessValidationHelper.assertFailedValidation(response.validation, expectedValidationMessageList); }); }); const assertAuctionBidAuctionDao = () => { expect(AuctionBidStoreValidator.auctionDao.getOneByCriteria).toHaveBeenCalledTimes(1); expect(AuctionBidStoreValidator.auctionDao.getOneByCriteria).toHaveBeenCalledWith(awid, { id: dtoIn.auctionId, state: "active", }); }; const assertCcmServiceListMarketParticipant = () => { expect(CcmService.listMarketParticipant).toHaveBeenCalledTimes(1); expect(CcmService.listMarketParticipant).toHaveBeenCalledWith(awid, [ dtoIn.senderMarketParticipantId, dtoIn.marketParticipantId, ]); }; const assertAuctionParticipantMD = (timeInterval) => { let timeInt = timeInterval || TestData.auction.timeInterval; expect(MasterDataService.getMasterDataAsObject).toHaveBeenCalledTimes(1); expect(MasterDataService.getMasterDataAsObject).toHaveBeenCalledWith(awid, "auctionParticipant", undefined, timeInt, { marketParticipant: TestData.dtoIn.marketParticipantId, }); }; const assertTsDataServiceListData = (timeInt) => { let auction = TestData.auction; let timeInterval = timeInt || auction.timeInterval; expect(TsDataService.listData).toHaveBeenCalledTimes(1); expect(TsDataService.listData).toHaveBeenCalledWith( uri, { tsList: [ { tsId: { tsDefinitionCode: "oc_aucCat_pt15m", tsDimensionValueIdList: [auction.code, "home"], }, timeInterval, tsValueListSampleType: "fixed", }, ], }, null, {} ); };