diff --git a/cypress/e2e/finance/funds/money-transfer-between-funds-from-different-ledgers-is-successful-if-budget-from-already-has-zero-money-allocation.cy.js b/cypress/e2e/finance/funds/money-transfer-between-funds-from-different-ledgers-is-successful-if-budget-from-already-has-zero-money-allocation.cy.js new file mode 100644 index 0000000000..04465df43b --- /dev/null +++ b/cypress/e2e/finance/funds/money-transfer-between-funds-from-different-ledgers-is-successful-if-budget-from-already-has-zero-money-allocation.cy.js @@ -0,0 +1,101 @@ +import permissions from '../../../support/dictionary/permissions'; +import { + Budgets, + FinanceHelper, + FiscalYears, + Funds, + Ledgers, +} from '../../../support/fragments/finance'; +import TopMenu from '../../../support/fragments/topMenu'; +import Users from '../../../support/fragments/users/users'; +import InteractorsTools from '../../../support/utils/interactorsTools'; +import getRandomPostfix from '../../../support/utils/stringTools'; + +describe('Finance: Funds', () => { + const firstFiscalYear = { ...FiscalYears.defaultUiFiscalYear }; + const defaultLedger = { ...Ledgers.defaultUiLedger }; + const fromFund = { ...Funds.defaultUiFund }; + const toFund = { + name: `autotest_fund2_${getRandomPostfix()}`, + code: getRandomPostfix(), + externalAccountNo: getRandomPostfix(), + fundStatus: 'Active', + description: `This is fund created by E2E test automation script_${getRandomPostfix()}`, + }; + + const toBudget = Budgets.getDefaultBudget(); + const fromBudget = Budgets.getDefaultBudget(); + let user; + + before('Create test data', () => { + cy.getAdminToken().then(() => { + FiscalYears.createViaApi(firstFiscalYear).then((firstFiscalYearResponse) => { + firstFiscalYear.id = firstFiscalYearResponse.id; + toBudget.fiscalYearId = firstFiscalYearResponse.id; + fromBudget.fiscalYearId = firstFiscalYearResponse.id; + defaultLedger.fiscalYearOneId = firstFiscalYear.id; + Ledgers.createViaApi(defaultLedger).then((ledgerResponse) => { + defaultLedger.id = ledgerResponse.id; + fromFund.ledgerId = defaultLedger.id; + toFund.ledgerId = defaultLedger.id; + + Funds.createViaApi(toFund).then((fundResponse) => { + toFund.id = fundResponse.fund.id; + toBudget.fundId = fundResponse.fund.id; + Budgets.createViaApi(toBudget); + fromFund.allocatedToIds = [fundResponse.fund.id]; + Funds.createViaApi(fromFund).then((secondFundResponse) => { + fromFund.id = secondFundResponse.fund.id; + fromBudget.fundId = secondFundResponse.fund.id; + Budgets.createViaApi(fromBudget); + }); + }); + }); + }); + }); + + cy.createTempUser([ + permissions.uiFinanceCreateAllocations.gui, + permissions.uiFinanceViewFundAndBudget.gui, + ]).then((userProperties) => { + user = userProperties; + + cy.login(userProperties.username, userProperties.password, { + path: TopMenu.fundPath, + waiter: Funds.waitLoading, + }); + }); + }); + + after('Delete test data', () => { + cy.getAdminToken(); + Budgets.deleteViaApi(toBudget.id); + Budgets.deleteViaApi(fromBudget.id); + Funds.deleteFundViaApi(toFund.id); + Funds.deleteFundViaApi(fromFund.id); + Ledgers.deleteledgerViaApi(defaultLedger.id); + FiscalYears.deleteFiscalYearViaApi(firstFiscalYear.id); + Users.deleteViaApi(user.userId); + }); + + it( + 'C535516 Money transfer between funds from different ledgers is successful if budget "From" already has 0.00 money allocation (thunderjet)', + { tags: ['extendedPath', 'thunderjet'] }, + () => { + FinanceHelper.searchByName(fromFund.name); + Funds.selectFund(fromFund.name); + + Funds.checkBudgetDetails([{ ...fromBudget, available: fromBudget.allocated }]); + Funds.selectBudgetDetails(); + + const amount = '100'; + Funds.moveAllocation({ fromFund, toFund, amount }); + InteractorsTools.checkCalloutErrorMessage( + `$${amount}.00 was not successfully allocated to the budget ${toBudget.name} because it exceeds the total allocation amount of ${fromBudget.name} and ledger fund restrictions are active`, + ); + Funds.closeTransferModal(); + Funds.closeBudgetDetails(); + Funds.checkBudgetDetails([{ ...fromBudget, available: fromBudget.allocated }]); + }, + ); +});