View | Details | Raw Unified | Return to bug 26355
Collapse All | Expand All

(-)a/t/cypress/integration/Islands/SelfRenewal.ts (+215 lines)
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
});
(-)a/t/cypress/plugins/insertData.js (-1 / +27 lines)
Lines 388-393 const insertSampleCheckout = async ({ patron, baseUrl, authHeader }) => { Link Here
388
const insertSamplePatron = async ({
388
const insertSamplePatron = async ({
389
    library,
389
    library,
390
    patron_category,
390
    patron_category,
391
    patronValues,
391
    baseUrl,
392
    baseUrl,
392
    authHeader,
393
    authHeader,
393
}) => {
394
}) => {
Lines 427-432 const insertSamplePatron = async ({ Link Here
427
            category_id: patron_category.patron_category_id,
428
            category_id: patron_category.patron_category_id,
428
            incorrect_address: null,
429
            incorrect_address: null,
429
            patron_card_lost: null,
430
            patron_card_lost: null,
431
            ...patronValues,
430
        },
432
        },
431
    });
433
    });
432
434
Lines 443-448 const insertSamplePatron = async ({ Link Here
443
        lang,
445
        lang,
444
        login_attempts,
446
        login_attempts,
445
        sms_provider_id,
447
        sms_provider_id,
448
        self_renewal_available,
446
        ...patron
449
        ...patron
447
    } = generatedPatron;
450
    } = generatedPatron;
448
    delete patron.library;
451
    delete patron.library;
Lines 454-459 const insertSamplePatron = async ({ Link Here
454
        authHeader,
457
        authHeader,
455
    });
458
    });
456
459
460
    if (patronValues.hasOwnProperty("password")) {
461
        const password = patronValues.password;
462
        await apiPost({
463
            endpoint: `/api/v1/patrons/${patron.patron_id}/password`,
464
            body: { password, password_2: password },
465
            baseUrl,
466
            authHeader,
467
        });
468
    }
469
457
    return {
470
    return {
458
        patron,
471
        patron,
459
        ...(generatedLibrary ? { library } : {}),
472
        ...(generatedLibrary ? { library } : {}),
Lines 563-568 const deleteSampleObjects = async allObjects => { Link Here
563
            table: "erm_eholdings_titles",
576
            table: "erm_eholdings_titles",
564
            whereColumn: "title_id",
577
            whereColumn: "title_id",
565
        },
578
        },
579
        category: {
580
            plural: "categories",
581
            table: "categories",
582
            whereColumn: "categorycode",
583
            idField: "patron_category_id",
584
        },
566
    };
585
    };
567
    // Merge by type
586
    // Merge by type
568
    const mergedObjects = {};
587
    const mergedObjects = {};
Lines 594-599 const deleteSampleObjects = async allObjects => { Link Here
594
        "item_types",
613
        "item_types",
595
        "erm_agreements",
614
        "erm_agreements",
596
        "erm_eholdings_titles",
615
        "erm_eholdings_titles",
616
        "categories",
597
    ];
617
    ];
598
    const matchTypeToObjectMap = type => {
618
    const matchTypeToObjectMap = type => {
599
        const matchingKey = Object.keys(objectsMap).find(
619
        const matchingKey = Object.keys(objectsMap).find(
Lines 858-863 const insertObject = async ({ type, object, baseUrl, authHeader }) => { Link Here
858
            baseUrl,
878
            baseUrl,
859
            authHeader,
879
            authHeader,
860
        });
880
        });
881
    } else if (type === "category") {
882
        return apiPost({
883
            endpoint: "/api/v1/patron_categories",
884
            body: object,
885
            baseUrl,
886
            authHeader,
887
        });
861
    } else {
888
    } else {
862
        throw Error(`Unsupported object type '${type}' to insert`);
889
        throw Error(`Unsupported object type '${type}' to insert`);
863
    }
890
    }
864
- 

Return to bug 26355