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

(-)a/t/cypress/integration/t/insertData.ts (-1 / +20 lines)
Lines 7-19 const { APIClient } = require("./../../plugins/dist/api-client.cjs.js"); Link Here
7
let client = APIClient.default;
7
let client = APIClient.default;
8
8
9
describe("insertData", () => {
9
describe("insertData", () => {
10
11
    let tablesToCheck = [
10
    let tablesToCheck = [
12
        "borrowers",
11
        "borrowers",
13
        "branches",
12
        "branches",
14
        "items",
13
        "items",
15
        "biblio",
14
        "biblio",
16
        "reserves",
15
        "reserves",
16
        "issues",
17
    ];
17
    ];
18
    beforeEach(() => {
18
    beforeEach(() => {
19
        const counts = {};
19
        const counts = {};
Lines 202-207 describe("insertData", () => { Link Here
202
        });
202
        });
203
    });
203
    });
204
204
205
    describe("insertSampleCheckout", () => {
206
        it("insertSampleCheckout - without parameter", () => {
207
            cy.task("insertSampleCheckout").then(objects_checkout => {
208
                cy.task("apiGet", {
209
                    endpoint: `/api/v1/checkouts/${objects_checkout.checkout.checkout_id}`,
210
                    headers: {
211
                        "Content-Type": "application/json",
212
                    },
213
                }).then(checkout => {
214
                    expect(checkout.item_id).to.be.equal(
215
                        objects_checkout.items[0].item_id
216
                    );
217
                });
218
219
                cy.task("deleteSampleObjects", [objects_checkout]);
220
            });
221
        });
222
    });
223
205
    afterEach(function () {
224
    afterEach(function () {
206
        cy.get("@initialCounts").then(initialCounts => {
225
        cy.get("@initialCounts").then(initialCounts => {
207
            const queries = tablesToCheck.map(table => {
226
            const queries = tablesToCheck.map(table => {
(-)a/t/cypress/plugins/index.js (+4 lines)
Lines 5-10 const { buildSampleObject, buildSampleObjects } = require("./mockData.js"); Link Here
5
const {
5
const {
6
    insertSampleBiblio,
6
    insertSampleBiblio,
7
    insertSampleHold,
7
    insertSampleHold,
8
    insertSampleCheckout,
8
    insertObject,
9
    insertObject,
9
    deleteSampleObjects,
10
    deleteSampleObjects,
10
} = require("./insertData.js");
11
} = require("./insertData.js");
Lines 43-48 module.exports = (on, config) => { Link Here
43
        insertSampleHold(args) {
44
        insertSampleHold(args) {
44
            return insertSampleHold({ ...args, baseUrl, authHeader });
45
            return insertSampleHold({ ...args, baseUrl, authHeader });
45
        },
46
        },
47
        insertSampleCheckout(args) {
48
            return insertSampleCheckout({ ...args, baseUrl, authHeader });
49
        },
46
        insertObject(args) {
50
        insertObject(args) {
47
            return insertObject({ ...args, baseUrl, authHeader });
51
            return insertObject({ ...args, baseUrl, authHeader });
48
        },
52
        },
(-)a/t/cypress/plugins/insertData.js (-3 / +64 lines)
Lines 212-217 const insertSampleHold = async ({ Link Here
212
    return { hold, patron };
212
    return { hold, patron };
213
};
213
};
214
214
215
const insertSampleCheckout = async ({ baseUrl, authHeader }) => {
216
    let client = APIClient.default;
217
218
    const { biblio, items, libraries, item_type } = await insertSampleBiblio({
219
        item_count: 1,
220
        baseUrl,
221
        authHeader,
222
    });
223
    const generatedPatron = await buildSampleObject({
224
        object: "patron",
225
        values: {
226
            library_id: libraries[0].library_id,
227
            incorrect_address: null,
228
            patron_card_lost: null,
229
        },
230
        baseUrl,
231
        authHeader,
232
    });
233
234
    const patron = await insertObject({
235
        type: "patron",
236
        object: generatedPatron,
237
        baseUrl,
238
        authHeader,
239
    });
240
241
    const generatedCheckout = buildSampleObject({
242
        object: "checkout",
243
        values: {
244
            patron_id: patron.patron_id,
245
            item_id: items[0].item_id,
246
        },
247
    });
248
    delete generatedCheckout.external_id;
249
    const checkout = await insertObject({
250
        type: "checkout",
251
        object: generatedCheckout,
252
        baseUrl,
253
        authHeader,
254
    });
255
    return { biblio, items, libraries, item_type, patron, checkout };
256
};
257
215
const deleteSampleObjects = async allObjects => {
258
const deleteSampleObjects = async allObjects => {
216
    if (!Array.isArray(allObjects)) {
259
    if (!Array.isArray(allObjects)) {
217
        allObjects = [allObjects];
260
        allObjects = [allObjects];
Lines 219-224 const deleteSampleObjects = async allObjects => { Link Here
219
262
220
    const deletionOrder = [
263
    const deletionOrder = [
221
        "hold",
264
        "hold",
265
        "checkout",
222
        "patron",
266
        "patron",
223
        "item",
267
        "item",
224
        "items",
268
        "items",
Lines 276-281 const deleteSampleObjects = async allObjects => { Link Here
276
                        values: [objects[type].hold_id],
320
                        values: [objects[type].hold_id],
277
                    });
321
                    });
278
                    break;
322
                    break;
323
                case "checkout":
324
                    await query({
325
                        sql: "DELETE FROM issues WHERE issue_id = ?",
326
                        values: [objects[type].checkout_id],
327
                    });
328
                    break;
279
                case "item_type":
329
                case "item_type":
280
                    await query({
330
                    await query({
281
                        sql: "DELETE FROM itemtypes WHERE itemtype = ?",
331
                        sql: "DELETE FROM itemtypes WHERE itemtype = ?",
Lines 289-295 const deleteSampleObjects = async allObjects => { Link Here
289
                    });
339
                    });
290
                    break;
340
                    break;
291
                default:
341
                default:
292
                    console.log(
342
                    throw Error(
293
                        `Not implemented yet: cannot deleted object '${type}'`
343
                        `Not implemented yet: cannot deleted object '${type}'`
294
                    );
344
                    );
295
            }
345
            }
Lines 438-445 const insertObject = async ({ type, object, baseUrl, authHeader }) => { Link Here
438
            },
488
            },
439
            body: hold,
489
            body: hold,
440
        });
490
        });
491
    } else if (type == "checkout") {
492
        const { issuer, patron, ...checkout } = object;
493
494
        return client.koha.post({
495
            endpoint: `${baseUrl}/api/v1/checkouts`,
496
            headers: {
497
                "Content-Type": "application/json",
498
                Authorization: authHeader,
499
            },
500
            body: checkout,
501
        });
441
    } else {
502
    } else {
442
        return false;
503
        throw Error(`Unsupported object type '${type}' to insert`);
443
    }
504
    }
444
505
445
    return true;
506
    return true;
Lines 448-453 const insertObject = async ({ type, object, baseUrl, authHeader }) => { Link Here
448
module.exports = {
509
module.exports = {
449
    insertSampleBiblio,
510
    insertSampleBiblio,
450
    insertSampleHold,
511
    insertSampleHold,
512
    insertSampleCheckout,
451
    insertObject,
513
    insertObject,
452
    deleteSampleObjects,
514
    deleteSampleObjects,
453
};
515
};
454
- 

Return to bug 40301