diff --git a/api/v1/swagger/paths/acquisitions_vendors.yaml b/api/v1/swagger/paths/acquisitions_vendors.yaml index 73839cd342..d18cec83e5 100644 --- a/api/v1/swagger/paths/acquisitions_vendors.yaml +++ b/api/v1/swagger/paths/acquisitions_vendors.yaml @@ -152,6 +152,7 @@ - aliases - baskets+count - subscriptions+count + - invoices - invoices+count - interfaces - contacts diff --git a/t/cypress/integration/Acquisitions/Invoices_spec.ts b/t/cypress/integration/Acquisitions/Invoices_spec.ts new file mode 100644 index 0000000000..3ebe055223 --- /dev/null +++ b/t/cypress/integration/Acquisitions/Invoices_spec.ts @@ -0,0 +1,76 @@ +describe("Invoices - Files for invoices", () => { + beforeEach(() => { + cy.login(); + cy.title().should("eq", "Koha staff interface"); + + cy.task("buildSampleObject", { + object: "vendor", + values: { active: 1 }, + }) + .then(generatedVendor => { + delete generatedVendor.list_currency; + delete generatedVendor.invoice_currency; + return cy.task("insertObject", { + type: "vendor", + object: generatedVendor, + }); + }) + .then(vendor => { + cy.wrap(vendor).as("vendor"); + return cy.task("buildSampleObject", { + object: "invoice", + values: { vendor_id: vendor.id }, + }); + }) + .then(generatedInvoice => { + return cy.task("insertObject", { + type: "invoice", + object: generatedInvoice, + }); + }) + .then(invoice => { + cy.wrap(invoice).as("invoice"); + }); + + cy.task("query", { + sql: "SELECT value FROM systempreferences WHERE variable='AcqEnableFiles'", + }).then(value => { + cy.wrap(value).as("syspref_AcqEnableFiles"); + }); + }); + + afterEach(function () { + cy.task("deleteSampleObjects", [ + { vendor: this.vendor, invoice: this.invoice }, + ]); + cy.set_syspref("AcqEnableFiles", this.syspref_AcqEnableFiles); + }); + + it("should return 404 if AcqEnableFiles is disabled", function () { + const invoice = this.invoice; + cy.set_syspref("AcqEnableFiles", 0).then(() => { + cy.intercept( + `/cgi-bin/koha/acqui/invoice-files.pl?invoiceid=${invoice.invoice_id}` + ).as("show-invoice"); + cy.visit( + `/cgi-bin/koha/acqui/invoice-files.pl?invoiceid=${invoice.invoice_id}`, + { failOnStatusCode: false } + ); + cy.wait("@show-invoice") + .its("response.statusCode") + .should("equal", 404); + }); + }); + + it("should not return 404 if AcqEnableFiles is enabled", function () { + const invoice = this.invoice; + cy.set_syspref("AcqEnableFiles", 1).then(() => { + cy.visit( + `/cgi-bin/koha/acqui/invoice-files.pl?invoiceid=${invoice.invoice_id}` + ); + cy.get("h1").contains( + `Files for invoice: ${invoice.invoice_number}` + ); + }); + }); +}); diff --git a/t/cypress/plugins/insertData.js b/t/cypress/plugins/insertData.js index 3aa062611a..e7a90c726d 100644 --- a/t/cypress/plugins/insertData.js +++ b/t/cypress/plugins/insertData.js @@ -808,6 +808,40 @@ const insertObject = async ({ type, object, baseUrl, authHeader }) => { }); }) .then(baskets => baskets[0]); + } else if (type == "invoice") { + const keysToKeep = [ + "invoice_number", + "vendor_id", + "shipping_date", + "invoice_date", + ]; + const invoice = Object.fromEntries( + Object.entries(object).filter(([key]) => keysToKeep.includes(key)) + ); + return query({ + sql: "INSERT INTO aqinvoices(invoicenumber, booksellerid, shipmentdate, billingdate) VALUES (?, ?, ?, ?)", + values: [ + invoice.invoice_number, + invoice.vendor_id, + invoice.shipping_date, + invoice.invoice_date, + ], + }) + .then(result => { + const invoice_id = result.insertId; + // FIXME We need /acquisitions/invoices/:invoice_id + return apiGet({ + endpoint: `/api/v1/acquisitions/vendors/${invoice.vendor_id}`, + headers: { "x-koha-embed": "invoices" }, + baseUrl, + authHeader, + }); + }) + .then(vendor => + vendor.invoices.find( + i => i.invoice_number == invoice.invoice_number + ) + ); } else { throw Error(`Unsupported object type '${type}' to insert`); }