Bug 41594: Add Cypress tests
* Add Cypress tests to cover the 404 redirect if the pref is disabled * Add "invoices" as possible embed option for /acquisitions/vendors/:vendor_id Seems relevant as the api def for invoice if expecting for it api/v1/swagger/definitions/invoice.yaml * Tell insertObject how to generate an invoice and return it. Unfortunately we don't have a direct route for that, hence the embed on /vendors/:vendor_id Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org> Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl> Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>
This commit is contained in:
parent
4951426642
commit
6aa49457ed
|
|
@ -154,6 +154,7 @@
|
|||
- aliases
|
||||
- baskets+count
|
||||
- subscriptions+count
|
||||
- invoices
|
||||
- invoices+count
|
||||
- interfaces
|
||||
- contacts
|
||||
|
|
|
|||
|
|
@ -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}`
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
@ -823,6 +823,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 if (type === "erm_agreement") {
|
||||
const {
|
||||
agreement_id,
|
||||
|
|
|
|||
Loading…
Reference in New Issue