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

(-)a/t/cypress/integration/Circulation/FineNoRenewals_spec.ts (-1 / +180 lines)
Line 0 Link Here
0
- 
1
describe("Circulation - FineNoRenewals and AllowFineOverrideRenewing", () => {
2
    beforeEach(() => {
3
        cy.login();
4
        cy.title().should("eq", "Koha staff interface");
5
    });
6
7
    describe("Renewal with fines", () => {
8
        let patron, checkout, fine_amount;
9
10
        beforeEach(function () {
11
            // Set up test data: patron with checkout and fines
12
            cy.task("insertSampleCheckout").then(objects => {
13
                patron = objects.patron;
14
                checkout = objects.checkout;
15
16
                // Set FineNoRenewals to 5
17
                cy.task("query", {
18
                    sql: "UPDATE systempreferences SET value = ? WHERE variable = ?",
19
                    values: ["5", "FineNoRenewals"],
20
                });
21
22
                // Add a fine of 10 to the patron (exceeds limit)
23
                fine_amount = 10;
24
                cy.task("query", {
25
                    sql: `INSERT INTO accountlines (borrowernumber, amountoutstanding, debit_type_code, status, interface, itemnumber)
26
                          VALUES (?, ?, 'OVERDUE', 'UNRETURNED', 'test', ?)`,
27
                    values: [
28
                        patron.patron_id,
29
                        fine_amount,
30
                        objects.item.item_id,
31
                    ],
32
                });
33
34
                cy.wrap(objects).as("testObjects");
35
            });
36
        });
37
38
        afterEach(function () {
39
            // Clean up
40
            cy.task("deleteSampleObjects", [this.testObjects]);
41
42
            // Reset system preferences
43
            cy.task("query", {
44
                sql: "UPDATE systempreferences SET value = '100' WHERE variable = 'FineNoRenewals'",
45
            });
46
            cy.task("query", {
47
                sql: "UPDATE systempreferences SET value = '0' WHERE variable = 'AllowFineOverrideRenewing'",
48
            });
49
        });
50
51
        it("should block renewal when patron has fines over FineNoRenewals limit", function () {
52
            const barcode = this.testObjects.item.barcode;
53
54
            // Visit renewal page
55
            cy.visit("/cgi-bin/koha/circ/renew.pl");
56
57
            // Enter barcode
58
            cy.get("#barcode").type(barcode);
59
            cy.get("form").submit();
60
61
            // Should see error message about patron debt
62
            cy.get(".dialog.alert").should("be.visible");
63
            cy.get(".dialog.alert li").should(
64
                "contain",
65
                `The patron has a debt of`
66
            );
67
        });
68
69
        it("should show override button when AllowFineOverrideRenewing is enabled", function () {
70
            // Enable AllowFineOverrideRenewing
71
            cy.task("query", {
72
                sql: "UPDATE systempreferences SET value = '1' WHERE variable = 'AllowFineOverrideRenewing'",
73
            });
74
75
            const barcode = this.testObjects.item.barcode;
76
77
            // Visit renewal page
78
            cy.visit("/cgi-bin/koha/circ/renew.pl");
79
80
            // Enter barcode
81
            cy.get("#barcode").type(barcode);
82
            cy.get("form").submit();
83
84
            // Should see error message about patron debt
85
            cy.get(".dialog.alert").should("be.visible");
86
            cy.get(".dialog.alert li").should(
87
                "contain",
88
                `The patron has a debt of`
89
            );
90
91
            // Should see override button
92
            cy.get('.dialog.alert form button[type="submit"].approve').should(
93
                "be.visible"
94
            );
95
            cy.get('.dialog.alert form button[type="submit"].approve').should(
96
                "contain",
97
                "Renew checkout(s)"
98
            );
99
        });
100
101
        it("should NOT show override button when AllowFineOverrideRenewing is disabled", function () {
102
            // Ensure AllowFineOverrideRenewing is disabled
103
            cy.task("query", {
104
                sql: "UPDATE systempreferences SET value = '0' WHERE variable = 'AllowFineOverrideRenewing'",
105
            });
106
107
            const barcode = this.testObjects.item.barcode;
108
109
            // Visit renewal page
110
            cy.visit("/cgi-bin/koha/circ/renew.pl");
111
112
            // Enter barcode
113
            cy.get("#barcode").type(barcode);
114
            cy.get("form").submit();
115
116
            // Should see error message about patron debt
117
            cy.get(".dialog.alert").should("be.visible");
118
            cy.get(".dialog.alert li").should(
119
                "contain",
120
                `The patron has a debt of`
121
            );
122
123
            // Should NOT see override button
124
            cy.get('.dialog.alert form button[type="submit"].approve').should(
125
                "not.exist"
126
            );
127
        });
128
129
        it("should allow renewal after override when AllowFineOverrideRenewing is enabled", function () {
130
            // Enable AllowFineOverrideRenewing
131
            cy.task("query", {
132
                sql: "UPDATE systempreferences SET value = '1' WHERE variable = 'AllowFineOverrideRenewing'",
133
            });
134
135
            const barcode = this.testObjects.item.barcode;
136
137
            // Visit renewal page
138
            cy.visit("/cgi-bin/koha/circ/renew.pl");
139
140
            // Enter barcode
141
            cy.get("#barcode").type(barcode);
142
            cy.get("form").submit();
143
144
            // Click override button
145
            cy.get('.dialog.alert form button[type="submit"].approve').click();
146
147
            // Should see success message
148
            cy.get(".dialog.message").should("be.visible");
149
            cy.get(".dialog.message").should("contain", "Item renewed");
150
        });
151
152
        it("should allow renewal when patron has fines below FineNoRenewals limit", function () {
153
            // Delete the existing fine
154
            cy.task("query", {
155
                sql: "DELETE FROM accountlines WHERE borrowernumber = ?",
156
                values: [patron.patron_id],
157
            });
158
159
            // Add a smaller fine (below limit)
160
            cy.task("query", {
161
                sql: `INSERT INTO accountlines (borrowernumber, amountoutstanding, debit_type_code, status, interface, itemnumber)
162
                      VALUES (?, 3.00, 'OVERDUE', 'UNRETURNED', 'test', ?)`,
163
                values: [patron.patron_id, this.testObjects.item.item_id],
164
            });
165
166
            const barcode = this.testObjects.item.barcode;
167
168
            // Visit renewal page
169
            cy.visit("/cgi-bin/koha/circ/renew.pl");
170
171
            // Enter barcode
172
            cy.get("#barcode").type(barcode);
173
            cy.get("form").submit();
174
175
            // Should see success message (no error about fines)
176
            cy.get(".dialog.message").should("be.visible");
177
            cy.get(".dialog.message").should("contain", "Item renewed");
178
        });
179
    });
180
});

Return to bug 23415