meadow 2.0.23 → 2.0.27

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (62) hide show
  1. package/README.md +110 -141
  2. package/docs/README.md +34 -230
  3. package/docs/_cover.md +14 -0
  4. package/docs/_sidebar.md +44 -12
  5. package/docs/_topbar.md +5 -0
  6. package/docs/api/doCount.md +109 -0
  7. package/docs/api/doCreate.md +132 -0
  8. package/docs/api/doDelete.md +101 -0
  9. package/docs/api/doRead.md +122 -0
  10. package/docs/api/doReads.md +136 -0
  11. package/docs/api/doUndelete.md +98 -0
  12. package/docs/api/doUpdate.md +129 -0
  13. package/docs/api/getRoleName.md +84 -0
  14. package/docs/api/loadFromPackage.md +153 -0
  15. package/docs/api/marshalRecordFromSourceToObject.md +92 -0
  16. package/docs/api/query.md +133 -0
  17. package/docs/api/rawQueries.md +197 -0
  18. package/docs/api/reference.md +117 -0
  19. package/docs/api/setAuthorizer.md +103 -0
  20. package/docs/api/setDefault.md +90 -0
  21. package/docs/api/setDefaultIdentifier.md +84 -0
  22. package/docs/api/setDomain.md +56 -0
  23. package/docs/api/setIDUser.md +91 -0
  24. package/docs/api/setJsonSchema.md +92 -0
  25. package/docs/api/setProvider.md +87 -0
  26. package/docs/api/setSchema.md +107 -0
  27. package/docs/api/setScope.md +68 -0
  28. package/docs/api/validateObject.md +119 -0
  29. package/docs/architecture.md +316 -0
  30. package/docs/audit-tracking.md +226 -0
  31. package/docs/configuration.md +317 -0
  32. package/docs/providers/meadow-endpoints.md +306 -0
  33. package/docs/providers/mongodb.md +319 -0
  34. package/docs/providers/postgresql.md +312 -0
  35. package/docs/providers/rocksdb.md +297 -0
  36. package/docs/query-dsl.md +269 -0
  37. package/docs/quick-start.md +384 -0
  38. package/docs/raw-queries.md +193 -0
  39. package/docs/retold-catalog.json +61 -1
  40. package/docs/retold-keyword-index.json +15860 -4839
  41. package/docs/soft-deletes.md +224 -0
  42. package/package.json +44 -13
  43. package/scripts/bookstore-seed-postgresql.sql +135 -0
  44. package/scripts/dgraph-test-db.sh +144 -0
  45. package/scripts/meadow-test-cleanup.sh +5 -1
  46. package/scripts/mongodb-test-db.sh +98 -0
  47. package/scripts/postgresql-test-db.sh +124 -0
  48. package/scripts/solr-test-db.sh +135 -0
  49. package/source/Meadow.js +5 -0
  50. package/source/providers/Meadow-Provider-DGraph.js +679 -0
  51. package/source/providers/Meadow-Provider-MeadowEndpoints.js +1 -1
  52. package/source/providers/Meadow-Provider-MongoDB.js +527 -0
  53. package/source/providers/Meadow-Provider-PostgreSQL.js +361 -0
  54. package/source/providers/Meadow-Provider-RocksDB.js +1300 -0
  55. package/source/providers/Meadow-Provider-Solr.js +726 -0
  56. package/test/Meadow-Provider-DGraph_tests.js +741 -0
  57. package/test/Meadow-Provider-MongoDB_tests.js +661 -0
  58. package/test/Meadow-Provider-PostgreSQL_tests.js +787 -0
  59. package/test/Meadow-Provider-RocksDB_tests.js +887 -0
  60. package/test/Meadow-Provider-SQLiteBrowser-Headless_tests.js +657 -0
  61. package/test/Meadow-Provider-SQLiteBrowser_tests.js +895 -0
  62. package/test/Meadow-Provider-Solr_tests.js +679 -0
@@ -0,0 +1,787 @@
1
+ /**
2
+ * Unit tests for the Meadow "PostgreSQL" Provider
3
+ *
4
+ * These tests expect a PostgreSQL database.....
5
+ *
6
+ * @license MIT
7
+ *
8
+ * @author Steven Velozo <steven@velozo.com>
9
+ */
10
+
11
+ var Chai = require("chai");
12
+ var Expect = Chai.expect;
13
+
14
+ const libMeadowConnectionPostgreSQL = require('meadow-connection-postgresql');
15
+
16
+ var tmpFableSettings = (
17
+ {
18
+ "Product": "MeadowPostgreSQLTestBookstore",
19
+ "ProductVersion": "1.0.0",
20
+
21
+ "UUID":
22
+ {
23
+ "DataCenter": 0,
24
+ "Worker": 0
25
+ },
26
+ "LogStreams":
27
+ [
28
+ {
29
+ "streamtype": "console"
30
+ }
31
+ ],
32
+
33
+ "PostgreSQL":
34
+ {
35
+ "Server": "127.0.0.1",
36
+ "Port": 35432,
37
+ "User": "postgres",
38
+ "Password": "testpassword",
39
+ "Database": "bookstore",
40
+ "ConnectionPoolLimit": 20
41
+ }
42
+ });
43
+
44
+ var libFable = new (require('fable'))(tmpFableSettings);
45
+
46
+ libFable.serviceManager.addServiceType('MeadowPostgreSQLProvider', libMeadowConnectionPostgreSQL);
47
+ libFable.serviceManager.instantiateServiceProvider('MeadowPostgreSQLProvider');
48
+
49
+ var _AnimalJsonSchema = (
50
+ {
51
+ title: "Animal",
52
+ description: "A creature that lives in a meadow.",
53
+ type: "object",
54
+ properties: {
55
+ IDAnimal: {
56
+ description: "The unique identifier for an animal",
57
+ type: "integer"
58
+ },
59
+ Name: {
60
+ description: "The animal's name",
61
+ type: "string"
62
+ },
63
+ Type: {
64
+ description: "The type of the animal",
65
+ type: "string"
66
+ }
67
+ },
68
+ required: ["IDAnimal", "Name", "CreatingIDUser"]
69
+ });
70
+ var _AnimalSchema = (
71
+ [
72
+ { Column: "IDAnimal", Type: "AutoIdentity" },
73
+ { Column: "GUIDAnimal", Type: "AutoGUID" },
74
+ { Column: "CreateDate", Type: "CreateDate" },
75
+ { Column: "CreatingIDUser", Type: "CreateIDUser" },
76
+ { Column: "UpdateDate", Type: "UpdateDate" },
77
+ { Column: "UpdatingIDUser", Type: "UpdateIDUser" },
78
+ { Column: "Deleted", Type: "Deleted" },
79
+ { Column: "DeletingIDUser", Type: "DeleteIDUser" },
80
+ { Column: "DeleteDate", Type: "DeleteDate" },
81
+ { Column: "Name", Type: "String" },
82
+ { Column: "Type", Type: "String" }
83
+ ]);
84
+ var _AnimalDefault = (
85
+ {
86
+ IDAnimal: null,
87
+ GUIDAnimal: '',
88
+
89
+ CreateDate: false,
90
+ CreatingIDUser: 0,
91
+ UpdateDate: false,
92
+ UpdatingIDUser: 0,
93
+ Deleted: 0,
94
+ DeleteDate: false,
95
+ DeletingIDUser: 0,
96
+
97
+ Name: 'Unknown',
98
+ Type: 'Unclassified'
99
+ });
100
+
101
+ suite
102
+ (
103
+ 'Meadow-Provider-PostgreSQL',
104
+ function ()
105
+ {
106
+ var _SpooledUp = false;
107
+
108
+ var getAnimalInsert = function (pName, pType)
109
+ {
110
+ return 'INSERT INTO "FableTest" ("GUIDAnimal", "CreateDate", "CreatingIDUser", "UpdateDate", "UpdatingIDUser", "Deleted", "DeleteDate", "DeletingIDUser", "Name", "Type") VALUES (\'00000000-0000-0000-0000-000000000000\', NOW(), 1, NOW(), 1, 0, NULL, 0, \'' + pName + '\', \'' + pType + '\'); ';
111
+ };
112
+
113
+ var newMeadow = function ()
114
+ {
115
+ return require('../source/Meadow.js')
116
+ .new(libFable, 'FableTest')
117
+ .setProvider('PostgreSQL')
118
+ .setSchema(_AnimalSchema)
119
+ .setJsonSchema(_AnimalJsonSchema)
120
+ .setDefaultIdentifier('IDAnimal')
121
+ .setDefault(_AnimalDefault)
122
+ };
123
+
124
+ suiteSetup
125
+ (
126
+ function (fDone)
127
+ {
128
+ // Only do this for the first test.
129
+ if (!_SpooledUp)
130
+ {
131
+ // Tear down previous test data
132
+ libFable.Utility.waterfall(
133
+ [
134
+ function (fStageComplete)
135
+ {
136
+ libFable.MeadowPostgreSQLProvider.connectAsync(
137
+ (pError, pConnectionPool) =>
138
+ {
139
+ if (pError)
140
+ {
141
+ libFable.log.error(`Error connecting to PostgreSQL Database: ${pError}`);
142
+ fStageComplete(pError);
143
+ }
144
+
145
+ libFable.log.info('Connection opened!');
146
+ return fStageComplete();
147
+ }
148
+ );
149
+ },
150
+ function (fStageComplete)
151
+ {
152
+ libFable.MeadowPostgreSQLProvider.pool.query('DROP TABLE IF EXISTS "FableTest"').then(() => { return fStageComplete(); }).catch(fStageComplete);
153
+ },
154
+ function (fStageComplete)
155
+ {
156
+ libFable.MeadowPostgreSQLProvider.pool.query('CREATE TABLE IF NOT EXISTS "FableTest" ("IDAnimal" SERIAL PRIMARY KEY, "GUIDAnimal" VARCHAR(36) NOT NULL DEFAULT \'00000000-0000-0000-0000-000000000000\', "CreateDate" TIMESTAMP, "CreatingIDUser" INT NOT NULL DEFAULT 0, "UpdateDate" TIMESTAMP, "UpdatingIDUser" INT NOT NULL DEFAULT 0, "Deleted" SMALLINT NOT NULL DEFAULT 0, "DeleteDate" TIMESTAMP, "DeletingIDUser" INT NOT NULL DEFAULT 0, "Name" VARCHAR(128) NOT NULL DEFAULT \'\', "Type" VARCHAR(128) NOT NULL DEFAULT \'\');').then(() => { return fStageComplete(); }).catch(fStageComplete);
157
+ },
158
+ function (fStageComplete)
159
+ {
160
+ libFable.MeadowPostgreSQLProvider.pool.query(getAnimalInsert('Foo Foo', 'Bunny')).then(() => { return fStageComplete(); }).catch(fStageComplete);
161
+ },
162
+ function (fStageComplete)
163
+ {
164
+ libFable.MeadowPostgreSQLProvider.pool.query(getAnimalInsert('Red Riding Hood', 'Girl')).then(() => { return fStageComplete(); }).catch(fStageComplete);
165
+ },
166
+ function (fStageComplete)
167
+ {
168
+ libFable.MeadowPostgreSQLProvider.pool.query(getAnimalInsert('Red', 'Dog')).then(() => { return fStageComplete(); }).catch(fStageComplete);
169
+ },
170
+ function (fStageComplete)
171
+ {
172
+ libFable.MeadowPostgreSQLProvider.pool.query(getAnimalInsert('Spot', 'Dog')).then(() => { return fStageComplete(); }).catch(fStageComplete);
173
+ },
174
+ function (fStageComplete)
175
+ {
176
+ libFable.MeadowPostgreSQLProvider.pool.query(getAnimalInsert('Gertrude', 'Frog')).then(() => { return fStageComplete(); }).catch(fStageComplete);
177
+ }
178
+ ],
179
+ function (pError, pResult)
180
+ {
181
+ // Now continue the tests.
182
+ _SpooledUp = true;
183
+ fDone();
184
+ }
185
+ );
186
+ }
187
+ else
188
+ {
189
+ fDone();
190
+ }
191
+ }
192
+ );
193
+
194
+ suiteTeardown((fDone) =>
195
+ {
196
+ if (libFable.MeadowPostgreSQLProvider && libFable.MeadowPostgreSQLProvider.pool)
197
+ {
198
+ libFable.MeadowPostgreSQLProvider.pool.end().then(() => fDone()).catch(fDone);
199
+ }
200
+ else
201
+ {
202
+ fDone();
203
+ }
204
+ });
205
+
206
+ suite
207
+ (
208
+ 'Object Sanity',
209
+ function ()
210
+ {
211
+ test
212
+ (
213
+ 'The PostgreSQL class should initialize itself into a happy little object.',
214
+ function ()
215
+ {
216
+ var testMeadow = require('../source/Meadow.js').new(libFable).setProvider('PostgreSQL');
217
+ Expect(testMeadow).to.be.an('object', 'Meadow should initialize as an object directly from the require statement.');
218
+ }
219
+ );
220
+ }
221
+ );
222
+ suite
223
+ (
224
+ 'Query Processing',
225
+ function ()
226
+ {
227
+ test
228
+ (
229
+ 'Create a record in the database',
230
+ function (fDone)
231
+ {
232
+ var testMeadow = newMeadow().setIDUser(90210);
233
+
234
+ var tmpQuery = testMeadow.query.clone().setLogLevel(5)
235
+ .addRecord({ Name: 'Blastoise', Type: 'Pokemon' });
236
+
237
+ testMeadow.doCreate(tmpQuery,
238
+ function (pError, pQuery, pQueryRead, pRecord)
239
+ {
240
+ // We should have a record ....
241
+ Expect(pRecord.Name)
242
+ .to.equal('Blastoise');
243
+ Expect(pRecord.CreatingIDUser)
244
+ .to.equal(90210);
245
+ fDone();
246
+ }
247
+ )
248
+ }
249
+ );
250
+ test
251
+ (
252
+ 'Read a record from the database',
253
+ function (fDone)
254
+ {
255
+ var testMeadow = newMeadow();
256
+
257
+ var tmpQuery = testMeadow.query
258
+ .addFilter('IDAnimal', 1);
259
+
260
+ testMeadow.doRead(tmpQuery,
261
+ function (pError, pQuery, pRecord)
262
+ {
263
+ // We should have a record ....
264
+ Expect(pRecord.IDAnimal)
265
+ .to.equal(1);
266
+ Expect(pRecord.Name)
267
+ .to.equal('Foo Foo');
268
+ fDone();
269
+ }
270
+ )
271
+ }
272
+ );
273
+ test
274
+ (
275
+ 'Read all records from the database',
276
+ function (fDone)
277
+ {
278
+ var testMeadow = newMeadow();
279
+
280
+ testMeadow.doReads(testMeadow.query.addSort({Column: 'IDAnimal'}),
281
+ function (pError, pQuery, pRecords)
282
+ {
283
+ // We should have a record ....
284
+ Expect(pRecords[0].IDAnimal)
285
+ .to.equal(1);
286
+ Expect(pRecords[0].Name)
287
+ .to.equal('Foo Foo');
288
+ Expect(pRecords[1].IDAnimal)
289
+ .to.equal(2);
290
+ Expect(pRecords[1].Name)
291
+ .to.equal('Red Riding Hood');
292
+ Expect(pRecords[1].Type)
293
+ .to.equal('Girl');
294
+ fDone();
295
+ }
296
+ )
297
+ }
298
+ );
299
+ test
300
+ (
301
+ 'Update a record in the database',
302
+ function (fDone)
303
+ {
304
+ var testMeadow = newMeadow();
305
+
306
+ var tmpQuery = testMeadow.query
307
+ .addRecord({ IDAnimal: 2, Type: 'Human' });
308
+
309
+ testMeadow.doUpdate(tmpQuery,
310
+ function (pError, pQuery, pQueryRead, pRecord)
311
+ {
312
+ // We should have a record ....
313
+ Expect(pRecord.Type)
314
+ .to.equal('Human');
315
+ fDone();
316
+ }
317
+ )
318
+ }
319
+ );
320
+ test
321
+ (
322
+ 'Delete a record in the database',
323
+ function (fDone)
324
+ {
325
+ var testMeadow = newMeadow();
326
+
327
+ var tmpQuery = testMeadow.query.addFilter('IDAnimal', 3);
328
+
329
+ testMeadow.doDelete(tmpQuery,
330
+ function (pError, pQuery, pRecord)
331
+ {
332
+ // It returns the number of rows deleted
333
+ Expect(pRecord)
334
+ .to.equal(1);
335
+ fDone();
336
+ }
337
+ )
338
+ }
339
+ );
340
+ test
341
+ (
342
+ 'Undelete a record in the database',
343
+ function (fDone)
344
+ {
345
+ var testMeadow = newMeadow();
346
+
347
+ var tmpDeleteQuery = testMeadow.query.addFilter('IDAnimal', 5);
348
+
349
+ // Make sure the record is deleted!
350
+ testMeadow.doDelete(tmpDeleteQuery,
351
+ function (pDeleteError, pDeleteQuery, pDeleteRecord)
352
+ {
353
+ var tmpQuery = testMeadow.query.addFilter('IDAnimal', 5);
354
+ testMeadow.doUndelete(tmpQuery,
355
+ function (pError, pQuery, pRecord)
356
+ {
357
+ // It returns the number of rows undeleted
358
+ Expect(pRecord)
359
+ .to.equal(1);
360
+ fDone();
361
+ });
362
+ });
363
+ }
364
+ );
365
+ test
366
+ (
367
+ 'Count all records from the database',
368
+ function (fDone)
369
+ {
370
+ var testMeadow = newMeadow();
371
+
372
+ Expect(testMeadow.query.parameters.result.executed)
373
+ .to.equal(false);
374
+ testMeadow.doCount(testMeadow.query,
375
+ function (pError, pQuery, pRecord)
376
+ {
377
+ // There should be 5 records
378
+ Expect(pRecord)
379
+ .to.equal(5);
380
+ Expect(pQuery.parameters.result.executed)
381
+ .to.equal(true);
382
+ fDone();
383
+ }
384
+ )
385
+ }
386
+ );
387
+ test
388
+ (
389
+ 'Perform operations with a schema-based instantiation',
390
+ function (fDone)
391
+ {
392
+ var testMeadow = require('../source/Meadow.js').new(libFable)
393
+ .loadFromPackage(__dirname + '/Animal.json').setProvider('PostgreSQL');
394
+
395
+ // Make sure the authentication stuff got loaded
396
+ Expect(testMeadow.schemaFull.authorizer.User)
397
+ .to.be.an('object');
398
+ Expect(testMeadow.schemaFull.authorizer.User.Create)
399
+ .to.equal('Allow');
400
+
401
+ var tmpQuery = testMeadow.query
402
+ .addRecord({ Name: 'Grommet', Type: 'Dog' });
403
+
404
+ testMeadow.doCreate(tmpQuery,
405
+ function (pError, pQuery, pQueryRead, pRecord)
406
+ {
407
+ // We should have a record ....
408
+ Expect(pRecord.Name)
409
+ .to.equal('Grommet');
410
+ fDone();
411
+ }
412
+ )
413
+ }
414
+ );
415
+ }
416
+ );
417
+ suite
418
+ (
419
+ 'Logged Query Processing',
420
+ function ()
421
+ {
422
+ test
423
+ (
424
+ 'Create a record in the database',
425
+ function (fDone)
426
+ {
427
+ var testMeadow = newMeadow();
428
+
429
+ var tmpQuery = testMeadow.query
430
+ .setLogLevel(5)
431
+ .addRecord({ Name: 'MewTwo', Type: 'Pokemon' });
432
+
433
+ testMeadow.doCreate(tmpQuery,
434
+ function (pError, pQuery, pQueryRead, pRecord)
435
+ {
436
+ // We should have a record ....
437
+ Expect(pRecord.Name)
438
+ .to.equal('MewTwo');
439
+ fDone();
440
+ }
441
+ )
442
+ }
443
+ );
444
+ test
445
+ (
446
+ 'Create a record in the database with a predefined GUID',
447
+ function (fDone)
448
+ {
449
+ var testMeadow = newMeadow();
450
+
451
+ var tmpQuery = testMeadow.query
452
+ .setLogLevel(5)
453
+ .addRecord({ Name: 'MewThree', GUIDAnimal: '0x12345', Type: 'Pokemon' });
454
+
455
+ testMeadow.doCreate(tmpQuery,
456
+ function (pError, pQuery, pQueryRead, pRecord)
457
+ {
458
+ // We should have a record ....
459
+ Expect(pRecord.Name)
460
+ .to.equal('MewThree');
461
+ fDone();
462
+ }
463
+ )
464
+ }
465
+ );
466
+ test
467
+ (
468
+ 'Create a record in the database with a previously predefined GUID -- expect failure',
469
+ function (fDone)
470
+ {
471
+ var testMeadow = newMeadow();
472
+
473
+ var tmpQuery = testMeadow.query
474
+ .setLogLevel(5)
475
+ .addRecord({ Name: 'MewThree', GUIDAnimal: '0x12345', Type: 'Pokemon' });
476
+
477
+ testMeadow.doCreate(tmpQuery,
478
+ function (pError, pQuery, pQueryRead, pRecord)
479
+ {
480
+ Expect(pError)
481
+ .to.equal("Record with GUID 0x12345 already exists!");
482
+ fDone();
483
+ }
484
+ )
485
+ }
486
+ );
487
+ test
488
+ (
489
+ 'Read a record from the database',
490
+ function (fDone)
491
+ {
492
+ var testMeadow = newMeadow();
493
+
494
+ var tmpQuery = testMeadow.query
495
+ .setLogLevel(5)
496
+ .addFilter('IDAnimal', 1);
497
+
498
+ testMeadow.doRead(tmpQuery,
499
+ function (pError, pQuery, pRecord)
500
+ {
501
+ // We should have a record ....
502
+ Expect(pRecord.IDAnimal)
503
+ .to.equal(1);
504
+ Expect(pRecord.Name)
505
+ .to.equal('Foo Foo');
506
+ fDone();
507
+ }
508
+ )
509
+ }
510
+ );
511
+ test
512
+ (
513
+ 'Read all records from the database',
514
+ function (fDone)
515
+ {
516
+ var testMeadow = newMeadow();
517
+
518
+ testMeadow.doReads(testMeadow.query.setLogLevel(5).addSort({Column: 'IDAnimal'}),
519
+ function (pError, pQuery, pRecords)
520
+ {
521
+ // We should have a record ....
522
+ Expect(pRecords[0].IDAnimal)
523
+ .to.equal(1);
524
+ Expect(pRecords[0].Name)
525
+ .to.equal('Foo Foo');
526
+ Expect(pRecords[1].IDAnimal)
527
+ .to.equal(2);
528
+ Expect(pRecords[1].Name)
529
+ .to.equal('Red Riding Hood');
530
+ Expect(pRecords[1].Type)
531
+ .to.equal('Human');
532
+ fDone();
533
+ }
534
+ )
535
+ }
536
+ );
537
+ test
538
+ (
539
+ 'Update a record in the database',
540
+ function (fDone)
541
+ {
542
+ var testMeadow = newMeadow();
543
+
544
+ var tmpQuery = testMeadow.query
545
+ .setLogLevel(5)
546
+ .addRecord({ IDAnimal: 2, Type: 'HumanGirl' });
547
+
548
+ testMeadow.doUpdate(tmpQuery,
549
+ function (pError, pQuery, pQueryRead, pRecord)
550
+ {
551
+ // We should have a record ....
552
+ Expect(pRecord.Type)
553
+ .to.equal('HumanGirl');
554
+ fDone();
555
+ }
556
+ )
557
+ }
558
+ );
559
+ test
560
+ (
561
+ 'Delete a record in the database',
562
+ function (fDone)
563
+ {
564
+ var testMeadow = newMeadow();
565
+
566
+ var tmpQuery = testMeadow.query
567
+ .setLogLevel(5)
568
+ .addFilter('IDAnimal', 4);
569
+
570
+ testMeadow.doDelete(tmpQuery,
571
+ function (pError, pQuery, pRecord)
572
+ {
573
+ // It returns the number of rows deleted
574
+ Expect(pRecord)
575
+ .to.equal(1);
576
+ fDone();
577
+ }
578
+ )
579
+ }
580
+ );
581
+ test
582
+ (
583
+ 'Count all records from the database',
584
+ function (fDone)
585
+ {
586
+ var testMeadow = newMeadow();
587
+
588
+ testMeadow.doCount(testMeadow.query.setLogLevel(5),
589
+ function (pError, pQuery, pRecord)
590
+ {
591
+ // There should be 7 records
592
+ Expect(pRecord)
593
+ .to.equal(7);
594
+ fDone();
595
+ }
596
+ )
597
+ }
598
+ );
599
+ test
600
+ (
601
+ 'Read a record from the database that had a defined GUID',
602
+ function (fDone)
603
+ {
604
+ var testMeadow = newMeadow();
605
+
606
+ var tmpQuery = testMeadow.query
607
+ .addFilter('GUIDAnimal', '0x12345');
608
+
609
+ testMeadow.doRead(tmpQuery,
610
+ function (pError, pQuery, pRecord)
611
+ {
612
+ // We should have a record ....
613
+ Expect(pRecord.Name)
614
+ .to.equal('MewThree');
615
+ fDone();
616
+ }
617
+ )
618
+ }
619
+ );
620
+ test
621
+ (
622
+ 'Create a record in the database with a defined creating user',
623
+ function (fDone)
624
+ {
625
+ var testMeadow = newMeadow();
626
+ var tmpQuery = testMeadow.query
627
+ .setIDUser(800)
628
+ .addRecord({ Name: 'MewSix', GUIDAnimal: '0x123456', Type: 'Pokemon' });
629
+
630
+ testMeadow.doCreate(tmpQuery,
631
+ function (pError, pQuery, pQueryRead, pRecord)
632
+ {
633
+ // We should have a record ....
634
+ Expect(pRecord.Name)
635
+ .to.equal('MewSix');
636
+ Expect(pRecord.CreatingIDUser)
637
+ .to.equal(800);
638
+ fDone();
639
+ }
640
+ )
641
+ }
642
+ );
643
+ }
644
+ );
645
+ suite
646
+ (
647
+ 'The Bad Kind of Query Processing',
648
+ function ()
649
+ {
650
+ test
651
+ (
652
+ 'Create a record in the database with no record',
653
+ function (fDone)
654
+ {
655
+ var testMeadow = newMeadow().setDefaultIdentifier('Type');
656
+
657
+ testMeadow.doCreate(testMeadow.query,
658
+ function (pError, pQuery, pQueryRead, pRecord)
659
+ {
660
+ Expect(pError)
661
+ .to.equal('No record submitted');
662
+ fDone();
663
+ }
664
+ )
665
+ }
666
+ );
667
+ test
668
+ (
669
+ 'Read a record from the database with no data returned',
670
+ function (fDone)
671
+ {
672
+ var testMeadow = newMeadow();
673
+
674
+ var tmpQuery = testMeadow.query
675
+ .addFilter('IDAnimal', 5000);
676
+ testMeadow.doRead(tmpQuery,
677
+ function (pError, pQuery, pRecord)
678
+ {
679
+ Expect(pRecord)
680
+ .to.equal(false);
681
+ fDone();
682
+ }
683
+ )
684
+ }
685
+ );
686
+ test
687
+ (
688
+ 'Read records from the database with no data returned',
689
+ function (fDone)
690
+ {
691
+ var testMeadow = newMeadow();
692
+
693
+ var tmpQuery = testMeadow.query
694
+ .addFilter('IDAnimal', 5000);
695
+
696
+ testMeadow.doReads(tmpQuery,
697
+ function (pError, pQuery, pRecord)
698
+ {
699
+ Expect(pRecord.length)
700
+ .to.equal(0);
701
+ fDone();
702
+ }
703
+ )
704
+ }
705
+ );
706
+ test
707
+ (
708
+ 'Update a record in the database with a bad filter',
709
+ function (fDone)
710
+ {
711
+ var testMeadow = newMeadow();
712
+
713
+ var tmpQuery = testMeadow.query
714
+ .setLogLevel(5)
715
+ .addRecord({ IDAnimal: undefined, Type: 'HumanGirl' });
716
+
717
+ testMeadow.doUpdate(tmpQuery,
718
+ function (pError, pQuery, pQueryRead, pRecord)
719
+ {
720
+ Expect(pError)
721
+ .to.equal('Automated update missing filters... aborting!');
722
+ fDone();
723
+ }
724
+ )
725
+ }
726
+ );
727
+ test
728
+ (
729
+ 'Update a record in the database without passing a record in',
730
+ function (fDone)
731
+ {
732
+ var testMeadow = newMeadow();
733
+
734
+ testMeadow.doUpdate(testMeadow.query,
735
+ function (pError, pQuery, pQueryRead, pRecord)
736
+ {
737
+ Expect(pError)
738
+ .to.equal('No record submitted');
739
+ fDone();
740
+ }
741
+ )
742
+ }
743
+ );
744
+ test
745
+ (
746
+ 'Update a record in the database with a bad record passed in (no default identifier)',
747
+ function (fDone)
748
+ {
749
+ var testMeadow = newMeadow();
750
+
751
+ var tmpQuery = testMeadow.query
752
+ .addRecord({ Name: 'Bill' });
753
+
754
+ testMeadow.doUpdate(tmpQuery,
755
+ function (pError, pQuery, pQueryRead, pRecord)
756
+ {
757
+ Expect(pError)
758
+ .to.equal('Automated update missing default identifier');
759
+ fDone();
760
+ }
761
+ )
762
+ }
763
+ );
764
+ test
765
+ (
766
+ 'Update a record in the database that does not exist',
767
+ function (fDone)
768
+ {
769
+ var testMeadow = newMeadow();
770
+
771
+ var tmpQuery = testMeadow.query
772
+ .addRecord({ IDAnimal: 983924 });
773
+
774
+ testMeadow.doUpdate(tmpQuery,
775
+ function (pError, pQuery, pQueryRead, pRecord)
776
+ {
777
+ Expect(pError)
778
+ .to.equal('No record found to update!');
779
+ fDone();
780
+ }
781
+ )
782
+ }
783
+ );
784
+ }
785
+ );
786
+ }
787
+ );