1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 | var Chai = require('chai');
|
10 | var Expect = Chai.expect;
|
11 | var Assert = Chai.assert;
|
12 |
|
13 | var libFable = require('fable');
|
14 | var libFoxHound = require('../source/FoxHound.js');
|
15 |
|
16 | var _AnimalSchema = (
|
17 | [
|
18 | { Column: "IDAnimal", Type:"AutoIdentity" },
|
19 | { Column: "GUIDAnimal", Type:"AutoGUID" },
|
20 | { Column: "CreateDate", Type:"CreateDate" },
|
21 | { Column: "CreatingIDUser", Type:"CreateIDUser" },
|
22 | { Column: "UpdateDate", Type:"UpdateDate" },
|
23 | { Column: "UpdatingIDUser", Type:"UpdateIDUser" },
|
24 | { Column: "Deleted", Type:"Deleted" },
|
25 | { Column: "DeletingIDUser", Type:"DeleteIDUser" },
|
26 | { Column: "DeleteDate", Type:"DeleteDate" }
|
27 | ]);
|
28 |
|
29 | var _AnimalSchemaWithoutDeleted = (
|
30 | [
|
31 | { Column: "IDAnimal", Type:"AutoIdentity" },
|
32 | { Column: "GUIDAnimal", Type:"AutoGUID" },
|
33 | { Column: "CreateDate", Type:"CreateDate" },
|
34 | { Column: "CreatingIDUser", Type:"CreateIDUser" },
|
35 | { Column: "UpdateDate", Type:"UpdateDate" },
|
36 | { Column: "UpdatingIDUser", Type:"UpdateIDUser" }
|
37 | ]);
|
38 |
|
39 | suite
|
40 | (
|
41 | 'FoxHound-Dialect-MySQL',
|
42 | function()
|
43 | {
|
44 | setup
|
45 | (
|
46 | function()
|
47 | {
|
48 | }
|
49 | );
|
50 |
|
51 | suite
|
52 | (
|
53 | 'Object Sanity',
|
54 | function()
|
55 | {
|
56 | test
|
57 | (
|
58 | 'initialize should build a happy little object',
|
59 | function()
|
60 | {
|
61 | var testFoxHound = libFoxHound.new(libFable).setDialect('MySQL');
|
62 | Expect(testFoxHound.dialect.name)
|
63 | .to.equal('MySQL');
|
64 | Expect(testFoxHound)
|
65 | .to.be.an('object', 'FoxHound with MySQL should initialize as an object directly from the require statement.');
|
66 | }
|
67 | );
|
68 | }
|
69 | );
|
70 |
|
71 | suite
|
72 | (
|
73 | 'Basic Query Generation',
|
74 | function()
|
75 | {
|
76 | test
|
77 | (
|
78 | 'Create Query',
|
79 | function()
|
80 | {
|
81 | var tmpQuery = libFoxHound.new(libFable)
|
82 | .setLogLevel(5)
|
83 | .setDialect('MySQL')
|
84 | .setScope('Animal')
|
85 | .addRecord({IDAnimal:null, Name:'Foo Foo', Age:15});
|
86 |
|
87 | tmpQuery.buildCreateQuery();
|
88 |
|
89 | libFable.log.trace('Create Query', tmpQuery.query);
|
90 | Expect(tmpQuery.query.body)
|
91 | .to.equal("INSERT INTO `Animal` ( IDAnimal, Name, Age) VALUES ( :IDAnimal_0, :Name_1, :Age_2);");
|
92 | }
|
93 | );
|
94 | test
|
95 | (
|
96 | 'Bad Create Query',
|
97 | function()
|
98 | {
|
99 | var tmpQuery = libFoxHound.new(libFable).setDialect('MySQL');
|
100 |
|
101 | tmpQuery.buildCreateQuery();
|
102 | tmpQuery.addRecord({});
|
103 | tmpQuery.buildCreateQuery();
|
104 |
|
105 | libFable.log.trace('Create Query', tmpQuery.query);
|
106 | Expect(tmpQuery.query.body)
|
107 | .to.equal(false);
|
108 | }
|
109 | );
|
110 | test
|
111 | (
|
112 | 'Read Query',
|
113 | function()
|
114 | {
|
115 | var tmpQuery = libFoxHound.new(libFable).setDialect('MySQL').setScope('Animal');
|
116 | tmpQuery.addSort({Column:'Cost',Direction:'Descending'});
|
117 |
|
118 | tmpQuery.buildReadQuery();
|
119 |
|
120 | libFable.log.trace('Simple Select Query', tmpQuery.query);
|
121 | Expect(tmpQuery.query.body)
|
122 | .to.equal('SELECT * FROM `Animal` ORDER BY Cost DESC;');
|
123 | }
|
124 | );
|
125 | test
|
126 | (
|
127 | 'Complex Read Query',
|
128 | function()
|
129 | {
|
130 | var tmpQuery = libFoxHound.new(libFable)
|
131 | .setDialect('MySQL')
|
132 | .setScope('Animal')
|
133 | .setCap(10)
|
134 | .setBegin(0)
|
135 | .setDataElements(['Name', 'Age', 'Cost'])
|
136 | .setSort([{Column:'Age',Direction:'Ascending'}])
|
137 | .setFilter({Column:'Age',Operator:'=',Value:'15',Connector:'AND',Parameter:'Age'});
|
138 | tmpQuery.addSort('Cost');
|
139 |
|
140 | tmpQuery.buildReadQuery();
|
141 |
|
142 | libFable.log.trace('Select Query', tmpQuery.query);
|
143 | Expect(tmpQuery.query.body)
|
144 | .to.equal('SELECT Name, Age, Cost FROM `Animal` WHERE Age = :Age_w0 ORDER BY Age, Cost LIMIT 0, 10;');
|
145 | }
|
146 | );
|
147 | test
|
148 | (
|
149 | 'Complex Read Query 2',
|
150 | function()
|
151 | {
|
152 | var tmpQuery = libFoxHound.new(libFable)
|
153 | .setDialect('MySQL')
|
154 | .setScope('Animal')
|
155 | .setDataElements(['Name', 'Age', 'Cost'])
|
156 | .setCap(100)
|
157 | .addFilter('Age', '25')
|
158 | .addFilter('', '', '(')
|
159 | .addFilter('Color', 'Red')
|
160 | .addFilter('Color', 'Green', '=', 'OR')
|
161 | .addFilter('', '', ')')
|
162 | .addFilter('Description', '', 'IS NOT NULL')
|
163 | .addFilter('IDOffice', [10, 11, 15, 18, 22], 'IN');
|
164 | tmpQuery.setLogLevel(3).addSort('Age');
|
165 |
|
166 | tmpQuery.buildReadQuery();
|
167 |
|
168 | libFable.log.trace('Select Query', tmpQuery.query);
|
169 | Expect(tmpQuery.query.body)
|
170 | .to.equal('SELECT Name, Age, Cost FROM `Animal` WHERE Age = :Age_w0 AND ( Color = :Color_w2 OR Color = :Color_w3 ) AND Description IS NOT NULL AND IDOffice IN ( :IDOffice_w6 ) ORDER BY Age LIMIT 100;');
|
171 | }
|
172 | );
|
173 | test
|
174 | (
|
175 | 'Custom Read Query',
|
176 | function()
|
177 | {
|
178 | var tmpQuery = libFoxHound.new(libFable)
|
179 | .setDialect('MySQL')
|
180 | .setScope('Animal')
|
181 | .setCap(10)
|
182 | .setBegin(0)
|
183 | .setDataElements(['Name', 'Age', 'Cost'])
|
184 | .setSort([{Column:'Age',Direction:'Ascending'},{Column:'Cost',Direction:'Descending'}])
|
185 | .setFilter({Column:'Age',Operator:'=',Value:'15',Connector:'AND',Parameter:'Age'});
|
186 | tmpQuery.parameters.queryOverride = 'SELECT Name, Age * 5, Cost FROM <%= TableName %> <%= Where %> <%= Limit %>;';
|
187 |
|
188 | tmpQuery.buildReadQuery();
|
189 |
|
190 | libFable.log.trace('Custom Select Query', tmpQuery.query);
|
191 | Expect(tmpQuery.query.body)
|
192 | .to.equal('SELECT Name, Age * 5, Cost FROM `Animal` WHERE Age = :Age_w0 LIMIT 0, 10;');
|
193 | }
|
194 | );
|
195 | test
|
196 | (
|
197 | 'Bad Custom Read Query',
|
198 | function()
|
199 | {
|
200 | var tmpQuery = libFoxHound.new(libFable)
|
201 | .setDialect('MySQL')
|
202 | .setScope('Animal')
|
203 | .setCap(10)
|
204 | .setBegin(0)
|
205 | .setDataElements(['Name', 'Age', 'Cost'])
|
206 | .setSort([{Column:'Age',Direction:'Ascending'}])
|
207 | .setFilter({Column:'Age',Operator:'=',Value:'15',Connector:'AND',Parameter:'Age'});
|
208 | tmpQuery.parameters.queryOverride = 'SELECT Name, Age * 5, Cost FROM <%= TableName <%= Where %> <%= Limit ;';
|
209 |
|
210 | tmpQuery.buildReadQuery();
|
211 |
|
212 | libFable.log.trace('Custom Select Query', tmpQuery.query);
|
213 | Expect(tmpQuery.query.body)
|
214 | .to.equal(false);
|
215 | }
|
216 | );
|
217 | test
|
218 | (
|
219 | 'Bad Custom Count Query',
|
220 | function()
|
221 | {
|
222 | var tmpQuery = libFoxHound.new(libFable)
|
223 | .setDialect('MySQL')
|
224 | .setScope('Animal')
|
225 | .setFilter({Column:'Age',Operator:'=',Value:'15',Connector:'AND',Parameter:'Age'});
|
226 | tmpQuery.parameters.queryOverride = 'SELECT COUNT(*) AS RowCount FROM <%= TableName <%= TableName %> <%= Where;';
|
227 |
|
228 | tmpQuery.buildCountQuery();
|
229 |
|
230 | libFable.log.trace('Custom Count Query', tmpQuery.query);
|
231 | Expect(tmpQuery.query.body)
|
232 | .to.equal(false);
|
233 | }
|
234 | );
|
235 | test
|
236 | (
|
237 | 'Custom Count Query',
|
238 | function()
|
239 | {
|
240 | var tmpQuery = libFoxHound.new(libFable)
|
241 | .setDialect('MySQL')
|
242 | .setScope('Animal')
|
243 | .setFilter({Column:'Age',Operator:'=',Value:'15',Connector:'AND',Parameter:'Age'});
|
244 | tmpQuery.parameters.queryOverride = 'SELECT COUNT(*) AS RowCount FROM <%= TableName %> <%= Where %>;';
|
245 |
|
246 | tmpQuery.buildCountQuery();
|
247 |
|
248 | libFable.log.trace('Custom Count Query', tmpQuery.query);
|
249 | Expect(tmpQuery.query.body)
|
250 | .to.equal('SELECT COUNT(*) AS RowCount FROM `Animal` WHERE Age = :Age_w0;');
|
251 | }
|
252 | );
|
253 | test
|
254 | (
|
255 | 'Update Query',
|
256 | function()
|
257 | {
|
258 | var tmpQuery = libFoxHound.new(libFable).setDialect('MySQL')
|
259 | .setLogLevel(5)
|
260 | .setScope('Animal')
|
261 | .addFilter('IDAnimal', 9)
|
262 | .addRecord({Age:15,Color:'Brown'});
|
263 |
|
264 |
|
265 | tmpQuery.buildUpdateQuery();
|
266 |
|
267 | libFable.log.trace('Update Query', tmpQuery.query);
|
268 | Expect(tmpQuery.query.body)
|
269 | .to.equal('UPDATE `Animal` SET Age = :Age_0, Color = :Color_1 WHERE IDAnimal = :IDAnimal_w0;');
|
270 | }
|
271 | );
|
272 | test
|
273 | (
|
274 | 'Bad Update Query',
|
275 | function()
|
276 | {
|
277 | var tmpQuery = libFoxHound.new(libFable).setDialect('MySQL');
|
278 |
|
279 |
|
280 | tmpQuery.buildUpdateQuery();
|
281 | tmpQuery.addRecord({});
|
282 | tmpQuery.buildUpdateQuery();
|
283 |
|
284 | libFable.log.trace('Update Query', tmpQuery.query);
|
285 | Expect(tmpQuery.query.body)
|
286 | .to.equal(false);
|
287 | }
|
288 | );
|
289 | test
|
290 | (
|
291 | 'Delete Query',
|
292 | function()
|
293 | {
|
294 | var tmpQuery = libFoxHound.new(libFable).setDialect('MySQL')
|
295 | .setScope('Animal')
|
296 | .addFilter('IDAnimal', 10);
|
297 |
|
298 |
|
299 | tmpQuery.buildDeleteQuery();
|
300 |
|
301 | libFable.log.trace('Delete Query', tmpQuery.query);
|
302 | Expect(tmpQuery.query.body)
|
303 | .to.equal('DELETE FROM `Animal` WHERE IDAnimal = :IDAnimal_w0;');
|
304 | }
|
305 | );
|
306 | test
|
307 | (
|
308 | 'Count Query',
|
309 | function()
|
310 | {
|
311 | var tmpQuery = libFoxHound.new(libFable)
|
312 | .setDialect('MySQL')
|
313 | .setScope('Animal');
|
314 |
|
315 |
|
316 | tmpQuery.buildCountQuery();
|
317 |
|
318 | libFable.log.trace('Count Query', tmpQuery.query);
|
319 | Expect(tmpQuery.query.body)
|
320 | .to.equal('SELECT COUNT(*) AS RowCount FROM `Animal`;');
|
321 | }
|
322 | );
|
323 | }
|
324 | );
|
325 |
|
326 | suite
|
327 | (
|
328 | 'Complex Query Generation - Schemas',
|
329 | function()
|
330 | {
|
331 | test
|
332 | (
|
333 | 'Create Query',
|
334 | function()
|
335 | {
|
336 | var tmpQuery = libFoxHound.new(libFable)
|
337 | .setLogLevel(5)
|
338 | .setDialect('MySQL')
|
339 | .setScope('Animal')
|
340 | .addRecord(
|
341 | {
|
342 | IDAnimal:false,
|
343 | GUIDAnimal:false,
|
344 | CreateDate:false,
|
345 | CreatingIDUser:false,
|
346 | UpdateDate:false,
|
347 | UpdatingIDUser:false,
|
348 | Deleted:false,
|
349 | DeletingIDUser:false,
|
350 | DeleteDate:false,
|
351 | Name:'Froo Froo',
|
352 | Age:18
|
353 | });
|
354 | tmpQuery.query.schema = _AnimalSchema;
|
355 |
|
356 | tmpQuery.buildCreateQuery();
|
357 |
|
358 | libFable.log.trace('Create Query', tmpQuery.query);
|
359 | Expect(tmpQuery.query.body)
|
360 | .to.equal("INSERT INTO `Animal` ( IDAnimal, GUIDAnimal, CreateDate, CreatingIDUser, UpdateDate, UpdatingIDUser, Deleted, Name, Age) VALUES ( NULL, :GUIDAnimal_1, NOW(3), :CreatingIDUser_3, NOW(3), :UpdatingIDUser_5, :Deleted_6, :Name_7, :Age_8);");
|
361 | }
|
362 | );
|
363 | test
|
364 | (
|
365 | 'Create Query -- with GUID specified',
|
366 | function()
|
367 | {
|
368 | var tmpQuery = libFoxHound.new(libFable)
|
369 | .setLogLevel(5)
|
370 | .setDialect('MySQL')
|
371 | .setScope('Animal')
|
372 | .addRecord(
|
373 | {
|
374 | IDAnimal:false,
|
375 | GUIDAnimal:'0xabcdef',
|
376 | CreateDate:false,
|
377 | CreatingIDUser:false,
|
378 | UpdateDate:false,
|
379 | UpdatingIDUser:false,
|
380 | Deleted:false,
|
381 | DeletingIDUser:false,
|
382 | DeleteDate:false,
|
383 | Name:'Froo Froo',
|
384 | Age:18
|
385 | });
|
386 | tmpQuery.query.schema = _AnimalSchema;
|
387 |
|
388 | tmpQuery.buildCreateQuery();
|
389 |
|
390 | libFable.log.trace('Create Query', tmpQuery.query);
|
391 | Expect(tmpQuery.query.body)
|
392 | .to.equal("INSERT INTO `Animal` ( IDAnimal, GUIDAnimal, CreateDate, CreatingIDUser, UpdateDate, UpdatingIDUser, Deleted, Name, Age) VALUES ( NULL, :GUIDAnimal_1, NOW(3), :CreatingIDUser_3, NOW(3), :UpdatingIDUser_5, :Deleted_6, :Name_7, :Age_8);");
|
393 | }
|
394 | );
|
395 | test
|
396 | (
|
397 | 'Create Query - with AutoIdentity disabled',
|
398 | function()
|
399 | {
|
400 | var tmpQuery = libFoxHound.new(libFable)
|
401 | .setLogLevel(5)
|
402 | .setDialect('MySQL')
|
403 | .setScope('Animal')
|
404 | .setDisableAutoIdentity(true)
|
405 | .setDisableDeleteTracking(true)
|
406 | .setDisableAutoDateStamp(true)
|
407 | .setDisableAutoUserStamp(true)
|
408 | .addRecord(
|
409 | {
|
410 | IDAnimal:false,
|
411 | GUIDAnimal:false,
|
412 | CreateDate:false,
|
413 | CreatingIDUser:false,
|
414 | UpdateDate:false,
|
415 | UpdatingIDUser:false,
|
416 | Deleted:false,
|
417 | DeletingIDUser:false,
|
418 | DeleteDate:false,
|
419 | Name:'Froo Froo',
|
420 | Age:18
|
421 | });
|
422 | tmpQuery.query.schema = _AnimalSchema;
|
423 |
|
424 | tmpQuery.buildCreateQuery();
|
425 |
|
426 | libFable.log.trace('Create Query (AutoIdentity disabled)', tmpQuery.query);
|
427 | Expect(tmpQuery.query.body)
|
428 | .to.equal("INSERT INTO `Animal` ( IDAnimal, GUIDAnimal, CreateDate, CreatingIDUser, UpdateDate, UpdatingIDUser, Deleted, DeletingIDUser, DeleteDate, Name, Age) VALUES ( :IDAnimal_0, :GUIDAnimal_1, :CreateDate_2, :CreatingIDUser_3, :UpdateDate_4, :UpdatingIDUser_5, :Deleted_6, :DeletingIDUser_7, :DeleteDate_8, :Name_9, :Age_10);");
|
429 | }
|
430 | );
|
431 | test
|
432 | (
|
433 | 'Complex Read Query 2, verify checking Deleted bit with no filters',
|
434 | function()
|
435 | {
|
436 | var tmpQuery = libFoxHound.new(libFable)
|
437 | .setDialect('MySQL')
|
438 | .setScope('Animal')
|
439 | .setDataElements(['Name', 'Age', 'Cost'])
|
440 | .setCap(100);
|
441 |
|
442 |
|
443 | tmpQuery.query.schema = _AnimalSchema;
|
444 |
|
445 | tmpQuery.buildReadQuery();
|
446 |
|
447 | libFable.log.trace('Select Query', tmpQuery.query);
|
448 | Expect(tmpQuery.query.body)
|
449 | .to.equal('SELECT Name, Age, Cost FROM `Animal` WHERE `Animal`.Deleted = :Deleted_w0 LIMIT 100;');
|
450 | }
|
451 | );
|
452 | test
|
453 | (
|
454 | 'Complex Read Query 2, manually checking Deleted bit with Schema that has one',
|
455 | function()
|
456 | {
|
457 | var tmpQuery = libFoxHound.new(libFable)
|
458 | .setDialect('MySQL')
|
459 | .setScope('Animal')
|
460 | .setDataElements(['Name', 'Age', 'Cost'])
|
461 | .setCap(100)
|
462 | .addFilter('Age', '25')
|
463 | .addFilter('', '', '(')
|
464 | .addFilter('Color', 'Red')
|
465 | .addFilter('Color', 'Green', '=', 'OR')
|
466 | .addFilter('', '', ')')
|
467 | .addFilter('Description', '', 'IS NOT NULL')
|
468 | .addFilter('IDOffice', [10, 11, 15, 18, 22], 'IN')
|
469 | .addFilter('Deleted', '1');
|
470 |
|
471 |
|
472 | tmpQuery.query.schema = _AnimalSchema;
|
473 |
|
474 | tmpQuery.buildReadQuery();
|
475 |
|
476 | libFable.log.trace('Select Query', tmpQuery.query);
|
477 | Expect(tmpQuery.query.body)
|
478 | .to.equal('SELECT Name, Age, Cost FROM `Animal` WHERE Age = :Age_w0 AND ( Color = :Color_w2 OR Color = :Color_w3 ) AND Description IS NOT NULL AND IDOffice IN ( :IDOffice_w6 ) AND Deleted = :Deleted_w7 LIMIT 100;');
|
479 | }
|
480 | );
|
481 | test
|
482 | (
|
483 | 'Complex Read Query 2, delete tracking disabled',
|
484 | function()
|
485 | {
|
486 | var tmpQuery = libFoxHound.new(libFable)
|
487 | .setDialect('MySQL')
|
488 | .setScope('Animal')
|
489 | .setDisableDeleteTracking(true)
|
490 | .setDataElements(['Name', 'Age', 'Cost'])
|
491 | .setCap(100);
|
492 |
|
493 |
|
494 | tmpQuery.query.schema = _AnimalSchema;
|
495 |
|
496 | tmpQuery.buildReadQuery();
|
497 |
|
498 | libFable.log.trace('Select Query', tmpQuery.query);
|
499 | Expect(tmpQuery.query.body)
|
500 | .to.equal('SELECT Name, Age, Cost FROM `Animal` LIMIT 100;');
|
501 | }
|
502 | );
|
503 | test
|
504 | (
|
505 | 'Delete Query with Filters',
|
506 | function()
|
507 | {
|
508 | var tmpQuery = libFoxHound.new(libFable).setDialect('MySQL')
|
509 | .setScope('Animal')
|
510 | .addFilter('IDAnimal', 10);
|
511 |
|
512 |
|
513 |
|
514 | tmpQuery.query.schema = _AnimalSchema;
|
515 |
|
516 |
|
517 | tmpQuery.buildDeleteQuery();
|
518 |
|
519 | libFable.log.trace('Delete Query', tmpQuery.query);
|
520 | Expect(tmpQuery.query.body)
|
521 | .to.equal('UPDATE `Animal` SET UpdateDate = NOW(3), Deleted = 1, DeletingIDUser = :DeletingIDUser_2, DeleteDate = NOW(3) WHERE IDAnimal = :IDAnimal_w0 AND `Animal`.Deleted = :Deleted_w1;');
|
522 | }
|
523 | );
|
524 | test
|
525 | (
|
526 | 'Update Query -- without Deleted',
|
527 | function()
|
528 | {
|
529 | var tmpQuery = libFoxHound.new(libFable).setDialect('MySQL')
|
530 | .setLogLevel(5)
|
531 | .setScope('Animal')
|
532 | .addFilter('IDAnimal', 9)
|
533 | .addRecord({
|
534 | IDAnimal:82,
|
535 | GUIDAnimal:'1111-2222-3333-4444-5555-6666-7777',
|
536 | CreateDate:false,
|
537 | CreatingIDUser:false,
|
538 | UpdateDate:false,
|
539 | UpdatingIDUser:false,
|
540 | Name:'Froo Froo',
|
541 | Age:18
|
542 | });
|
543 | tmpQuery.query.schema = _AnimalSchemaWithoutDeleted;
|
544 |
|
545 | tmpQuery.buildUpdateQuery();
|
546 |
|
547 | libFable.log.trace('Update Query', tmpQuery.query);
|
548 | Expect(tmpQuery.query.body)
|
549 | .to.equal('UPDATE `Animal` SET GUIDAnimal = :GUIDAnimal_0, UpdateDate = NOW(3), UpdatingIDUser = :UpdatingIDUser_2, Name = :Name_3, Age = :Age_4 WHERE IDAnimal = :IDAnimal_w0;');
|
550 | }
|
551 | );
|
552 | test
|
553 | (
|
554 | 'Update Query -- without Deleted, UpdateDate and UpdatingIDUser',
|
555 | function()
|
556 | {
|
557 | var tmpQuery = libFoxHound.new(libFable).setDialect('MySQL')
|
558 | .setLogLevel(5)
|
559 | .setScope('Animal')
|
560 | .addFilter('IDAnimal', 9)
|
561 | .setDisableAutoUserStamp(true)
|
562 | .setDisableAutoDateStamp(true)
|
563 | .addRecord({
|
564 | IDAnimal:82,
|
565 | GUIDAnimal:'1111-2222-3333-4444-5555-6666-7777',
|
566 | CreateDate:false,
|
567 | CreatingIDUser:false,
|
568 | UpdateDate:false,
|
569 | UpdatingIDUser:false,
|
570 | Name:'Froo Froo',
|
571 | Age:18
|
572 | });
|
573 | tmpQuery.query.schema = _AnimalSchemaWithoutDeleted;
|
574 |
|
575 | tmpQuery.buildUpdateQuery();
|
576 |
|
577 | libFable.log.trace('Update Query', tmpQuery.query);
|
578 | Expect(tmpQuery.query.body)
|
579 | .to.equal('UPDATE `Animal` SET GUIDAnimal = :GUIDAnimal_0, Name = :Name_1, Age = :Age_2 WHERE IDAnimal = :IDAnimal_w0;');
|
580 | }
|
581 | );
|
582 | test
|
583 | (
|
584 | 'Delete Query -- without Deleted',
|
585 | function()
|
586 | {
|
587 | var tmpQuery = libFoxHound.new(libFable).setDialect('MySQL')
|
588 | .setLogLevel(5)
|
589 | .setScope('Animal')
|
590 | .addFilter('IDAnimal', 9)
|
591 | .addRecord({
|
592 | IDAnimal:82,
|
593 | GUIDAnimal:'1111-2222-3333-4444-5555-6666-7777'
|
594 | });
|
595 | tmpQuery.query.schema = _AnimalSchemaWithoutDeleted;
|
596 |
|
597 | tmpQuery.buildDeleteQuery();
|
598 |
|
599 | libFable.log.trace('Delete Query', tmpQuery.query);
|
600 | Expect(tmpQuery.query.body)
|
601 | .to.equal('DELETE FROM `Animal` WHERE IDAnimal = :IDAnimal_w0;');
|
602 | }
|
603 | );
|
604 | test
|
605 | (
|
606 | 'Update Query',
|
607 | function()
|
608 | {
|
609 | var tmpQuery = libFoxHound.new(libFable).setDialect('MySQL')
|
610 | .setLogLevel(5)
|
611 | .setScope('Animal')
|
612 | .addFilter('IDAnimal', 9)
|
613 | .addFilter('Deleted', 0)
|
614 | .addRecord({
|
615 | IDAnimal:82,
|
616 | GUIDAnimal:'1111-2222-3333-4444-5555-6666-7777',
|
617 | CreateDate:false,
|
618 | CreatingIDUser:false,
|
619 | UpdateDate:false,
|
620 | UpdatingIDUser:false,
|
621 | Deleted:false,
|
622 | DeletingIDUser:false,
|
623 | DeleteDate:false,
|
624 | Name:'Froo Froo',
|
625 | Age:18
|
626 | });
|
627 | tmpQuery.query.schema = _AnimalSchema;
|
628 |
|
629 | tmpQuery.buildUpdateQuery();
|
630 |
|
631 | libFable.log.trace('Update Query', tmpQuery.query);
|
632 | Expect(tmpQuery.query.body)
|
633 | .to.equal('UPDATE `Animal` SET GUIDAnimal = :GUIDAnimal_0, UpdateDate = NOW(3), UpdatingIDUser = :UpdatingIDUser_2, Deleted = :Deleted_3, Name = :Name_4, Age = :Age_5 WHERE IDAnimal = :IDAnimal_w0 AND Deleted = :Deleted_w1;');
|
634 | }
|
635 | );
|
636 | test
|
637 | (
|
638 | 'Delete Query',
|
639 | function()
|
640 | {
|
641 | var tmpQuery = libFoxHound.new(libFable).setDialect('MySQL')
|
642 | .setLogLevel(5)
|
643 | .setScope('Animal')
|
644 | .addFilter('IDAnimal', 9)
|
645 | .addRecord({
|
646 | IDAnimal:82,
|
647 | GUIDAnimal:'1111-2222-3333-4444-5555-6666-7777'
|
648 | });
|
649 | tmpQuery.query.schema = _AnimalSchema;
|
650 |
|
651 | tmpQuery.buildDeleteQuery();
|
652 |
|
653 | libFable.log.trace('Delete Query', tmpQuery.query);
|
654 | Expect(tmpQuery.query.body)
|
655 | .to.equal('UPDATE `Animal` SET UpdateDate = NOW(3), Deleted = 1, DeletingIDUser = :DeletingIDUser_2, DeleteDate = NOW(3) WHERE IDAnimal = :IDAnimal_w0 AND `Animal`.Deleted = :Deleted_w1;');
|
656 | }
|
657 | );
|
658 | test
|
659 | (
|
660 | 'Delete Query with Delete Tracking Disabled',
|
661 | function()
|
662 | {
|
663 | var tmpQuery = libFoxHound.new(libFable).setDialect('MySQL')
|
664 | .setLogLevel(5)
|
665 | .setScope('Animal')
|
666 | .setDisableDeleteTracking(true)
|
667 | .addFilter('IDAnimal', 9)
|
668 | .addRecord({
|
669 | IDAnimal:82,
|
670 | GUIDAnimal:'1111-2222-3333-4444-5555-6666-7777'
|
671 | });
|
672 | tmpQuery.query.schema = _AnimalSchema;
|
673 |
|
674 | tmpQuery.buildDeleteQuery();
|
675 |
|
676 | libFable.log.trace('Delete Query', tmpQuery.query);
|
677 | Expect(tmpQuery.query.body)
|
678 | .to.equal('DELETE FROM `Animal` WHERE IDAnimal = :IDAnimal_w0;');
|
679 | }
|
680 | );
|
681 | }
|
682 | );
|
683 |
|
684 | suite
|
685 | (
|
686 | 'Join Query Generation',
|
687 | function()
|
688 | {
|
689 | test
|
690 | (
|
691 | 'Join Read Query',
|
692 | function()
|
693 | {
|
694 | var tmpQuery = libFoxHound.new(libFable)
|
695 | .setDialect('MySQL')
|
696 | .setScope('Animal')
|
697 | .setCap(10)
|
698 | .setBegin(0)
|
699 | .setDataElements(['Name', 'Age', 'Cost'])
|
700 | .setSort([{Column:'Age',Direction:'Ascending'}])
|
701 | .setFilter({Column:'Age',Operator:'=',Value:'15',Connector:'AND',Parameter:'Age'})
|
702 | .setJoin({Table: 'Test', From:'Test.IDAnimal', To: 'Animal.IDAnimal'});
|
703 |
|
704 |
|
705 | tmpQuery.buildReadQuery();
|
706 |
|
707 | libFable.log.trace('Select Query', tmpQuery.query);
|
708 | Expect(tmpQuery.query.body)
|
709 | .to.equal('SELECT Name, Age, Cost FROM `Animal` INNER JOIN Test ON Test.IDAnimal = Animal.IDAnimal WHERE Age = :Age_w0 ORDER BY Age LIMIT 0, 10;');
|
710 | }
|
711 | );
|
712 | test
|
713 | (
|
714 | 'Bad Join Read Query',
|
715 | function()
|
716 | {
|
717 | var tmpQuery = libFoxHound.new(libFable)
|
718 | .setDialect('MySQL')
|
719 | .setScope('Animal')
|
720 | .setJoin({Table: 'Test', From:'Bad.IDAnimal', To: 'Animal.IDAnimal'});
|
721 |
|
722 |
|
723 | tmpQuery.buildReadQuery();
|
724 |
|
725 | libFable.log.trace('Select Query', tmpQuery.query);
|
726 | Expect(tmpQuery.query.body)
|
727 | .to.equal('SELECT * FROM `Animal`;');
|
728 | }
|
729 | );
|
730 | }
|
731 | );
|
732 | }
|
733 | ); |
\ | No newline at end of file |