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

(-)a/t/cypress/integration/Acquisitions/Vendors_spec.ts (-23 / +61 lines)
Lines 232-263 describe("Vendor CRUD operations", () => { Link Here
232
            .contains("Vendor")
232
            .contains("Vendor")
233
            .contains("deleted");
233
            .contains("deleted");
234
    });
234
    });
235
});
235
236
236
    it("receive should open in the same tab", () => {
237
describe("Vendor module", () => {
237
        const vendor = cy.getVendor();
238
    beforeEach(() => {
238
        vendor.baskets_count = 1;
239
        cy.login();
240
        cy.title().should("eq", "Koha staff interface");
239
241
240
        cy.intercept("GET", "/api/v1/acquisitions/vendors\?*", {
242
        cy.task("buildSampleObject", {
241
            statusCode: 200,
243
            object: "vendor",
242
            body: [vendor],
244
            values: { active: 1 },
243
            headers: {
245
        })
244
                "X-Base-Total-Count": "1",
246
            .then(generatedVendor => {
245
                "X-Total-Count": "1",
247
                delete generatedVendor.list_currency;
246
            },
248
                delete generatedVendor.invoice_currency;
247
        });
249
                return cy.task("insertObject", {
248
        cy.intercept(
250
                    type: "vendor",
249
            "GET",
251
                    object: generatedVendor,
250
            new RegExp("/api/v1/acquisitions/vendors/(?!config$).+"),
252
                });
251
            vendor
253
            })
252
        );
254
            .then(vendor => {
255
                cy.wrap(vendor).as("vendor");
256
                return cy.task("buildSampleObject", {
257
                    object: "basket",
258
                    values: { vendor_id: vendor.id },
259
                });
260
            })
261
            .then(generatedBasket => {
262
                return cy.task("insertObject", {
263
                    type: "basket",
264
                    object: generatedBasket,
265
                });
266
            })
267
            .then(basket => {
268
                cy.wrap(basket).as("basket");
269
            });
270
    });
271
272
    afterEach(function () {
273
        cy.task("deleteSampleObjects", [
274
            { vendor: this.vendor, basket: this.basket },
275
        ]);
276
    });
277
278
    it("receive should open in the same tab", function () {
253
        cy.visit("/cgi-bin/koha/acquisition/vendors");
279
        cy.visit("/cgi-bin/koha/acquisition/vendors");
254
280
255
        cy.get("#vendors_list table tbody tr:first")
281
        // table_id is currently 'DataTables_Table_0', and it should be fixed
256
            .contains("Receive shipments")
282
        cy.get("#vendors_list table.dataTable")
257
            .click();
283
            .invoke("attr", "id")
258
        cy.url().should(
284
            .then(table_id => {
259
            "contain",
285
                cy.intercept("GET", "/api/v1/acquisitions/vendors*").as(
260
            "/cgi-bin/koha/acqui/parcels.pl?booksellerid=1"
286
                    "get-vendors"
261
        );
287
                );
288
                cy.get(`#${table_id}_wrapper input.dt-input`).type(
289
                    this.vendor.name
290
                );
291
                cy.wait("@get-vendors");
292
                cy.get(`#${table_id} tbody tr:first`)
293
                    .contains("Receive shipments")
294
                    .click();
295
                cy.url().should(
296
                    "contain",
297
                    `/cgi-bin/koha/acqui/parcels.pl?booksellerid=${this.vendor.id}`
298
                );
299
            });
262
    });
300
    });
263
});
301
});
(-)a/t/cypress/plugins/insertData.js (-1 / +61 lines)
Lines 333-338 const deleteSampleObjects = async allObjects => { Link Here
333
        hold: "holds",
333
        hold: "holds",
334
        checkout: "checkouts",
334
        checkout: "checkouts",
335
        old_checkout: "old_checkouts",
335
        old_checkout: "old_checkouts",
336
        basket: "baskets",
337
        vendor: "vendors",
336
        patron: "patrons",
338
        patron: "patrons",
337
        item: "items",
339
        item: "items",
338
        biblio: "biblios",
340
        biblio: "biblios",
Lines 360-365 const deleteSampleObjects = async allObjects => { Link Here
360
        "holds",
362
        "holds",
361
        "checkouts",
363
        "checkouts",
362
        "old_checkouts",
364
        "old_checkouts",
365
        "baskets",
366
        "vendors",
363
        "patrons",
367
        "patrons",
364
        "items",
368
        "items",
365
        "biblios",
369
        "biblios",
Lines 431-436 const deleteSampleObjects = async allObjects => { Link Here
431
                    values: ids,
435
                    values: ids,
432
                });
436
                });
433
                break;
437
                break;
438
            case "baskets":
439
                ids = objects.map(i => i.basket_id);
440
                await query({
441
                    sql: `DELETE FROM aqbasket WHERE basketno IN (${ids.map(() => "?").join(",")})`,
442
                    values: ids,
443
                });
444
                break;
445
            case "vendors":
446
                ids = objects.map(i => i.id);
447
                await query({
448
                    sql: `DELETE FROM aqbooksellers WHERE id IN (${ids.map(() => "?").join(",")})`,
449
                    values: ids,
450
                });
451
                break;
434
            default:
452
            default:
435
                throw Error(
453
                throw Error(
436
                    `Not implemented yet: cannot deleted object '${type}'`
454
                    `Not implemented yet: cannot deleted object '${type}'`
Lines 544-549 const insertObject = async ({ type, object, baseUrl, authHeader }) => { Link Here
544
            baseUrl,
562
            baseUrl,
545
            authHeader,
563
            authHeader,
546
        });
564
        });
565
    } else if (type == "vendor") {
566
        const {
567
            id,
568
            baskets_count,
569
            invoices_count,
570
            subscriptions_count,
571
            external_id,
572
            aliases,
573
            baskets,
574
            contacts,
575
            contracts,
576
            interfaces,
577
            invoices,
578
            ...vendor
579
        } = object;
580
581
        let endpoint = "/api/v1/acquisitions/vendors";
582
583
        return apiPost({
584
            endpoint,
585
            body: vendor,
586
            baseUrl,
587
            authHeader,
588
        });
589
    } else if (type == "basket") {
590
        const keysToKeep = ["name", "vendor_id", "close_date"];
591
        const basket = Object.fromEntries(
592
            Object.entries(object).filter(([key]) => keysToKeep.includes(key))
593
        );
594
        return query({
595
            sql: "INSERT INTO aqbasket(basketname, booksellerid, closedate) VALUES (?, ?, ?)",
596
            values: [basket.name, basket.vendor_id, basket.close_date],
597
        })
598
            .then(result => {
599
                const basket_id = result.insertId;
600
                // FIXME We need /acquisitions/baskets/:basket_id
601
                return apiGet({
602
                    endpoint: `/api/v1/acquisitions/baskets?q={"basket_id":"${basket_id}"}`,
603
                    baseUrl,
604
                    authHeader,
605
                });
606
            })
607
            .then(baskets => baskets[0]);
547
    } else {
608
    } else {
548
        throw Error(`Unsupported object type '${type}' to insert`);
609
        throw Error(`Unsupported object type '${type}' to insert`);
549
    }
610
    }
550
- 

Return to bug 40430