|
Line 0
Link Here
|
|
|
1 |
describe("Patron self-renewal", () => { |
| 2 |
beforeEach(() => { |
| 3 |
cy.task("buildSampleObject", { |
| 4 |
object: "patron_category", |
| 5 |
values: { |
| 6 |
self_renewal_enabled: 1, |
| 7 |
self_renewal_availability_start: 10, |
| 8 |
self_renewal_if_expired: 10, |
| 9 |
self_renewal_failure_message: "This cypress renewal has failed", |
| 10 |
self_renewal_fines_block: 0, |
| 11 |
}, |
| 12 |
}).then(patron_category => { |
| 13 |
cy.task("insertObject", { |
| 14 |
type: "category", |
| 15 |
object: patron_category, |
| 16 |
}).then(patron_category => { |
| 17 |
cy.wrap(patron_category).as("patron_category"); |
| 18 |
cy.task("insertSamplePatron", { |
| 19 |
patron_category, |
| 20 |
patronValues: { |
| 21 |
password: "Cypress1234", |
| 22 |
email: "test@email.com", |
| 23 |
secondary_email: "test@email.com", |
| 24 |
altaddress_email: "test@email.com", |
| 25 |
}, |
| 26 |
}).then(objects_patron => { |
| 27 |
cy.wrap(objects_patron).as("objects_patron"); |
| 28 |
cy.loginOpac( |
| 29 |
objects_patron.patron.cardnumber, |
| 30 |
"Cypress1234" |
| 31 |
); |
| 32 |
}); |
| 33 |
}); |
| 34 |
}); |
| 35 |
}); |
| 36 |
|
| 37 |
afterEach(function () { |
| 38 |
this.objects_patron.category = this.patron_category; |
| 39 |
cy.task("deleteSampleObjects", this.objects_patron); |
| 40 |
}); |
| 41 |
|
| 42 |
it("should display a message that self renewal is available", function () { |
| 43 |
cy.visitOpac("/cgi-bin/koha/opac-user.pl"); |
| 44 |
cy.get("#self_renewal_available").contains( |
| 45 |
"You are eligible for self-renewal. Please click here to renew your account" |
| 46 |
); |
| 47 |
}); |
| 48 |
it("should open the modal for self-renewal", function () { |
| 49 |
cy.visitOpac("/cgi-bin/koha/opac-user.pl"); |
| 50 |
cy.get("#patronSelfRenewal", { timeout: 10000 }); |
| 51 |
cy.get("#self_renewal_available a").click(); |
| 52 |
cy.get("#patronSelfRenewal").should("be.visible"); |
| 53 |
}); |
| 54 |
it("should verify that the patron wants to renew their account", function () { |
| 55 |
cy.visitOpac("/cgi-bin/koha/opac-user.pl"); |
| 56 |
cy.intercept( |
| 57 |
"GET", |
| 58 |
Cypress.env("opacBaseUrl") + |
| 59 |
"/api/v1/public/patrons/self_renewal?_per_page=-1", |
| 60 |
{ |
| 61 |
self_renewal_settings: { |
| 62 |
opac_patron_details: "0", |
| 63 |
self_renewal_failure_message: |
| 64 |
"Your self-renewal can't be processed at this time. Please visit your local branch to complete your renewal.", |
| 65 |
}, |
| 66 |
verification_checks: [], |
| 67 |
} |
| 68 |
).as("renewalConfig"); |
| 69 |
cy.get("#patronSelfRenewal", { timeout: 10000 }); |
| 70 |
cy.get("#self_renewal_available a").click(); |
| 71 |
cy.wait("@renewalConfig"); |
| 72 |
cy.get("#patronSelfRenewal .verification_question").contains( |
| 73 |
"Are you sure you want to renew your account?" |
| 74 |
); |
| 75 |
}); |
| 76 |
it("should renew a patron's account", function () { |
| 77 |
cy.visitOpac("/cgi-bin/koha/opac-user.pl"); |
| 78 |
cy.intercept( |
| 79 |
"GET", |
| 80 |
Cypress.env("opacBaseUrl") + |
| 81 |
"/api/v1/public/patrons/self_renewal?_per_page=-1", |
| 82 |
{ |
| 83 |
self_renewal_settings: { |
| 84 |
opac_patron_details: "0", |
| 85 |
self_renewal_failure_message: |
| 86 |
"Your self-renewal can't be processed at this time. Please visit your local branch to complete your renewal.", |
| 87 |
}, |
| 88 |
verification_checks: [], |
| 89 |
} |
| 90 |
).as("renewalConfig"); |
| 91 |
cy.get("#patronSelfRenewal", { timeout: 10000 }); |
| 92 |
cy.get("#self_renewal_available a").click(); |
| 93 |
cy.wait("@renewalConfig"); |
| 94 |
cy.intercept( |
| 95 |
"POST", |
| 96 |
Cypress.env("opacBaseUrl") + "/api/v1/public/patrons/self_renewal", |
| 97 |
{ |
| 98 |
statusCode: 201, |
| 99 |
body: { |
| 100 |
expiry_date: "2099-01-01", |
| 101 |
confirmation_sent: true, |
| 102 |
}, |
| 103 |
} |
| 104 |
).as("submitRenewal"); |
| 105 |
cy.get("#patronSelfRenewal .verification_actions") |
| 106 |
.contains("Yes") |
| 107 |
.click(); |
| 108 |
cy.wait("@submitRenewal"); |
| 109 |
cy.get("#self_renewal_success").contains( |
| 110 |
"Your account has been successfully renewed" |
| 111 |
); |
| 112 |
}); |
| 113 |
it("should handle verification steps", function () { |
| 114 |
cy.visitOpac("/cgi-bin/koha/opac-user.pl"); |
| 115 |
cy.intercept( |
| 116 |
"GET", |
| 117 |
Cypress.env("opacBaseUrl") + |
| 118 |
"/api/v1/public/patrons/self_renewal?_per_page=-1", |
| 119 |
{ |
| 120 |
self_renewal_settings: { |
| 121 |
opac_patron_details: "0", |
| 122 |
self_renewal_failure_message: |
| 123 |
"Your self-renewal can't be processed at this time. Please visit your local branch to complete your renewal.", |
| 124 |
}, |
| 125 |
verification_checks: [ |
| 126 |
{ description: "This is step 1" }, |
| 127 |
{ description: "This is step 2" }, |
| 128 |
], |
| 129 |
} |
| 130 |
).as("renewalConfig"); |
| 131 |
cy.get("#patronSelfRenewal", { timeout: 10000 }); |
| 132 |
cy.get("#self_renewal_available a").click(); |
| 133 |
cy.wait("@renewalConfig"); |
| 134 |
cy.intercept( |
| 135 |
"POST", |
| 136 |
Cypress.env("opacBaseUrl") + "/api/v1/public/patrons/self_renewal", |
| 137 |
{ |
| 138 |
statusCode: 201, |
| 139 |
body: { |
| 140 |
expiry_date: "2099-01-01", |
| 141 |
confirmation_sent: true, |
| 142 |
}, |
| 143 |
} |
| 144 |
).as("submitRenewal"); |
| 145 |
cy.get("#patronSelfRenewal legend").contains("Verification step 1"); |
| 146 |
cy.get("#patronSelfRenewal .verification_question").contains( |
| 147 |
"This is step 1" |
| 148 |
); |
| 149 |
cy.get("#patronSelfRenewal .verification_actions") |
| 150 |
.contains("Yes") |
| 151 |
.click(); |
| 152 |
cy.get("#patronSelfRenewal legend").contains("Verification step 2"); |
| 153 |
cy.get("#patronSelfRenewal .verification_question").contains( |
| 154 |
"This is step 2" |
| 155 |
); |
| 156 |
cy.get("#patronSelfRenewal .verification_actions") |
| 157 |
.contains("Yes") |
| 158 |
.click(); |
| 159 |
|
| 160 |
cy.get("#patronSelfRenewal .verification_actions") |
| 161 |
.contains("Yes") |
| 162 |
.click(); |
| 163 |
cy.wait("@submitRenewal"); |
| 164 |
cy.get("#self_renewal_success").contains( |
| 165 |
"Your account has been successfully renewed" |
| 166 |
); |
| 167 |
}); |
| 168 |
it("should confirm patron details if required", function () { |
| 169 |
cy.visitOpac("/cgi-bin/koha/opac-user.pl"); |
| 170 |
cy.intercept( |
| 171 |
"GET", |
| 172 |
Cypress.env("opacBaseUrl") + |
| 173 |
"/api/v1/public/patrons/self_renewal?_per_page=-1", |
| 174 |
{ |
| 175 |
self_renewal_settings: { |
| 176 |
opac_patron_details: "1", |
| 177 |
self_renewal_failure_message: |
| 178 |
"Your self-renewal can't be processed at this time. Please visit your local branch to complete your renewal.", |
| 179 |
}, |
| 180 |
verification_checks: [], |
| 181 |
} |
| 182 |
).as("renewalConfig"); |
| 183 |
cy.get("#patronSelfRenewal", { timeout: 10000 }); |
| 184 |
cy.get("#self_renewal_available a").click(); |
| 185 |
cy.wait("@renewalConfig"); |
| 186 |
|
| 187 |
cy.get("#patronSelfRenewal legend").contains( |
| 188 |
"Confirm your account details" |
| 189 |
); |
| 190 |
cy.get("#patronSelfRenewal button").contains("Continue").click(); |
| 191 |
|
| 192 |
cy.get("h1").contains("Your personal details"); |
| 193 |
cy.get("#update-account div.alert.alert-info").contains( |
| 194 |
"Please verify your details to proceed with your self-renewal" |
| 195 |
); |
| 196 |
cy.intercept( |
| 197 |
"POST", |
| 198 |
Cypress.env("opacBaseUrl") + "/api/v1/public/patrons/self_renewal", |
| 199 |
{ |
| 200 |
statusCode: 201, |
| 201 |
body: { |
| 202 |
expiry_date: "2099-01-01", |
| 203 |
confirmation_sent: true, |
| 204 |
}, |
| 205 |
} |
| 206 |
).as("submitRenewal"); |
| 207 |
cy.get("#update-account fieldset.action input[type='submit']") |
| 208 |
.contains("Submit renewal request") |
| 209 |
.click(); |
| 210 |
cy.wait("@submitRenewal"); |
| 211 |
cy.get("#self_renewal_success").contains( |
| 212 |
"Your account has been successfully renewed" |
| 213 |
); |
| 214 |
}); |
| 215 |
}); |