|
| 1 | +const pages = require('../../../pages'); |
| 2 | +const relative = require('../../../relativeURL'); |
| 3 | +const dealWithNotStartedFacilityStatuses = require('./dealWithNotStartedFacilityStatuses'); |
| 4 | +const MOCK_USERS = require('../../../../../../e2e-fixtures'); |
| 5 | +const { fillAndSubmitIssueBondFacilityForm } = require('../fill-and-submit-issue-facility-form/fillAndSubmitIssueBondFacilityForm'); |
| 6 | +const { fillAndSubmitIssueLoanFacilityForm } = require('../fill-and-submit-issue-facility-form/fillAndSubmitIssueLoanFacilityForm'); |
| 7 | + |
| 8 | +const { BANK1_MAKER1, ADMIN } = MOCK_USERS; |
| 9 | + |
| 10 | +context('A maker should not be able to submit the deal if it has atleast one `Incomplete` facility', () => { |
| 11 | + let deal; |
| 12 | + let dealId; |
| 13 | + const dealFacilities = { |
| 14 | + bonds: [], |
| 15 | + loans: [], |
| 16 | + }; |
| 17 | + |
| 18 | + before(() => { |
| 19 | + cy.insertOneDeal(dealWithNotStartedFacilityStatuses, BANK1_MAKER1).then((insertedDeal) => { |
| 20 | + deal = insertedDeal; |
| 21 | + dealId = deal._id; |
| 22 | + |
| 23 | + const { mockFacilities } = dealWithNotStartedFacilityStatuses; |
| 24 | + |
| 25 | + cy.createFacilities(dealId, mockFacilities, BANK1_MAKER1).then((createdFacilities) => { |
| 26 | + const bonds = createdFacilities.filter((f) => f.type === 'Bond'); |
| 27 | + const loans = createdFacilities.filter((f) => f.type === 'Loan'); |
| 28 | + |
| 29 | + dealFacilities.bonds = bonds; |
| 30 | + dealFacilities.loans = loans; |
| 31 | + }); |
| 32 | + }); |
| 33 | + }); |
| 34 | + |
| 35 | + beforeEach(() => { |
| 36 | + // Login and visit the deal |
| 37 | + cy.login(BANK1_MAKER1); |
| 38 | + pages.contract.visit(deal); |
| 39 | + }); |
| 40 | + |
| 41 | + after(() => { |
| 42 | + cy.deleteDeals(ADMIN); |
| 43 | + dealFacilities.bonds.forEach((facility) => { |
| 44 | + cy.deleteFacility(facility._id, BANK1_MAKER1); |
| 45 | + }); |
| 46 | + dealFacilities.loans.forEach((facility) => { |
| 47 | + cy.deleteFacility(facility._id, BANK1_MAKER1); |
| 48 | + }); |
| 49 | + }); |
| 50 | + |
| 51 | + it('Complete few facilities for submission', () => { |
| 52 | + pages.contract.proceedToReview().should('not.exist'); |
| 53 | + |
| 54 | + const firstBondId = dealFacilities.bonds[0]._id; |
| 55 | + const firstBondRow = pages.contract.bondTransactionsTable.row(firstBondId); |
| 56 | + |
| 57 | + const thirdBondId = dealFacilities.bonds[2]._id; |
| 58 | + const thirdBondRow = pages.contract.bondTransactionsTable.row(thirdBondId); |
| 59 | + |
| 60 | + const firstLoanId = dealFacilities.loans[0]._id; |
| 61 | + const firstLoanRow = pages.contract.loansTransactionsTable.row(firstLoanId); |
| 62 | + |
| 63 | + const thirdLoanId = dealFacilities.loans[2]._id; |
| 64 | + const thirdLoanRow = pages.contract.loansTransactionsTable.row(thirdLoanId); |
| 65 | + |
| 66 | + //--------------------------------------------------------------- |
| 67 | + // check initial facility stage, status and issue facility link |
| 68 | + //--------------------------------------------------------------- |
| 69 | + dealFacilities.bonds.forEach((bond) => { |
| 70 | + const bondId = bond._id; |
| 71 | + const bondRow = pages.contract.bondTransactionsTable.row(bondId); |
| 72 | + |
| 73 | + bondRow |
| 74 | + .facilityStage() |
| 75 | + .invoke('text') |
| 76 | + .then((text) => { |
| 77 | + expect(text.trim()).to.equal('Unissued'); |
| 78 | + }); |
| 79 | + |
| 80 | + bondRow |
| 81 | + .bondStatus() |
| 82 | + .invoke('text') |
| 83 | + .then((text) => { |
| 84 | + expect(text.trim()).to.equal('Not started'); |
| 85 | + }); |
| 86 | + |
| 87 | + bondRow |
| 88 | + .issueFacilityLink() |
| 89 | + .invoke('text') |
| 90 | + .then((text) => { |
| 91 | + expect(text.trim()).to.equal('Issue facility'); |
| 92 | + }); |
| 93 | + |
| 94 | + bondRow |
| 95 | + .issueFacilityLink() |
| 96 | + .invoke('attr', 'href') |
| 97 | + .then((href) => { |
| 98 | + expect(href).to.equal(`/contract/${dealId}/bond/${bondId}/issue-facility`); |
| 99 | + }); |
| 100 | + }); |
| 101 | + |
| 102 | + //--------------------------------------------------------------- |
| 103 | + // check initial Loan stage, status and issue facility link |
| 104 | + //--------------------------------------------------------------- |
| 105 | + dealFacilities.loans.forEach((loan) => { |
| 106 | + const loanId = loan._id; |
| 107 | + const loanRow = pages.contract.loansTransactionsTable.row(loanId); |
| 108 | + |
| 109 | + loanRow |
| 110 | + .facilityStage() |
| 111 | + .invoke('text') |
| 112 | + .then((text) => { |
| 113 | + expect(text.trim()).to.equal('Conditional'); |
| 114 | + }); |
| 115 | + |
| 116 | + loanRow |
| 117 | + .loanStatus() |
| 118 | + .invoke('text') |
| 119 | + .then((text) => { |
| 120 | + expect(text.trim()).to.equal('Not started'); |
| 121 | + }); |
| 122 | + |
| 123 | + loanRow |
| 124 | + .issueFacilityLink() |
| 125 | + .invoke('text') |
| 126 | + .then((text) => { |
| 127 | + expect(text.trim()).to.equal('Issue facility'); |
| 128 | + }); |
| 129 | + |
| 130 | + loanRow |
| 131 | + .issueFacilityLink() |
| 132 | + .invoke('attr', 'href') |
| 133 | + .then((href) => { |
| 134 | + expect(href).to.equal(`/contract/${dealId}/loan/${loanId}/issue-facility`); |
| 135 | + }); |
| 136 | + }); |
| 137 | + |
| 138 | + //--------------------------------------------------------------- |
| 139 | + // makers completes first Bond Issue Facility form |
| 140 | + //--------------------------------------------------------------- |
| 141 | + firstBondRow.issueFacilityLink().click(); |
| 142 | + cy.url().should('eq', relative(`/contract/${dealId}/bond/${firstBondId}/issue-facility`)); |
| 143 | + |
| 144 | + fillAndSubmitIssueBondFacilityForm(); |
| 145 | + cy.url().should('eq', relative(`/contract/${dealId}`)); |
| 146 | + |
| 147 | + //--------------------------------------------------------------- |
| 148 | + // Bond facility link and status should be updated |
| 149 | + //--------------------------------------------------------------- |
| 150 | + firstBondRow |
| 151 | + .issueFacilityLink() |
| 152 | + .invoke('text') |
| 153 | + .then((text) => { |
| 154 | + expect(text.trim()).to.equal('Facility issued'); |
| 155 | + }); |
| 156 | + |
| 157 | + firstBondRow |
| 158 | + .bondStatus() |
| 159 | + .invoke('text') |
| 160 | + .then((text) => { |
| 161 | + expect(text.trim()).to.equal('Completed'); |
| 162 | + }); |
| 163 | + |
| 164 | + //--------------------------------------------------------------- |
| 165 | + // makers completes third Bond Issue Facility form |
| 166 | + //--------------------------------------------------------------- |
| 167 | + thirdBondRow.issueFacilityLink().click(); |
| 168 | + cy.url().should('eq', relative(`/contract/${dealId}/bond/${thirdBondId}/issue-facility`)); |
| 169 | + |
| 170 | + fillAndSubmitIssueBondFacilityForm(); |
| 171 | + cy.url().should('eq', relative(`/contract/${dealId}`)); |
| 172 | + |
| 173 | + //--------------------------------------------------------------- |
| 174 | + // Bond facility link and status should be updated |
| 175 | + //--------------------------------------------------------------- |
| 176 | + thirdBondRow |
| 177 | + .issueFacilityLink() |
| 178 | + .invoke('text') |
| 179 | + .then((text) => { |
| 180 | + expect(text.trim()).to.equal('Facility issued'); |
| 181 | + }); |
| 182 | + |
| 183 | + thirdBondRow |
| 184 | + .bondStatus() |
| 185 | + .invoke('text') |
| 186 | + .then((text) => { |
| 187 | + expect(text.trim()).to.equal('Completed'); |
| 188 | + }); |
| 189 | + |
| 190 | + //--------------------------------------------------------------- |
| 191 | + // makers completes one Loan Issue Facility form |
| 192 | + //--------------------------------------------------------------- |
| 193 | + firstLoanRow.issueFacilityLink().click(); |
| 194 | + cy.url().should('eq', relative(`/contract/${dealId}/loan/${firstLoanId}/issue-facility`)); |
| 195 | + |
| 196 | + fillAndSubmitIssueLoanFacilityForm(); |
| 197 | + cy.url().should('eq', relative(`/contract/${dealId}`)); |
| 198 | + |
| 199 | + //--------------------------------------------------------------- |
| 200 | + // Loan facility link and status should be updated |
| 201 | + //--------------------------------------------------------------- |
| 202 | + firstLoanRow |
| 203 | + .issueFacilityLink() |
| 204 | + .invoke('text') |
| 205 | + .then((text) => { |
| 206 | + expect(text.trim()).to.equal('Facility issued'); |
| 207 | + }); |
| 208 | + |
| 209 | + firstLoanRow |
| 210 | + .loanStatus() |
| 211 | + .invoke('text') |
| 212 | + .then((text) => { |
| 213 | + expect(text.trim()).to.equal('Completed'); |
| 214 | + }); |
| 215 | + |
| 216 | + //--------------------------------------------------------------- |
| 217 | + // makers completes third Loan Issue Facility form |
| 218 | + //--------------------------------------------------------------- |
| 219 | + thirdLoanRow.issueFacilityLink().click(); |
| 220 | + cy.url().should('eq', relative(`/contract/${dealId}/loan/${thirdLoanId}/issue-facility`)); |
| 221 | + |
| 222 | + fillAndSubmitIssueLoanFacilityForm(); |
| 223 | + cy.url().should('eq', relative(`/contract/${dealId}`)); |
| 224 | + |
| 225 | + //--------------------------------------------------------------- |
| 226 | + // Loan facility link and status should be updated |
| 227 | + //--------------------------------------------------------------- |
| 228 | + thirdLoanRow |
| 229 | + .issueFacilityLink() |
| 230 | + .invoke('text') |
| 231 | + .then((text) => { |
| 232 | + expect(text.trim()).to.equal('Facility issued'); |
| 233 | + }); |
| 234 | + |
| 235 | + thirdLoanRow |
| 236 | + .loanStatus() |
| 237 | + .invoke('text') |
| 238 | + .then((text) => { |
| 239 | + expect(text.trim()).to.equal('Completed'); |
| 240 | + }); |
| 241 | + }); |
| 242 | + |
| 243 | + it('Maker start a bond and a loan and does not finish the whole journey', () => { |
| 244 | + //--------------------------------------------------------------- |
| 245 | + // Maker starts, but does not finish, a different Issue Facility form (Bond) |
| 246 | + //--------------------------------------------------------------- |
| 247 | + const incompleteIssueFacilityBondId = dealFacilities.bonds[1]._id; |
| 248 | + const incompleteIssueFacilityBondRow = pages.contract.bondTransactionsTable.row(incompleteIssueFacilityBondId); |
| 249 | + |
| 250 | + incompleteIssueFacilityBondRow.issueFacilityLink().click(); |
| 251 | + cy.url().should('eq', relative(`/contract/${dealId}/bond/${incompleteIssueFacilityBondId}/issue-facility`)); |
| 252 | + |
| 253 | + pages.bondIssueFacility.name().type('1234'); |
| 254 | + pages.bondIssueFacility.submit().click(); |
| 255 | + pages.bondIssueFacility.cancelButton().click(); |
| 256 | + cy.url().should('eq', relative(`/contract/${dealId}`)); |
| 257 | + |
| 258 | + //--------------------------------------------------------------- |
| 259 | + // Bond with incomplete Issue Facility form |
| 260 | + // - status should not be updated |
| 261 | + // - link remains the same |
| 262 | + //--------------------------------------------------------------- |
| 263 | + incompleteIssueFacilityBondRow |
| 264 | + .issueFacilityLink() |
| 265 | + .invoke('text') |
| 266 | + .then((text) => { |
| 267 | + expect(text.trim()).to.equal('Issue facility'); |
| 268 | + }); |
| 269 | + |
| 270 | + incompleteIssueFacilityBondRow |
| 271 | + .bondStatus() |
| 272 | + .invoke('text') |
| 273 | + .then((text) => { |
| 274 | + expect(text.trim()).to.equal('Incomplete'); |
| 275 | + }); |
| 276 | + |
| 277 | + //--------------------------------------------------------------- |
| 278 | + // Maker starts, but does not finish, a different Issue Facility form (Loan) |
| 279 | + //--------------------------------------------------------------- |
| 280 | + const incompleteIssueFacilityLoanId = dealFacilities.loans[1]._id; |
| 281 | + const incompleteIssueFacilityLoanRow = pages.contract.loansTransactionsTable.row(incompleteIssueFacilityLoanId); |
| 282 | + |
| 283 | + incompleteIssueFacilityLoanRow.issueFacilityLink().click(); |
| 284 | + cy.url().should('eq', relative(`/contract/${dealId}/loan/${incompleteIssueFacilityLoanId}/issue-facility`)); |
| 285 | + |
| 286 | + pages.loanIssueFacility.disbursementAmount().type('1234'); |
| 287 | + pages.loanIssueFacility.submit().click(); |
| 288 | + pages.loanIssueFacility.cancelButton().click(); |
| 289 | + cy.url().should('eq', relative(`/contract/${dealId}`)); |
| 290 | + |
| 291 | + //--------------------------------------------------------------- |
| 292 | + // Loan with incomplete Issue Facility form |
| 293 | + // - status should not be updated |
| 294 | + // - link remains the same |
| 295 | + //--------------------------------------------------------------- |
| 296 | + incompleteIssueFacilityLoanRow |
| 297 | + .issueFacilityLink() |
| 298 | + .invoke('text') |
| 299 | + .then((text) => { |
| 300 | + expect(text.trim()).to.equal('Issue facility'); |
| 301 | + }); |
| 302 | + |
| 303 | + incompleteIssueFacilityLoanRow |
| 304 | + .loanStatus() |
| 305 | + .invoke('text') |
| 306 | + .then((text) => { |
| 307 | + expect(text.trim()).to.equal('Incomplete'); |
| 308 | + }); |
| 309 | + }); |
| 310 | + |
| 311 | + it('Maker is unable to submit the application', () => { |
| 312 | + //--------------------------------------------------------------- |
| 313 | + // Ensure Maker cannot submit a deal with `Incomplete` facilities |
| 314 | + //--------------------------------------------------------------- |
| 315 | + pages.contract.proceedToReview().should('not.exist'); |
| 316 | + }); |
| 317 | +}); |
0 commit comments