|
Lines 1-78
Link Here
|
| 1 |
const { query } = require("./../../plugins/db.js"); |
1 |
const { query } = require("./../../plugins/db.js"); |
|
|
2 |
const { APIClient } = require("./../../plugins/dist/api-client.cjs.js"); |
| 3 |
const { getBasicAuthHeader } = require("./../../plugins/auth.js"); |
| 2 |
|
4 |
|
| 3 |
describe("insertSampleBiblio", () => { |
5 |
const { APIClient } = require("./../../plugins/dist/api-client.cjs.js"); |
| 4 |
it("insertSampleBiblio - should generate library and item type", () => { |
|
|
| 5 |
cy.task("insertSampleBiblio", { item_count: 3 }).then(objects => { |
| 6 |
expect(typeof objects.biblio.biblio_id).to.be.equal("number"); |
| 7 |
expect(typeof objects.biblio.title).to.be.equal("string"); |
| 8 |
expect(typeof objects.biblio.author).to.be.equal("string"); |
| 9 |
|
6 |
|
| 10 |
const biblio_id = objects.biblio.biblio_id; |
7 |
let client = APIClient.default; |
| 11 |
|
8 |
|
| 12 |
cy.task("query", { |
9 |
describe("insertData", () => { |
| 13 |
sql: "SELECT COUNT(*) as count FROM biblio WHERE biblionumber=?", |
10 |
describe("insertSampleBiblio", () => { |
| 14 |
values: [biblio_id], |
11 |
it("should generate library and item type", () => { |
| 15 |
}).then(result => { |
12 |
cy.task("insertSampleBiblio", { item_count: 3 }).then(objects => { |
| 16 |
expect(result[0].count).to.be.equal(1); |
13 |
expect(typeof objects.biblio.biblio_id).to.be.equal("number"); |
| 17 |
}); |
14 |
expect(typeof objects.biblio.title).to.be.equal("string"); |
|
|
15 |
expect(typeof objects.biblio.author).to.be.equal("string"); |
| 18 |
|
16 |
|
| 19 |
cy.task("query", { |
17 |
const biblio_id = objects.biblio.biblio_id; |
| 20 |
sql: "SELECT COUNT(*) as count FROM items WHERE biblionumber=?", |
|
|
| 21 |
values: [biblio_id], |
| 22 |
}).then(result => { |
| 23 |
expect(result[0].count).to.be.equal(3); |
| 24 |
}); |
| 25 |
|
18 |
|
| 26 |
cy.task("query", { |
19 |
cy.task("query", { |
| 27 |
sql: "SELECT DISTINCT(itype) as count FROM items WHERE biblionumber=?", |
20 |
sql: "SELECT COUNT(*) as count FROM biblio WHERE biblionumber=?", |
| 28 |
values: [biblio_id], |
21 |
values: [biblio_id], |
| 29 |
}).then(result => { |
22 |
}).then(result => { |
| 30 |
expect(result.length).to.be.equal(1); |
23 |
expect(result[0].count).to.be.equal(1); |
| 31 |
}); |
24 |
}); |
| 32 |
|
25 |
|
| 33 |
cy.task("query", { |
26 |
cy.task("query", { |
| 34 |
sql: "SELECT COUNT(*) as count FROM branches WHERE branchcode=?", |
27 |
sql: "SELECT COUNT(*) as count FROM items WHERE biblionumber=?", |
| 35 |
values: [objects.libraries[0].library_id], |
28 |
values: [biblio_id], |
| 36 |
}).then(result => { |
29 |
}).then(result => { |
| 37 |
expect(result[0].count).to.be.equal(1); |
30 |
expect(result[0].count).to.be.equal(3); |
| 38 |
}); |
31 |
}); |
| 39 |
|
32 |
|
| 40 |
cy.task("query", { |
33 |
cy.task("query", { |
| 41 |
sql: "SELECT COUNT(*) as count FROM itemtypes WHERE itemtype=?", |
34 |
sql: "SELECT DISTINCT(itype) as count FROM items WHERE biblionumber=?", |
| 42 |
values: [objects.item_type.item_type_id], |
35 |
values: [biblio_id], |
| 43 |
}).then(result => { |
36 |
}).then(result => { |
| 44 |
expect(result[0].count).to.be.equal(1); |
37 |
expect(result.length).to.be.equal(1); |
| 45 |
}); |
38 |
}); |
| 46 |
|
39 |
|
| 47 |
cy.task("deleteSampleObjects", objects); |
40 |
cy.task("query", { |
|
|
41 |
sql: "SELECT COUNT(*) as count FROM branches WHERE branchcode=?", |
| 42 |
values: [objects.libraries[0].library_id], |
| 43 |
}).then(result => { |
| 44 |
expect(result[0].count).to.be.equal(1); |
| 45 |
}); |
| 48 |
|
46 |
|
| 49 |
cy.task("query", { |
47 |
cy.task("query", { |
| 50 |
sql: "SELECT COUNT(*) as count FROM biblio WHERE biblionumber=?", |
48 |
sql: "SELECT COUNT(*) as count FROM itemtypes WHERE itemtype=?", |
| 51 |
values: [biblio_id], |
49 |
values: [objects.item_type.item_type_id], |
| 52 |
}).then(result => { |
50 |
}).then(result => { |
| 53 |
expect(result[0].count).to.be.equal(0); |
51 |
expect(result[0].count).to.be.equal(1); |
| 54 |
}); |
52 |
}); |
| 55 |
|
53 |
|
| 56 |
cy.task("query", { |
54 |
cy.task("deleteSampleObjects", objects); |
| 57 |
sql: "SELECT COUNT(*) as count FROM items WHERE biblionumber=?", |
55 |
|
| 58 |
values: [biblio_id], |
56 |
cy.task("query", { |
| 59 |
}).then(result => { |
57 |
sql: "SELECT COUNT(*) as count FROM biblio WHERE biblionumber=?", |
| 60 |
expect(result[0].count).to.be.equal(0); |
58 |
values: [biblio_id], |
| 61 |
}); |
59 |
}).then(result => { |
|
|
60 |
expect(result[0].count).to.be.equal(0); |
| 61 |
}); |
| 62 |
|
| 63 |
cy.task("query", { |
| 64 |
sql: "SELECT COUNT(*) as count FROM items WHERE biblionumber=?", |
| 65 |
values: [biblio_id], |
| 66 |
}).then(result => { |
| 67 |
expect(result[0].count).to.be.equal(0); |
| 68 |
}); |
| 62 |
|
69 |
|
| 63 |
cy.task("query", { |
70 |
cy.task("query", { |
| 64 |
sql: "SELECT COUNT(*) as count FROM branches WHERE branchcode=?", |
71 |
sql: "SELECT COUNT(*) as count FROM branches WHERE branchcode=?", |
| 65 |
values: [objects.libraries[0].library_id], |
72 |
values: [objects.libraries[0].library_id], |
| 66 |
}).then(result => { |
73 |
}).then(result => { |
| 67 |
expect(result[0].count).to.be.equal(0); |
74 |
expect(result[0].count).to.be.equal(0); |
|
|
75 |
}); |
| 76 |
|
| 77 |
cy.task("query", { |
| 78 |
sql: "SELECT COUNT(*) as count FROM itemtypes WHERE itemtype=?", |
| 79 |
values: [objects.item_type.item_type_id], |
| 80 |
}).then(result => { |
| 81 |
expect(result[0].count).to.be.equal(0); |
| 82 |
}); |
| 68 |
}); |
83 |
}); |
|
|
84 |
}); |
| 85 |
|
| 86 |
it("insertSampleBiblio - options.different_libraries", () => { |
| 87 |
cy.task("insertSampleBiblio", { |
| 88 |
item_count: 3, |
| 89 |
options: { different_libraries: true }, |
| 90 |
}).then(objects => { |
| 91 |
expect(objects.libraries.length).to.be.equal(3); |
| 92 |
let libraries = objects.libraries |
| 93 |
.map(library => library.library_id) |
| 94 |
.sort(); |
| 95 |
let itemsLibraries = objects.items |
| 96 |
.map(item => item.home_library_id) |
| 97 |
.sort(); |
| 98 |
expect(libraries).deep.to.equal(itemsLibraries); |
| 69 |
|
99 |
|
| 70 |
cy.task("query", { |
100 |
cy.task("deleteSampleObjects", objects); |
| 71 |
sql: "SELECT COUNT(*) as count FROM itemtypes WHERE itemtype=?", |
|
|
| 72 |
values: [objects.item_type.item_type_id], |
| 73 |
}).then(result => { |
| 74 |
expect(result[0].count).to.be.equal(0); |
| 75 |
}); |
101 |
}); |
| 76 |
}); |
102 |
}); |
| 77 |
}); |
103 |
}); |
|
|
104 |
|
| 105 |
describe("insertSampleHold", () => { |
| 106 |
it("insertSampleHold - item/biblio", () => { |
| 107 |
cy.task("insertSampleBiblio", { item_count: 2 }).then( |
| 108 |
objects_biblio => { |
| 109 |
cy.task("insertSampleHold", { |
| 110 |
item: objects_biblio.items[0], |
| 111 |
}).then(objects_hold_1 => { |
| 112 |
cy.task("insertSampleHold", { |
| 113 |
biblio: objects_biblio.biblio, |
| 114 |
library_id: objects_biblio.items[0].home_library_id, |
| 115 |
}).then(objects_hold_2 => { |
| 116 |
cy.task("apiGet", { |
| 117 |
// No /holds/:hold_id (yet) |
| 118 |
// No q={} (yet) |
| 119 |
endpoint: `/api/v1/holds?hold_id=${objects_hold_1.hold.hold_id}`, |
| 120 |
headers: { |
| 121 |
"Content-Type": "application/json", |
| 122 |
}, |
| 123 |
}).then(holds => { |
| 124 |
expect(holds.length).to.be.equal(1); |
| 125 |
expect(holds[0].biblio_id).to.be.equal( |
| 126 |
objects_biblio.biblio.biblio_id |
| 127 |
); |
| 128 |
expect(holds[0].item_id).to.be.equal( |
| 129 |
objects_biblio.items[0].item_id |
| 130 |
); |
| 131 |
}); |
| 132 |
cy.task("apiGet", { |
| 133 |
// No /holds/:hold_id (yet) |
| 134 |
// No q={} (yet) |
| 135 |
endpoint: `/api/v1/holds?hold_id=${objects_hold_2.hold.hold_id}`, |
| 136 |
headers: { |
| 137 |
"Content-Type": "application/json", |
| 138 |
}, |
| 139 |
}).then(holds => { |
| 140 |
expect(holds.length).to.be.equal(1); |
| 141 |
expect(holds[0].biblio_id).to.be.equal( |
| 142 |
objects_biblio.biblio.biblio_id |
| 143 |
); |
| 144 |
expect(holds[0].item_id).to.be.equal(null); |
| 145 |
}); |
| 146 |
|
| 147 |
cy.task("deleteSampleObjects", [ |
| 148 |
objects_biblio, |
| 149 |
objects_hold_1, |
| 150 |
objects_hold_2, |
| 151 |
]); |
| 152 |
}); |
| 153 |
}); |
| 154 |
} |
| 155 |
); |
| 156 |
}); |
| 157 |
|
| 158 |
// How to properly test for Error? |
| 159 |
it.skip("insertSampleHold - missing library_id", () => { |
| 160 |
cy.task("insertSampleBiblio", { item_count: 2 }).then( |
| 161 |
objects_biblio => { |
| 162 |
cy.task("insertSampleHold", { |
| 163 |
biblio: objects_biblio.biblio, |
| 164 |
}).then( |
| 165 |
() => { |
| 166 |
throw new Error("Task should have failed"); |
| 167 |
}, |
| 168 |
err => { |
| 169 |
expect(err.message).to.include( |
| 170 |
"Could not generate sample hold without library_id or item" |
| 171 |
); |
| 172 |
} |
| 173 |
); |
| 174 |
} |
| 175 |
); |
| 176 |
}); |
| 177 |
}); |
| 78 |
}); |
178 |
}); |