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