Bug 40301: Add insertSampleCheckout
Signed-off-by: Owen Leonard <oleonard@myacpl.org>
Signed-off-by: Martin Renvoize <martin.renvoize@openfifth.co.uk>
Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>
(cherry picked from commit 19843bd9ba)
Signed-off-by: Paul Derscheid <paul.derscheid@lmscloud.de>
This commit is contained in:
parent
f8e6f72f26
commit
ab57ff4c63
|
|
@ -8,6 +8,7 @@ describe("insertData", () => {
|
|||
"items",
|
||||
"biblio",
|
||||
"reserves",
|
||||
"issues",
|
||||
];
|
||||
beforeEach(() => {
|
||||
const counts = {};
|
||||
|
|
@ -215,6 +216,22 @@ describe("insertData", () => {
|
|||
});
|
||||
});
|
||||
|
||||
describe("insertSampleCheckout", () => {
|
||||
it("insertSampleCheckout - without parameter", () => {
|
||||
cy.task("insertSampleCheckout").then(objects_checkout => {
|
||||
cy.task("apiGet", {
|
||||
endpoint: `/api/v1/checkouts/${objects_checkout.checkout.checkout_id}`,
|
||||
}).then(checkout => {
|
||||
expect(checkout.item_id).to.be.equal(
|
||||
objects_checkout.items[0].item_id
|
||||
);
|
||||
});
|
||||
|
||||
cy.task("deleteSampleObjects", objects_checkout);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
afterEach(function () {
|
||||
cy.get("@initialCounts").then(initialCounts => {
|
||||
const queries = tablesToCheck.map(table => {
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ const { buildSampleObject, buildSampleObjects } = require("./mockData.js");
|
|||
const {
|
||||
insertSampleBiblio,
|
||||
insertSampleHold,
|
||||
insertSampleCheckout,
|
||||
insertObject,
|
||||
deleteSampleObjects,
|
||||
} = require("./insertData.js");
|
||||
|
|
@ -43,6 +44,9 @@ module.exports = (on, config) => {
|
|||
insertSampleHold(args) {
|
||||
return insertSampleHold({ ...args, baseUrl, authHeader });
|
||||
},
|
||||
insertSampleCheckout(args) {
|
||||
return insertSampleCheckout({ ...args, baseUrl, authHeader });
|
||||
},
|
||||
insertObject(args) {
|
||||
return insertObject({ ...args, baseUrl, authHeader });
|
||||
},
|
||||
|
|
|
|||
|
|
@ -205,6 +205,47 @@ const insertSampleHold = async ({
|
|||
return { hold, patron };
|
||||
};
|
||||
|
||||
const insertSampleCheckout = async ({ baseUrl, authHeader }) => {
|
||||
const { biblio, items, libraries, item_type } = await insertSampleBiblio({
|
||||
item_count: 1,
|
||||
baseUrl,
|
||||
authHeader,
|
||||
});
|
||||
const generatedPatron = await buildSampleObject({
|
||||
object: "patron",
|
||||
values: {
|
||||
library_id: libraries[0].library_id,
|
||||
incorrect_address: null,
|
||||
patron_card_lost: null,
|
||||
},
|
||||
baseUrl,
|
||||
authHeader,
|
||||
});
|
||||
|
||||
const patron = await insertObject({
|
||||
type: "patron",
|
||||
object: generatedPatron,
|
||||
baseUrl,
|
||||
authHeader,
|
||||
});
|
||||
|
||||
const generatedCheckout = buildSampleObject({
|
||||
object: "checkout",
|
||||
values: {
|
||||
patron_id: patron.patron_id,
|
||||
item_id: items[0].item_id,
|
||||
},
|
||||
});
|
||||
delete generatedCheckout.external_id;
|
||||
const checkout = await insertObject({
|
||||
type: "checkout",
|
||||
object: generatedCheckout,
|
||||
baseUrl,
|
||||
authHeader,
|
||||
});
|
||||
return { biblio, items, libraries, item_type, patron, checkout };
|
||||
};
|
||||
|
||||
const deleteSampleObjects = async allObjects => {
|
||||
if (!Array.isArray(allObjects)) {
|
||||
allObjects = [allObjects];
|
||||
|
|
@ -212,6 +253,7 @@ const deleteSampleObjects = async allObjects => {
|
|||
|
||||
const pluralMap = {
|
||||
hold: "holds",
|
||||
checkout: "checkouts",
|
||||
patron: "patrons",
|
||||
item: "items",
|
||||
biblio: "biblios",
|
||||
|
|
@ -237,6 +279,7 @@ const deleteSampleObjects = async allObjects => {
|
|||
|
||||
const deletionOrder = [
|
||||
"holds",
|
||||
"checkouts",
|
||||
"patrons",
|
||||
"items",
|
||||
"biblios",
|
||||
|
|
@ -280,6 +323,13 @@ const deleteSampleObjects = async allObjects => {
|
|||
values: ids,
|
||||
});
|
||||
break;
|
||||
case "checkouts":
|
||||
ids = objects.map(i => i.checkout_id);
|
||||
await query({
|
||||
sql: `DELETE FROM issues WHERE issue_id IN (${ids.map(() => "?").join(",")})`,
|
||||
values: ids,
|
||||
});
|
||||
break;
|
||||
case "item_types":
|
||||
ids = objects.map(i => i.item_type_id);
|
||||
await query({
|
||||
|
|
@ -431,6 +481,15 @@ const insertObject = async ({ type, object, baseUrl, authHeader }) => {
|
|||
baseUrl,
|
||||
authHeader,
|
||||
});
|
||||
} else if (type == "checkout") {
|
||||
const { issuer, patron, ...checkout } = object;
|
||||
|
||||
return apiPost({
|
||||
endpoint: "/api/v1/checkouts",
|
||||
body: checkout,
|
||||
baseUrl,
|
||||
authHeader,
|
||||
});
|
||||
} else {
|
||||
throw Error(`Unsupported object type '${type}' to insert`);
|
||||
}
|
||||
|
|
@ -441,6 +500,7 @@ const insertObject = async ({ type, object, baseUrl, authHeader }) => {
|
|||
module.exports = {
|
||||
insertSampleBiblio,
|
||||
insertSampleHold,
|
||||
insertSampleCheckout,
|
||||
insertObject,
|
||||
deleteSampleObjects,
|
||||
};
|
||||
|
|
|
|||
Loading…
Reference in New Issue