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

(-)a/t/cypress/integration/t/insertData.ts (+17 lines)
Lines 8-13 describe("insertData", () => { Link Here
8
        "items",
8
        "items",
9
        "biblio",
9
        "biblio",
10
        "reserves",
10
        "reserves",
11
        "issues",
11
    ];
12
    ];
12
    beforeEach(() => {
13
    beforeEach(() => {
13
        const counts = {};
14
        const counts = {};
Lines 215-220 describe("insertData", () => { Link Here
215
        });
216
        });
216
    });
217
    });
217
218
219
    describe("insertSampleCheckout", () => {
220
        it("insertSampleCheckout - without parameter", () => {
221
            cy.task("insertSampleCheckout").then(objects_checkout => {
222
                cy.task("apiGet", {
223
                    endpoint: `/api/v1/checkouts/${objects_checkout.checkout.checkout_id}`,
224
                }).then(checkout => {
225
                    expect(checkout.item_id).to.be.equal(
226
                        objects_checkout.items[0].item_id
227
                    );
228
                });
229
230
                cy.task("deleteSampleObjects", objects_checkout);
231
            });
232
        });
233
    });
234
218
    afterEach(function () {
235
    afterEach(function () {
219
        cy.get("@initialCounts").then(initialCounts => {
236
        cy.get("@initialCounts").then(initialCounts => {
220
            const queries = tablesToCheck.map(table => {
237
            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 (-1 / +60 lines)
Lines 205-210 const insertSampleHold = async ({ Link Here
205
    return { hold, patron };
205
    return { hold, patron };
206
};
206
};
207
207
208
const insertSampleCheckout = async ({ baseUrl, authHeader }) => {
209
    const { biblio, items, libraries, item_type } = await insertSampleBiblio({
210
        item_count: 1,
211
        baseUrl,
212
        authHeader,
213
    });
214
    const generatedPatron = await buildSampleObject({
215
        object: "patron",
216
        values: {
217
            library_id: libraries[0].library_id,
218
            incorrect_address: null,
219
            patron_card_lost: null,
220
        },
221
        baseUrl,
222
        authHeader,
223
    });
224
225
    const patron = await insertObject({
226
        type: "patron",
227
        object: generatedPatron,
228
        baseUrl,
229
        authHeader,
230
    });
231
232
    const generatedCheckout = buildSampleObject({
233
        object: "checkout",
234
        values: {
235
            patron_id: patron.patron_id,
236
            item_id: items[0].item_id,
237
        },
238
    });
239
    delete generatedCheckout.external_id;
240
    const checkout = await insertObject({
241
        type: "checkout",
242
        object: generatedCheckout,
243
        baseUrl,
244
        authHeader,
245
    });
246
    return { biblio, items, libraries, item_type, patron, checkout };
247
};
248
208
const deleteSampleObjects = async allObjects => {
249
const deleteSampleObjects = async allObjects => {
209
    if (!Array.isArray(allObjects)) {
250
    if (!Array.isArray(allObjects)) {
210
        allObjects = [allObjects];
251
        allObjects = [allObjects];
Lines 212-217 const deleteSampleObjects = async allObjects => { Link Here
212
253
213
    const pluralMap = {
254
    const pluralMap = {
214
        hold: "holds",
255
        hold: "holds",
256
        checkout: "checkouts",
215
        patron: "patrons",
257
        patron: "patrons",
216
        item: "items",
258
        item: "items",
217
        biblio: "biblios",
259
        biblio: "biblios",
Lines 237-242 const deleteSampleObjects = async allObjects => { Link Here
237
279
238
    const deletionOrder = [
280
    const deletionOrder = [
239
        "holds",
281
        "holds",
282
        "checkouts",
240
        "patrons",
283
        "patrons",
241
        "items",
284
        "items",
242
        "biblios",
285
        "biblios",
Lines 280-285 const deleteSampleObjects = async allObjects => { Link Here
280
                    values: ids,
323
                    values: ids,
281
                });
324
                });
282
                break;
325
                break;
326
            case "checkouts":
327
                ids = objects.map(i => i.checkout_id);
328
                await query({
329
                    sql: `DELETE FROM issues WHERE issue_id IN (${ids.map(() => "?").join(",")})`,
330
                    values: ids,
331
                });
332
                break;
283
            case "item_types":
333
            case "item_types":
284
                ids = objects.map(i => i.item_type_id);
334
                ids = objects.map(i => i.item_type_id);
285
                await query({
335
                await query({
Lines 431-436 const insertObject = async ({ type, object, baseUrl, authHeader }) => { Link Here
431
            baseUrl,
481
            baseUrl,
432
            authHeader,
482
            authHeader,
433
        });
483
        });
484
    } else if (type == "checkout") {
485
        const { issuer, patron, ...checkout } = object;
486
487
        return apiPost({
488
            endpoint: "/api/v1/checkouts",
489
            body: checkout,
490
            baseUrl,
491
            authHeader,
492
        });
434
    } else {
493
    } else {
435
        throw Error(`Unsupported object type '${type}' to insert`);
494
        throw Error(`Unsupported object type '${type}' to insert`);
436
    }
495
    }
Lines 441-446 const insertObject = async ({ type, object, baseUrl, authHeader }) => { Link Here
441
module.exports = {
500
module.exports = {
442
    insertSampleBiblio,
501
    insertSampleBiblio,
443
    insertSampleHold,
502
    insertSampleHold,
503
    insertSampleCheckout,
444
    insertObject,
504
    insertObject,
445
    deleteSampleObjects,
505
    deleteSampleObjects,
446
};
506
};
447
- 

Return to bug 40301