meadow-endpoints 3.0.7 → 4.0.2

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 (127) hide show
  1. package/Dockerfile_LUXURYCode +1 -1
  2. package/README.md +48 -14
  3. package/debug/Animal.json +62 -0
  4. package/debug/Harness-Configuration.json +31 -0
  5. package/debug/Harness.js +7 -108
  6. package/debug/KillHarness.sh +10 -0
  7. package/dist/meadowendpoints.js +4402 -0
  8. package/dist/meadowendpoints.min.js +92 -0
  9. package/dist/meadowendpoints.min.js.map +1 -0
  10. package/gulpfile.js +83 -0
  11. package/package.json +27 -15
  12. package/source/Meadow-Endpoints-Browser-Shim.js +14 -0
  13. package/source/Meadow-Endpoints.js +176 -565
  14. package/source/controller/Meadow-Endpoints-Controller-Base.js +161 -0
  15. package/source/controller/components/Meadow-Endpoints-Controller-BehaviorInjection.js +125 -0
  16. package/source/controller/components/Meadow-Endpoints-Controller-Error-StatusCodes.txt +189 -0
  17. package/source/controller/components/Meadow-Endpoints-Controller-Error.js +118 -0
  18. package/source/controller/components/Meadow-Endpoints-Controller-Log.js +103 -0
  19. package/source/controller/utility/Meadow-Endpoints-Filter-Parser.js +225 -0
  20. package/source/controller/utility/Meadow-Endpoints-Session-Marshaler.js +48 -0
  21. package/source/controller/utility/Meadow-Endpoints-Stream-RecordArray.js +66 -0
  22. package/source/endpoints/count/Meadow-Endpoint-Count.js +49 -0
  23. package/source/endpoints/count/Meadow-Endpoint-CountBy.js +40 -0
  24. package/source/endpoints/create/Meadow-Endpoint-BulkCreate.js +53 -0
  25. package/source/endpoints/create/Meadow-Endpoint-Create.js +58 -0
  26. package/source/endpoints/create/Meadow-Operation-Create.js +83 -0
  27. package/source/endpoints/delete/Meadow-Endpoint-Delete.js +93 -0
  28. package/source/endpoints/delete/Meadow-Endpoint-Undelete.js +108 -0
  29. package/source/endpoints/read/Meadow-Endpoint-Read.js +72 -0
  30. package/source/endpoints/read/Meadow-Endpoint-ReadDistinctList.js +92 -0
  31. package/source/endpoints/read/Meadow-Endpoint-ReadLiteList.js +85 -0
  32. package/source/endpoints/read/Meadow-Endpoint-ReadMax.js +55 -0
  33. package/source/endpoints/read/Meadow-Endpoint-ReadSelectList.js +89 -0
  34. package/source/endpoints/read/Meadow-Endpoint-Reads.js +75 -0
  35. package/source/endpoints/read/Meadow-Endpoint-ReadsBy.js +100 -0
  36. package/source/{crud → endpoints/read}/Meadow-Marshal-DistinctList.js +4 -13
  37. package/source/{crud → endpoints/read}/Meadow-Marshal-LiteList.js +5 -14
  38. package/source/endpoints/schema/Meadow-Endpoint-New.js +36 -0
  39. package/source/endpoints/schema/Meadow-Endpoint-Schema.js +36 -0
  40. package/source/endpoints/schema/Meadow-Endpoint-Validate.js +41 -0
  41. package/source/endpoints/update/Meadow-Endpoint-BulkUpdate.js +50 -0
  42. package/source/endpoints/update/Meadow-Endpoint-Update.js +58 -0
  43. package/source/endpoints/update/Meadow-Operation-Update.js +115 -0
  44. package/source/endpoints/upsert/Meadow-Endpoint-BulkUpsert.js +52 -0
  45. package/source/endpoints/upsert/Meadow-Endpoint-Upsert.js +57 -0
  46. package/source/endpoints/upsert/Meadow-Operation-Upsert.js +137 -0
  47. package/test/MeadowEndpoints_basic_tests.js +50 -2408
  48. package/test_support/bookstore-api-endpoint-exercises.paw +0 -0
  49. package/test_support/bookstore-configuration.json +28 -0
  50. package/test_support/bookstore-import-books-run.js +1 -0
  51. package/test_support/bookstore-import-books.js +215 -0
  52. package/test_support/bookstore-serve-meadow-endpoint-apis-IPC.js +138 -0
  53. package/test_support/bookstore-serve-meadow-endpoint-apis-run.js +6 -0
  54. package/test_support/bookstore-serve-meadow-endpoint-apis.js +129 -0
  55. package/test_support/data/books.csv +10001 -0
  56. package/test_support/model/ddl/BookStore.ddl +66 -0
  57. package/test_support/model/generated_diagram/README.md +1 -0
  58. package/test_support/model/generated_diagram/Stricture_Output.dot +13 -0
  59. package/test_support/model/generated_diagram/Stricture_Output.png +0 -0
  60. package/test_support/model/generated_documentation/Dictionary.md +18 -0
  61. package/test_support/model/generated_documentation/Model-Author.md +20 -0
  62. package/test_support/model/generated_documentation/Model-Book.md +26 -0
  63. package/test_support/model/generated_documentation/Model-BookAuthorJoin.md +14 -0
  64. package/test_support/model/generated_documentation/Model-BookPrice.md +25 -0
  65. package/test_support/model/generated_documentation/Model-Review.md +22 -0
  66. package/test_support/model/generated_documentation/ModelChangeTracking.md +17 -0
  67. package/test_support/model/generated_documentation/README.md +1 -0
  68. package/test_support/model/manual_scripts/DropTables.sql +5 -0
  69. package/test_support/model/manual_scripts/README.md +2 -0
  70. package/test_support/model/sql_create/BookStore-CreateDatabase.mysql.sql +116 -0
  71. package/test_support/model/sql_create/README.md +1 -0
  72. package/test_support/test_old/Tests.js +3243 -0
  73. package/test_support/test_old/untitled.js +88 -0
  74. package/source/Meadow-Authenticator.js +0 -31
  75. package/source/Meadow-Authorizers.js +0 -214
  76. package/source/Meadow-BehaviorModifications.js +0 -170
  77. package/source/Meadow-CommonServices.js +0 -206
  78. package/source/Meadow-MarshallSessionData.js +0 -64
  79. package/source/Restify-RouteParser.js +0 -114
  80. package/source/authorizers/Meadow-Authorizer-Allow.js +0 -17
  81. package/source/authorizers/Meadow-Authorizer-Deny.js +0 -17
  82. package/source/authorizers/Meadow-Authorizer-Mine.js +0 -47
  83. package/source/authorizers/Meadow-Authorizer-MyCustomer.js +0 -48
  84. package/source/crud/Meadow-Endpoint-BulkCreate.js +0 -67
  85. package/source/crud/Meadow-Endpoint-BulkUpdate.js +0 -74
  86. package/source/crud/Meadow-Endpoint-BulkUpsert.js +0 -76
  87. package/source/crud/Meadow-Endpoint-Count.js +0 -93
  88. package/source/crud/Meadow-Endpoint-CountBy.js +0 -101
  89. package/source/crud/Meadow-Endpoint-Create.js +0 -77
  90. package/source/crud/Meadow-Endpoint-Delete.js +0 -139
  91. package/source/crud/Meadow-Endpoint-Read.js +0 -109
  92. package/source/crud/Meadow-Endpoint-ReadDistinctList.js +0 -146
  93. package/source/crud/Meadow-Endpoint-ReadLiteList.js +0 -139
  94. package/source/crud/Meadow-Endpoint-ReadMax.js +0 -86
  95. package/source/crud/Meadow-Endpoint-ReadSelectList.js +0 -145
  96. package/source/crud/Meadow-Endpoint-Reads.js +0 -129
  97. package/source/crud/Meadow-Endpoint-ReadsBy.js +0 -155
  98. package/source/crud/Meadow-Endpoint-Undelete.js +0 -161
  99. package/source/crud/Meadow-Endpoint-Update.js +0 -80
  100. package/source/crud/Meadow-Endpoint-Upsert.js +0 -78
  101. package/source/crud/Meadow-Operation-Create.js +0 -105
  102. package/source/crud/Meadow-Operation-Update.js +0 -145
  103. package/source/crud/Meadow-Operation-Upsert.js +0 -106
  104. package/source/crud/Meadow-StreamRecordArray.js +0 -45
  105. package/source/schema/Meadow-Endpoint-New.js +0 -37
  106. package/source/schema/Meadow-Endpoint-Schema.js +0 -37
  107. package/source/schema/Meadow-Endpoint-Validate.js +0 -43
  108. package/test/Animal.json +0 -140
  109. package/test/MeadowEndpoints_disabledAuth_tests.js +0 -1325
  110. package/test/MeadowEndpoints_trustedSession_tests.js +0 -1731
  111. package/test/load/artillery-low.yml +0 -10
  112. package/test/load/cloud9setup.sh +0 -25
  113. package/test/load/package.json +0 -19
  114. package/test/load/test-schema-initializedatabase.sql +0 -29
  115. package/test/load/test-schema.json +0 -119
  116. package/test/load/test-server.js +0 -157
  117. package/test/scripts/InitializeDatabase-C9.sql +0 -7
  118. /package/{test/schemas → test_support/model}/json_schema/BookStore-Extended.json +0 -0
  119. /package/{test/schemas → test_support/model}/json_schema/BookStore-PICT.json +0 -0
  120. /package/{test/schemas → test_support/model}/json_schema/BookStore.json +0 -0
  121. /package/{test/schemas → test_support/model}/json_schema/README.md +0 -0
  122. /package/{test/schemas → test_support/model}/meadow_schema/BookStore-MeadowSchema-Author.json +0 -0
  123. /package/{test/schemas → test_support/model}/meadow_schema/BookStore-MeadowSchema-Book.json +0 -0
  124. /package/{test/schemas → test_support/model}/meadow_schema/BookStore-MeadowSchema-BookAuthorJoin.json +0 -0
  125. /package/{test/schemas → test_support/model}/meadow_schema/BookStore-MeadowSchema-BookPrice.json +0 -0
  126. /package/{test/schemas → test_support/model}/meadow_schema/BookStore-MeadowSchema-Review.json +0 -0
  127. /package/{test/schemas → test_support/model}/meadow_schema/README.md +0 -0
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Unit tests for the MeadowEndpoints Server
2
+ * Unit tests for Meadow Endpoints
3
3
  *
4
4
  * @license MIT
5
5
  *
@@ -10,398 +10,81 @@ var Chai = require("chai");
10
10
  var Expect = Chai.expect;
11
11
  var Assert = Chai.assert;
12
12
 
13
- var libSuperTest = require('supertest');
13
+ const libAsync = require('async');
14
14
 
15
- var libMySQL = require('mysql2');
16
- var libAsync = require('async');
15
+ const libBookServer = require('../test_support/bookstore-serve-meadow-endpoint-apis.js');
16
+ let _BookServer = false;
17
17
 
18
- var tmpFableSettings = (
19
- {
20
- Product: 'MockOratorAlternate',
21
- ProductVersion: '0.0.0',
18
+ let _INITIALIZATION_COMPLETE = false;
22
19
 
23
- "UnauthorizedRequestDelay": 10,
20
+ const libMeadowEndpoints = require('../source/Meadow-Endpoints.js');
24
21
 
25
- MeadowAuthenticationMode: 'LoggedIn',
26
- MeadowAuthorizationMode: 'SimpleOwnership',
27
-
28
- APIServerPort: 9080,
29
-
30
- MySQL:
31
- {
32
- // This is queued up for Travis defaults.
33
- Server: "localhost",
34
- Port: 3306,
35
- User: process.env.DEV_MYSQL_USER || "root",
36
- Password: process.env.DEV_MYSQL_PASS || "123456789",
37
- Database: "FableTest",
38
- ConnectionPoolLimit: 20
39
- },
40
- ConfigFile: __dirname + "/../MeadowTest-Settings.json"
41
- });
42
-
43
- var libFable = require('fable').new(tmpFableSettings);
44
- tmpFableSettings = libFable.settings;
45
-
46
- libFable.MeadowMySQLConnectionPool = libMySQL.createPool
47
- (
48
- {
49
- connectionLimit: libFable.settings.MySQL.ConnectionPoolLimit,
50
- host: libFable.settings.MySQL.Server,
51
- port: libFable.settings.MySQL.Port,
52
- user: libFable.settings.MySQL.User,
53
- password: libFable.settings.MySQL.Password,
54
- database: libFable.settings.MySQL.Database,
55
- namedPlaceholders: true
56
- }
57
- );
58
-
59
- var _MockSessionValidUser = (
60
- {
61
- SessionID: '0000-VALID',
62
- UserID: 37,
63
- UserRole: 'User',
64
- UserRoleIndex: 1,
65
- LoggedIn: true,
66
- DeviceID: 'TEST-HARNESS',
67
- CustomerID: 1
68
- });
69
- var ValidAuthentication = function(pRequest, pResponse, fNext)
70
- {
71
- pRequest.UserSession = _MockSessionValidUser;
72
- fNext();
73
- }
74
-
75
- var _Meadow;
76
- var _MeadowEndpoints;
77
-
78
- var _AnimalSchema = require('./Animal.json');
79
-
80
- // Now that we have some test data, wire up the endpoints!
81
-
82
- // Load up a Meadow (pointing at the Animal database)
83
- _Meadow = require('meadow')
84
- .new(libFable, 'FableTest')
85
- .setProvider('MySQL')
86
- .setSchema(_AnimalSchema.Schema)
87
- .setJsonSchema(_AnimalSchema.JsonSchema)
88
- .setDefaultIdentifier(_AnimalSchema.DefaultIdentifier)
89
- .setDefault(_AnimalSchema.DefaultObject)
90
- .setAuthorizer(_AnimalSchema.Authorization);
91
- // Instantiate the endpoints
92
- _MeadowEndpoints = require('../source/Meadow-Endpoints.js').new(_Meadow);
22
+ const libSuperTest = require('supertest');
93
23
 
94
24
  suite
95
25
  (
96
- 'Meadow-Endpoints',
97
- function()
26
+ 'Meadow-Endpoints-Core',
27
+ () =>
98
28
  {
99
- // TODO: Abstract this so it can be run again and again.
100
- var _SpooledUp = false;
101
- var _Orator;
102
-
103
- var getAnimalInsert = function(pName, pType)
29
+ suiteSetup ((fSetupComplete) =>
104
30
  {
105
- return "INSERT INTO `FableTest` (`IDAnimal`, `GUIDAnimal`, `CreateDate`, `CreatingIDUser`, `UpdateDate`, `UpdatingIDUser`, `Deleted`, `DeleteDate`, `DeletingIDUser`, `Name`, `Type`, `IDCustomer`) VALUES (NULL, '00000000-0000-0000-0000-000000000000', NOW(), 1, NOW(), 1, 0, NULL, 0, '"+pName+"', '"+pType+"', 1); ";
106
- };
107
-
108
- setup
109
- (
110
- function(fDone)
31
+ if (!_INITIALIZATION_COMPLETE)
111
32
  {
112
- // Only do this for the first test, so we persiste database state across suites
113
- if (!_SpooledUp)
114
- {
115
- _Orator = require('orator').new(tmpFableSettings);
116
- _Orator.enabledModules.CORS = true;
117
- _Orator.enabledModules.FullResponse = true;
118
- _Orator.enabledModules.Body = false;
119
-
120
-
121
- var _SQLConnectionPool = libMySQL.createPool
122
- (
123
- {
124
- connectionLimit: tmpFableSettings.MySQL.ConnectionPoolLimit,
125
- host: tmpFableSettings.MySQL.Server,
126
- port: tmpFableSettings.MySQL.Port,
127
- user: tmpFableSettings.MySQL.User,
128
- password: tmpFableSettings.MySQL.Password,
129
- database: tmpFableSettings.MySQL.Database
130
- }
131
- );
132
-
133
- // Tear down previous test data, rebuild records
134
- libAsync.waterfall(
135
- [
136
- function(fCallBack)
137
- {
138
- _SQLConnectionPool.query('DROP TABLE IF EXISTS FableTest',
139
- function(pErrorUpdate, pResponse) { fCallBack(null); });
140
- },
141
- function(fCallBack)
142
- {
143
- _SQLConnectionPool.query("CREATE TABLE IF NOT EXISTS FableTest (IDAnimal INT UNSIGNED NOT NULL AUTO_INCREMENT, GUIDAnimal CHAR(36) NOT NULL DEFAULT '00000000-0000-0000-0000-000000000000', CreateDate DATETIME, CreatingIDUser INT NOT NULL DEFAULT '0', UpdateDate DATETIME, UpdatingIDUser INT NOT NULL DEFAULT '0', Deleted TINYINT NOT NULL DEFAULT '0', DeleteDate DATETIME, DeletingIDUser INT NOT NULL DEFAULT '0', Name CHAR(128) NOT NULL DEFAULT '', Type CHAR(128) NOT NULL DEFAULT '', IDCustomer INT NOT NULL DEFAULT '0', PRIMARY KEY (IDAnimal) );",
144
- function(pErrorUpdate, pResponse) { fCallBack(null); });
145
- },
146
- function(fCallBack)
147
- {
148
- _SQLConnectionPool.query(getAnimalInsert('Foo Foo', 'Bunny'),
149
- function(pErrorUpdate, pResponse) { fCallBack(null); });
150
- },
151
- function(fCallBack)
152
- {
153
- _SQLConnectionPool.query(getAnimalInsert('Red Riding Hood', 'Girl'),
154
- function(pErrorUpdate, pResponse) { fCallBack(null); });
155
- },
156
- function(fCallBack)
157
- {
158
- _SQLConnectionPool.query(getAnimalInsert('Red', 'Dog'),
159
- function(pErrorUpdate, pResponse) { fCallBack(null); });
160
- },
161
- function(fCallBack)
162
- {
163
- _SQLConnectionPool.query(getAnimalInsert('Spot', 'Dog'),
164
- function(pErrorUpdate, pResponse) { fCallBack(null); });
165
- },
166
- function(fCallBack)
167
- {
168
- _SQLConnectionPool.query(getAnimalInsert('Gertrude', 'Frog'),
169
- function(pErrorUpdate, pResponse) { fCallBack(null); });
170
- },
171
- function(fCallBack)
172
- {
173
- // Start the web server
174
- // Wire up an "always logged in" user in the request chain, so session is set right.
175
- _Orator.webServer.use(ValidAuthentication);
176
- _MeadowEndpoints.setEndpointAuthorization
177
- (
178
- 'Create',
179
- 2
180
- );
181
- _MeadowEndpoints.setEndpointAuthenticator ('Reads');
182
- _MeadowEndpoints.setEndpointAuthenticator
183
- (
184
- 'Reads',
185
- function(pRequest, pResponse, fNext)
186
- {
187
- pRequest.EndpointAuthenticated = true;
188
- fNext();
189
- }
190
- );
191
- _MeadowEndpoints.setEndpoint('Randomize');
192
- _MeadowEndpoints.setEndpoint('Randomize', function() {});
193
-
194
- _MeadowEndpoints.behaviorModifications.setTemplate('ListQuery', '<%= MyData %>');
195
- //_MeadowEndpoints.behaviorModifications.setTemplate('SelectList', '<%= Name %>|<%= Type %>');
196
-
197
- // Wire the endpoints up
198
- _MeadowEndpoints.connectRoutes(_Orator.webServer);
199
- _Orator.startWebServer (function() { fCallBack(null); });
200
- }
201
- ],
202
- function(pError, pResult)
203
- {
204
- // Now continue the tests.
205
- _SpooledUp = true;
206
- fDone();
207
- }
208
- );
209
- }
210
- else
33
+ // do something before every test
34
+ console.log('Beginning Custom Test Suite(s) Setup...')
35
+ libAsync.waterfall([
36
+ // Launch the book server
37
+ (fStageComplete)=>
38
+ {
39
+ console.log('...Server...');
40
+ _BookServer = libBookServer(fStageComplete);
41
+ }
42
+ ],
43
+ (pError) =>
211
44
  {
212
- fDone();
213
- }
45
+ console.log('Setup complete!')
46
+ _INITIALIZATION_COMPLETE = true;
47
+ return fSetupComplete(pError);
48
+ });
214
49
  }
215
- );
50
+ });
216
51
 
217
- setup
218
- (
219
- function()
52
+ suiteTeardown((fTeardownComplete) =>
53
+ {
54
+ console.log('Ending suite!');
55
+ _BookServer.serviceServer.close(()=>
220
56
  {
221
- }
222
- );
57
+ console.log('...Server closed!')
58
+ return fTeardownComplete();
59
+ });
60
+ })
223
61
 
224
62
  suite
225
63
  (
226
64
  'Object Sanity',
227
- function()
228
- {
229
- test
230
- (
231
- 'initialize should build a happy little object',
232
- function()
233
- {
234
- Expect(_MeadowEndpoints).to.be.an('object', 'MeadowEndpoints should initialize as an object directly from the require statement.');
235
- }
236
- );
237
- }
238
- );
239
- suite
240
- (
241
- 'Behavior Modifications',
242
- function()
65
+ () =>
243
66
  {
244
67
  test
245
68
  (
246
- 'instantiate a behavior modification object',
247
- function()
248
- {
249
- var tmpBehaviorMods = require('../source/Meadow-BehaviorModifications.js').new(libFable);
250
- Expect(tmpBehaviorMods).to.be.an('object');
251
- }
252
- );
253
- test
254
- (
255
- 'exercise the templates api',
256
- function()
257
- {
258
- var tmpBehaviorMods = require('../source/Meadow-BehaviorModifications.js').new(libFable);
259
-
260
- var tmpCrossBehaviorState = 0;
261
-
262
- Expect(tmpBehaviorMods.runBehavior('NoBehaviorsHere', {}, function() {})).to.equal(undefined, 'nonexistant behaviors should just execute');
263
- tmpBehaviorMods.setBehavior('BigBehavior', function() { tmpCrossBehaviorState++ });
264
- Expect(tmpCrossBehaviorState).to.equal(0);
265
- Expect(tmpBehaviorMods.runBehavior('BigBehavior', {}, function() {})).to.equal(undefined, 'existant behaviors should just execute');
266
- Expect(tmpCrossBehaviorState).to.equal(1);
267
- }
268
- );
269
- test
270
- (
271
- 'exercise the behavior modification api',
272
- function()
273
- {
274
- var tmpBehaviorMods = require('../source/Meadow-BehaviorModifications.js').new(libFable);
275
- Expect(tmpBehaviorMods.getTemplateFunction('NoTemplatesHere')).to.equal(false, 'empty template hashes on empty sets should return false');
276
- Expect(tmpBehaviorMods.getTemplate('NoTemplatesHere')).to.equal(false,'emtpy template sets should be false');
277
- tmpBehaviorMods.setTemplate('AnimalFormatter', '<p>An animal (id <%= Number %> is here</p>');
278
- Expect(tmpBehaviorMods.getTemplate('AnimalFormatter')).to.contain('An animal');
279
- Expect(tmpBehaviorMods.processTemplate('AnimalFormatter', {Number:5})).to.contain('id 5');
280
- Expect(tmpBehaviorMods.processTemplate('FriendFormatter', {Number:5}, 'blit <%= Number %>')).to.contain('blit 5');
281
- Expect(tmpBehaviorMods.processTemplate('Blank', {Number:5})).to.equal('');
282
- tmpBehaviorMods.setTemplate('SimpleTemplate', 'Not so simple.');
283
- Expect(tmpBehaviorMods.processTemplate('SimpleTemplate')).to.equal('Not so simple.');
284
- }
285
- );
286
- test
287
- (
288
- 'exercise the security modification api',
289
- function()
290
- {
291
- var tmpAuthorizers = require('../source/Meadow-Authorizers.js').new(libFable);
292
- tmpAuthorizers.setAuthorizer('AlwaysAuthorize',
293
- function(pRequest, fComplete)
294
- {
295
- pRequest.MeadowAuthorization = true;
296
- });
297
- var tmpMockRequest = {MeadowAuthorization: 'Green'};
298
- tmpAuthorizers.authorize('BadHash', tmpMockRequest,
299
- function()
300
- {
301
- Expect(tmpMockRequest.MeadowAuthorization).to.equal('Green');
302
- });
303
- tmpAuthorizers.authorize('AlwaysAuthorize', tmpMockRequest,
304
- function()
305
- {
306
- Expect(tmpMockRequest.MeadowAuthorization).to.equal(true);
307
- });
308
- tmpAuthorizers.authorize('Allow', tmpMockRequest,
309
- function()
310
- {
311
- Expect(tmpMockRequest.MeadowAuthorization).to.equal(true);
312
- });
313
- tmpAuthorizers.authorize('Deny', tmpMockRequest,
314
- function()
315
- {
316
- Expect(tmpMockRequest.MeadowAuthorization).to.equal(false);
317
- });
318
- var tmpMockFullRequest =
319
- {
320
- UserSession:
321
- {
322
- CustomerID: 10,
323
- UserID: 1
324
- },
325
- Record:
326
- {
327
- IDCustomer: 10,
328
- IDUser: 1
329
- }
330
- };
331
- // Test that
332
- }
333
- );
334
- test
335
- (
336
- 'exercise the security modification authenticators',
337
- function()
69
+ 'The class should initialize itself into a happy little object.',
70
+ function (fDone)
338
71
  {
339
- var tmpAuthorizers = require('../source/Meadow-Authorizers.js').new(libFable);
340
- var tmpMockFullRequest =
341
- {
342
- UserSession:
343
- {
344
- CustomerID: 10,
345
- UserID: 1
346
- },
347
- Record:
348
- {
349
- IDCustomer: 10,
350
- CreatingIDUser: 1
351
- }
352
- };
353
- // Mine and MyCustomer should both work
354
- tmpAuthorizers.authorize('Mine', tmpMockFullRequest,
355
- function()
356
- {
357
- Expect(tmpMockFullRequest.MeadowAuthorization).to.equal(true);
358
- });
359
- tmpAuthorizers.authorize('MyCustomer', tmpMockFullRequest,
360
- function()
361
- {
362
- Expect(tmpMockFullRequest.MeadowAuthorization).to.equal(true);
363
- });
364
- tmpMockFullRequest.UserSession.CustomerID = 100;
365
- tmpMockFullRequest.UserSession.UserID = 100;
366
- // Now they should both fail
367
- tmpAuthorizers.authorize('Mine', tmpMockFullRequest,
368
- function()
369
- {
370
- //If record does not have matching CreatingIDUser, then it should fail
371
- Expect(tmpMockFullRequest.MeadowAuthorization).to.equal(false);
372
- });
373
- tmpAuthorizers.authorize('MyCustomer', tmpMockFullRequest,
374
- function()
375
- {
376
- //If record does not have matching CustomerID, then it should fail
377
- Expect(tmpMockFullRequest.MeadowAuthorization).to.equal(false);
378
- });
72
+ Expect(true).to.equal(true);
73
+ fDone();
379
74
  }
380
75
  );
381
- }
382
- );
383
- suite
384
- (
385
- 'Basic Server Routes',
386
- function()
387
- {
388
76
  test
389
77
  (
390
- 'create: create a record',
78
+ 'read: get a specific record',
391
79
  function(fDone)
392
80
  {
393
- var tmpRecord = {Name:'BatBrains', Type:'Mammoth'};
394
- _MockSessionValidUser.UserRoleIndex = 2;
395
- libSuperTest('http://localhost:9080/')
396
- .post('1.0/FableTest')
397
- .send(tmpRecord)
81
+ libSuperTest('http://localhost:8086/')
82
+ .get('1.0/Book/1')
398
83
  .end(
399
- function(pError, pResponse)
84
+ function (pError, pResponse)
400
85
  {
401
- // Expect response to be the record we just created.
402
86
  var tmpResult = JSON.parse(pResponse.text);
403
- Expect(tmpResult.Type).to.equal('Mammoth');
404
- Expect(tmpResult.CreatingIDUser).to.equal(37);
87
+ Expect(tmpResult.Title).to.equal('The Hunger Games');
405
88
  fDone();
406
89
  }
407
90
  );
@@ -412,2058 +95,17 @@ suite
412
95
  'create: create a record',
413
96
  function(fDone)
414
97
  {
415
- var tmpRecord = {Name:'BatBrains', Type:'Mammoth'};
416
- _MockSessionValidUser.UserRoleIndex = 1;
417
- libSuperTest('http://localhost:9080/')
418
- .post('1.0/FableTest')
419
- .send(tmpRecord)
420
- .end(
421
- function(pError, pResponse)
422
- {
423
- // Expect response to be the record we just created.
424
- var tmpResult = JSON.parse(pResponse.text);
425
- Expect(tmpResult.Error).to.contain('authenticated');
426
- fDone();
427
- }
428
- );
429
- }
430
- );
431
- test
432
- (
433
- 'create: create a record with a bad record passed in',
434
- function(fDone)
435
- {
436
- var tmpRecord = ' ';
437
- _MockSessionValidUser.UserRoleIndex = 2;
438
- libSuperTest('http://localhost:9080/')
439
- .post('1.0/FableTest')
98
+ var tmpRecord = {Title:'Batman is Batman'};
99
+ libSuperTest('http://localhost:8086/')
100
+ .post('1.0/Book')
440
101
  .send(tmpRecord)
441
102
  .end(
442
103
  function(pError, pResponse)
443
104
  {
444
105
  // Expect response to be the record we just created.
445
106
  var tmpResult = JSON.parse(pResponse.text);
446
- Expect(tmpResult.Error).to.not.be.null;
447
- fDone();
448
- }
449
- );
450
- }
451
- );
452
- test
453
- (
454
- 'read: get a specific record',
455
- function(fDone)
456
- {
457
- libSuperTest('http://localhost:9080/')
458
- .get('1.0/FableTest/2')
459
- .end(
460
- function (pError, pResponse)
461
- {
462
- var tmpResult = JSON.parse(pResponse.text);
463
- Expect(tmpResult.Type).to.equal('Girl');
464
- fDone();
465
- }
466
- );
467
- }
468
- );
469
- test
470
- (
471
- 'read: define a custom authorization behavior',
472
- function(fDone)
473
- {
474
- const defaultAuthorizer = _MeadowEndpoints.endpointAuthorizers.getAuthorizer('Allow');
475
- _MeadowEndpoints.endpointAuthorizers.setAuthorizer('Allow', function(req, next) { req.MeadowAuthorization = false; return next(); });
476
- _Orator.webServer.get('/CustomHotRodRoute/:IDRecord', _MeadowEndpoints.endpointAuthenticators.Read, _MeadowEndpoints.wireState, _MeadowEndpoints.endpoints.Read);
477
- libSuperTest('http://localhost:9080/')
478
- .get('CustomHotRodRoute/2')
479
- .end(
480
- function (pError, pResponse)
481
- {
482
- _MeadowEndpoints.endpointAuthorizers.setAuthorizer('Allow', defaultAuthorizer);
483
- //TODO: it's weird that we don't get an error here for access denied...
484
- var tmpResult = JSON.parse(pResponse.text);
485
- Expect(tmpResult.Error).to.equal('UNAUTHORIZED ACCESS IS NOT ALLOWED');
486
- fDone();
487
- }
488
- );
489
- }
490
- );
491
- test
492
- (
493
- 'read: define a custom route and get a record with it',
494
- function(fDone)
495
- {
496
- _Orator.webServer.get('/CustomHotRodRoute/:IDRecord', _MeadowEndpoints.endpointAuthenticators.Read, _MeadowEndpoints.wireState, _MeadowEndpoints.endpoints.Read);
497
- libSuperTest('http://localhost:9080/')
498
- .get('CustomHotRodRoute/2')
499
- .end(
500
- function (pError, pResponse)
501
- {
502
- var tmpResult = JSON.parse(pResponse.text);
503
- Expect(tmpResult.Type).to.equal('Girl');
504
- fDone();
505
- }
506
- );
507
- }
508
- );
509
- test
510
- (
511
- 'read: get a specific record but be denied by security',
512
- function(fDone)
513
- {
514
- _Meadow.schemaFull.authorizer.Manager = {};
515
- _Meadow.schemaFull.authorizer.Manager.Read = 'Deny';
516
-
517
- libSuperTest('http://localhost:9080/')
518
- .get('1.0/FableTest/2')
519
- .end(
520
- function (pError, pResponse)
521
- {
522
- Expect(pResponse.text).to.contain('UNAUTHORIZED ACCESS IS NOT ALLOWED');
523
- // Reset authorization
524
- _Meadow.schemaFull.authorizer.Manager.Read = 'Allow';
525
- fDone();
526
- }
527
- );
528
- }
529
- );
530
- test
531
- (
532
- 'read: get a specific record which resolved to Deny authorization, but with a Deny authorizer that just allows',
533
- function(fDone)
534
- {
535
- _Meadow.schemaFull.authorizer.Manager = {};
536
- _Meadow.schemaFull.authorizer.Manager.Read = 'Deny';
537
- const defaultAuthorizer = _MeadowEndpoints.endpointAuthorizers.getAuthorizer('Deny');
538
- _MeadowEndpoints.endpointAuthorizers.setAuthorizer('Deny', function(req, next) { req.MeadowAuthorization = true; return next(); });
539
-
540
- libSuperTest('http://localhost:9080/')
541
- .get('1.0/FableTest/2')
542
- .end(
543
- function (pError, pResponse)
544
- {
545
- // Reset authorization
546
- _Meadow.schemaFull.authorizer.Manager.Read = 'Allow';
547
- _MeadowEndpoints.endpointAuthorizers.setAuthorizer('Deny', defaultAuthorizer);
548
-
549
- const responseBody = JSON.parse(pResponse.text);
550
- Expect(responseBody.IDAnimal).to.equal(2);
551
- fDone();
552
- }
553
- );
554
- }
555
- );
556
- test
557
- (
558
- 'read: get a specific record with a bad parameter',
559
- function(fDone)
560
- {
561
- libSuperTest('http://localhost:9080/')
562
- .get('1.0/FableTest/')
563
- .end(
564
- function (pError, pResponse)
565
- {
566
- var tmpResult = JSON.parse(pResponse.text);
567
- Expect(tmpResult.Error).to.equal('Error retreiving a record. Record not found');
568
- fDone();
569
- }
570
- );
571
- }
572
- );
573
- test
574
- (
575
- 'reads: get all records',
576
- function(fDone)
577
- {
578
- libSuperTest('http://localhost:9080/')
579
- .get('1.0/FableTests')
580
- .end(
581
- function (pError, pResponse)
582
- {
583
- var tmpResults = JSON.parse(pResponse.text);
584
- Expect(tmpResults.length).to.equal(6);
585
- Expect(tmpResults[0].Type).to.equal('Bunny');
586
- Expect(tmpResults[4].Name).to.equal('Gertrude');
587
- fDone();
588
- }
589
- );
590
- }
591
- );
592
- test
593
- (
594
- 'readsLiteExtended: get all records',
595
- function(fDone)
596
- {
597
- libSuperTest('http://localhost:9080/')
598
- .get('1.0/FableTests/LiteExtended/Type,Name')
599
- .end(
600
- function (pError, pResponse)
601
- {
602
- var tmpResults = JSON.parse(pResponse.text);
603
- Expect(tmpResults.length).to.equal(6);
604
- Expect(tmpResults[0].IDAnimal).to.equal(1);
605
- Expect(tmpResults[4].IDAnimal).to.equal(5);
606
- Expect(tmpResults[4].Type).to.equal('Frog');
607
- fDone();
608
- }
609
- );
610
- }
611
- );
612
- test
613
- (
614
- 'readsby: get all records by Type',
615
- function(fDone)
616
- {
617
- libSuperTest('http://localhost:9080/')
618
- .get('1.0/FableTests/By/Type/Dog')
619
- .end(
620
- function (pError, pResponse)
621
- {
622
- var tmpResults = JSON.parse(pResponse.text);
623
- Expect(tmpResults.length).to.equal(2);
624
- Expect(tmpResults[0].Type).to.equal('Dog');
625
- fDone();
626
- }
627
- );
628
- }
629
- );
630
- test
631
- (
632
- 'readsby: get all records by Type IN LIST',
633
- function(fDone)
634
- {
635
- libSuperTest('http://localhost:9080/')
636
- .get('1.0/FableTests/By/Type/Mammoth%2C%20WithComma,Dog')
637
- .end(
638
- function (pError, pResponse)
639
- {
640
- var tmpResults = JSON.parse(pResponse.text);
641
- Expect(tmpResults.length).to.equal(2);
642
- Expect(tmpResults[0].Type).to.equal('Dog');
643
- fDone();
644
- }
645
- );
646
- }
647
- );
648
- test
649
- (
650
- 'countby: get count of records by Type',
651
- function(fDone)
652
- {
653
- libSuperTest('http://localhost:9080/')
654
- .get('1.0/FableTests/Count/By/Type/Dog')
655
- .end(
656
- function (pError, pResponse)
657
- {
658
- var tmpResults = JSON.parse(pResponse.text);
659
- Expect(tmpResults.Count).to.equal(2);
660
- fDone();
661
- }
662
- );
663
- }
664
- );
665
- test
666
- (
667
- 'countby: get count of records by multiple Types',
668
- function(fDone)
669
- {
670
- libSuperTest('http://localhost:9080/')
671
- .get('1.0/FableTests/Count/By/Type/Dog,Mammoth')
672
- .end(
673
- function (pError, pResponse)
674
- {
675
- var tmpResults = JSON.parse(pResponse.text);
676
- Expect(tmpResults.Count).to.equal(3);
677
- fDone();
678
- }
679
- );
680
- }
681
- );
682
- test
683
- (
684
- 'readsby: get paged records by Type',
685
- function(fDone)
686
- {
687
- libSuperTest('http://localhost:9080/')
688
- .get('1.0/FableTests/By/Type/Dog/1/1')
689
- .end(
690
- function (pError, pResponse)
691
- {
692
- var tmpResults = JSON.parse(pResponse.text);
693
- Expect(tmpResults.length).to.equal(1);
694
- Expect(tmpResults[0].Name).to.equal('Spot');
695
- fDone();
696
- }
697
- );
698
- }
699
- );
700
- test
701
- (
702
- 'readselect: get a page of filtered records by date',
703
- function(fDone)
704
- {
705
- var today = new Date();
706
- today = today.toISOString().substring(0, 10);
707
-
708
- libSuperTest('http://localhost:9080/')
709
- .get(`1.0/FableTestSelect/FilteredTo/FBD~UpdateDate~EQ~${today}/0/1`)
710
- .end(
711
- function (pError, pResponse)
712
- {
713
- console.log(pResponse.text)
714
- var tmpResults = JSON.parse(pResponse.text);
715
- Expect(tmpResults.length).to.equal(1);
716
- Expect(tmpResults[0].Value).to.equal('FableTest #1');
717
- fDone();
718
- }
719
- );
720
- }
721
- );
722
- test
723
- (
724
- 'readselect: get all records',
725
- function(fDone)
726
- {
727
- libSuperTest('http://localhost:9080/')
728
- .get('1.0/FableTestSelect')
729
- .end(
730
- function (pError, pResponse)
731
- {
732
- console.log(pResponse.text)
733
- var tmpResults = JSON.parse(pResponse.text);
734
- Expect(tmpResults.length).to.equal(6);
735
- Expect(tmpResults[4].Value).to.equal('FableTest #5');
736
- fDone();
737
- }
738
- );
739
- }
740
- );
741
- test
742
- (
743
- 'readselect: get a page of records',
744
- function(fDone)
745
- {
746
- libSuperTest('http://localhost:9080/')
747
- .get('1.0/FableTestSelect/2/2')
748
- .end(
749
- function (pError, pResponse)
750
- {
751
- console.log(pResponse.text)
752
- var tmpResults = JSON.parse(pResponse.text);
753
- Expect(tmpResults.length).to.equal(2);
754
- Expect(tmpResults[1].Value).to.equal('FableTest #4');
755
- fDone();
756
- }
757
- );
758
- }
759
- );
760
- test
761
- (
762
- 'readselect: get a page of records',
763
- function(fDone)
764
- {
765
- libSuperTest('http://localhost:9080/')
766
- .get('1.0/FableTestSelect/2/2')
767
- .end(
768
- function (pError, pResponse)
769
- {
770
- console.log(pResponse.text)
771
- var tmpResults = JSON.parse(pResponse.text);
772
- Expect(tmpResults.length).to.equal(2);
773
- Expect(tmpResults[1].Value).to.equal('FableTest #4');
774
- fDone();
775
- }
776
- );
777
- }
778
- );
779
- test
780
- (
781
- 'readselect: get filtered records',
782
- function(fDone)
783
- {
784
- libSuperTest('http://localhost:9080/')
785
- .get('1.0/FableTestSelect/FilteredTo/FBV~Type~EQ~Dog')
786
- .end(
787
- function (pError, pResponse)
788
- {
789
- var tmpResults = JSON.parse(pResponse.text);
790
- Expect(tmpResults.length).to.equal(2);
791
- Expect(tmpResults[0].Value).to.equal('FableTest #3');
792
- fDone();
793
- }
794
- );
795
- }
796
- );
797
- test
798
- (
799
- 'readselect: get a page of filtered records',
800
- function(fDone)
801
- {
802
- libSuperTest('http://localhost:9080/')
803
- .get('1.0/FableTestSelect/FilteredTo/FBV~Type~EQ~Dog/1/1')
804
- .end(
805
- function (pError, pResponse)
806
- {
807
- console.log(pResponse.text)
808
- var tmpResults = JSON.parse(pResponse.text);
809
- Expect(tmpResults.length).to.equal(1);
810
- Expect(tmpResults[0].Value).to.equal('FableTest #4');
811
- fDone();
812
- }
813
- );
814
- }
815
- );
816
- test
817
- (
818
- 'readselect: get an empty page of records',
819
- function(fDone)
820
- {
821
- libSuperTest('http://localhost:9080/')
822
- .get('1.0/FableTestSelect/200/200')
823
- .end(
824
- function (pError, pResponse)
825
- {
826
- console.log(pResponse.text)
827
- var tmpResults = JSON.parse(pResponse.text);
828
- Expect(tmpResults.length).to.equal(0);
829
- fDone();
830
- }
831
- );
832
- }
833
- );
834
- test
835
- (
836
- 'reads: get a page of records',
837
- function(fDone)
838
- {
839
- libSuperTest('http://localhost:9080/')
840
- // Get page 2, 2 records per page.
841
- .get('1.0/FableTests/2/2')
842
- .end(
843
- function (pError, pResponse)
844
- {
845
- var tmpResults = JSON.parse(pResponse.text);
846
- Expect(tmpResults.length).to.equal(2);
847
- Expect(tmpResults[0].Type).to.equal('Dog');
848
- Expect(tmpResults[1].Name).to.equal('Spot');
849
- fDone();
850
- }
851
- );
852
- }
853
- );
854
- test
855
- (
856
- 'reads: get a filtered set of records',
857
- function(fDone)
858
- {
859
- libSuperTest('http://localhost:9080/')
860
- .get('1.0/FableTests/FilteredTo/FBV~Type~EQ~Frog')
861
- .end(
862
- function (pError, pResponse)
863
- {
864
- var tmpResults = JSON.parse(pResponse.text);
865
- Expect(tmpResults.length).to.equal(1);
866
- Expect(tmpResults[0].Type).to.equal('Frog');
867
- fDone();
868
- }
869
- );
870
- }
871
- );
872
- test
873
- (
874
- 'reads: get distinct values for a column',
875
- function(fDone)
876
- {
877
- libSuperTest('http://localhost:9080/')
878
- .get('1.0/FableTests/Distinct/Type')
879
- .end(
880
- function (pError, pResponse)
881
- {
882
- var tmpResults = JSON.parse(pResponse.text);
883
- Expect(tmpResults.length).to.equal(5);
884
- const types = tmpResults.map((r) => r.Type);
885
- Expect(types).to.have.members(['Bunny', 'Girl', 'Dog', 'Frog', 'Mammoth']);
886
- fDone();
887
- }
888
- );
889
- }
890
- );
891
- test
892
- (
893
- 'reads: get distinct values for a column with filter',
894
- function(fDone)
895
- {
896
- libSuperTest('http://localhost:9080/')
897
- .get('1.0/FableTests/Distinct/Type/FilteredTo/FBV~IDAnimal~LT~3')
898
- .end(
899
- function (pError, pResponse)
900
- {
901
- var tmpResults = JSON.parse(pResponse.text);
902
- Expect(tmpResults.length).to.equal(2);
903
- const types = new Set(tmpResults.map((r) => r.Type));
904
- Expect(types.size).to.equal(2);
905
- fDone();
906
- }
907
- );
908
- }
909
- );
910
- test
911
- (
912
- 'reads: get distinct values for a column with filter and pagination',
913
- function(fDone)
914
- {
915
- libSuperTest('http://localhost:9080/')
916
- .get('1.0/FableTests/Distinct/Type/FilteredTo/FBV~IDAnimal~LT~3/0/1')
917
- .end(
918
- function (pError, pResponse)
919
- {
920
- var tmpResults = JSON.parse(pResponse.text);
921
- Expect(tmpResults.length).to.equal(1);
922
- fDone();
923
- }
924
- );
925
- }
926
- );
927
- test
928
- (
929
- 'reads: get distinct values for a column with pagination',
930
- function(fDone)
931
- {
932
- libSuperTest('http://localhost:9080/')
933
- .get('1.0/FableTests/Distinct/Type/2/2')
934
- .end(
935
- function (pError, pResponse)
936
- {
937
- var tmpResults = JSON.parse(pResponse.text);
938
- Expect(tmpResults.length).to.equal(2);
939
- const types = new Set(tmpResults.map((r) => r.Type));
940
- Expect(types.size).to.equal(2);
941
- fDone();
942
- }
943
- );
944
- }
945
- );
946
- test
947
- (
948
- 'reads: get a filtered paged set of records',
949
- function(fDone)
950
- {
951
- libSuperTest('http://localhost:9080/')
952
- // Skip one record, 2 records per page.
953
- .get('1.0/FableTests/FilteredTo/FBV~Type~EQ~Dog/1/2')
954
- .end(
955
- function (pError, pResponse)
956
- {
957
- var tmpResults = JSON.parse(pResponse.text);
958
- Expect(tmpResults.length).to.equal(1);
959
- Expect(tmpResults[0].Type).to.equal('Dog');
960
- fDone();
961
- }
962
- );
963
- }
964
- );
965
- test
966
- (
967
- 'update: update a record',
968
- function(fDone)
969
- {
970
- // Change animal 4 ("Spot") to a Corgi
971
- var tmpRecord = {IDAnimal:4, Type:'Corgi'};
972
- libSuperTest('http://localhost:9080/')
973
- .put('1.0/FableTest')
974
- .send(tmpRecord)
975
- .end(
976
- function(pError, pResponse)
977
- {
978
- // Expect response to be the record we just created.
979
- var tmpResult = JSON.parse(pResponse.text);
980
- Expect(tmpResult.Type).to.equal('Corgi');
981
- Expect(tmpResult.CreatingIDUser).to.equal(1);
982
- Expect(tmpResult.UpdatingIDUser).to.equal(37);
983
- fDone();
984
- }
985
- );
986
- }
987
- );
988
- test
989
- (
990
- 'delete: delete a record',
991
- function(fDone)
992
- {
993
- // Delete animal 3 ("Red")
994
- var tmpRecord = {IDAnimal:3};
995
- libSuperTest('http://localhost:9080/')
996
- .del('1.0/FableTest')
997
- .send(tmpRecord)
998
- .end(
999
- function(pError, pResponse)
1000
- {
1001
- // Expect response to be the count of deleted records.
1002
- var tmpResult = JSON.parse(pResponse.text);
1003
- Expect(tmpResult.Count).to.equal(1);
1004
- fDone();
1005
- }
1006
- );
1007
- }
1008
- );
1009
- test
1010
- (
1011
- 'delete: undelete a record after deleting it',
1012
- function(fDone)
1013
- {
1014
- // Delete animal 4
1015
- var tmpRecord = {IDAnimal:4};
1016
- libSuperTest('http://localhost:9080/')
1017
- .del('1.0/FableTest')
1018
- .send(tmpRecord)
1019
- .end(
1020
- function(pError, pResponse)
1021
- {
1022
- // Expect response to be the count of deleted records.
1023
- var tmpResult = JSON.parse(pResponse.text);
1024
- Expect(tmpResult.Count).to.equal(1);
1025
-
1026
- // Now undelete the record
1027
- libSuperTest('http://localhost:9080/')
1028
- .get('1.0/FableTest/Undelete/4')
1029
- .end(
1030
- function(pError, pResponse)
1031
- {
1032
- // Expect response to be the count of deleted records.
1033
- var tmpResult = JSON.parse(pResponse.text);
1034
- Expect(tmpResult.Count).to.equal(1);
1035
- return fDone();
1036
- }
1037
- );
1038
- }
1039
- );
1040
- }
1041
- );
1042
- test
1043
- (
1044
- 'delete: delete a record with a bad parameter',
1045
- function(fDone)
1046
- {
1047
- // Delete animal 3 ("Red")
1048
- var tmpRecord = {IDAnimal:{MyStuff:4}};
1049
- libSuperTest('http://localhost:9080/')
1050
- .del('1.0/FableTest')
1051
- .send(tmpRecord)
1052
- .end(
1053
- function(pError, pResponse)
1054
- {
1055
- // Expect response to be the count of deleted records.
1056
- var tmpResult = JSON.parse(pResponse.text);
1057
- Expect(tmpResult.Error).to.contain('a valid record ID is required');
1058
- fDone();
1059
- }
1060
- );
1061
- }
1062
- );
1063
- test
1064
- (
1065
- 'count: get the count of records',
1066
- function(fDone)
1067
- {
1068
- libSuperTest('http://localhost:9080/')
1069
- .get('1.0/FableTests/Count')
1070
- .end(
1071
- function (pError, pResponse)
1072
- {
1073
- var tmpResults = JSON.parse(pResponse.text);
1074
- Expect(tmpResults.Count).to.equal(5);
1075
- fDone();
1076
- }
1077
- );
1078
- }
1079
- );
1080
- test
1081
- (
1082
- 'count: get the count of filtered records',
1083
- function(fDone)
1084
- {
1085
- libSuperTest('http://localhost:9080/')
1086
- .get('1.0/FableTests/Count/FilteredTo/FBV~Type~EQ~Girl')
1087
- .end(
1088
- function (pError, pResponse)
1089
- {
1090
- var tmpResults = JSON.parse(pResponse.text);
1091
- Expect(tmpResults.Count).to.equal(1);
1092
- fDone();
1093
- }
1094
- );
1095
- }
1096
- );
1097
- test
1098
- (
1099
- 'schema: get the schema of a record',
1100
- function(fDone)
1101
- {
1102
- libSuperTest('http://localhost:9080/')
1103
- .get('1.0/FableTest/Schema')
1104
- .end(
1105
- function (pError, pResponse)
1106
- {
1107
- var tmpResults = JSON.parse(pResponse.text);
1108
- //console.log('SCHEMA --> '+JSON.stringify(tmpResults, null, 4))
1109
- Expect(tmpResults.title).to.equal('Animal');
1110
- Expect(tmpResults.description).to.contain('creature that lives in');
1111
- fDone();
1112
- }
1113
- );
1114
- }
1115
- );
1116
- test
1117
- (
1118
- 'new: get a new empty record',
1119
- function(fDone)
1120
- {
1121
- libSuperTest('http://localhost:9080/')
1122
- .get('1.0/FableTest/Schema/New')
1123
- .end(
1124
- function (pError, pResponse)
1125
- {
1126
- var tmpResults = JSON.parse(pResponse.text);
1127
- //console.log(JSON.stringify(tmpResults, null, 4))
1128
- Expect(tmpResults.IDAnimal).to.equal(null);
1129
- Expect(tmpResults.Name).to.equal('Unknown');
1130
- Expect(tmpResults.Type).to.equal('Unclassified');
1131
- fDone();
1132
- }
1133
- );
1134
- }
1135
- );
1136
- test
1137
- (
1138
- 'validate: validate an invalid record',
1139
- function(fDone)
1140
- {
1141
- var tmpRecord = {IDAnimal:4, Type:'Corgi'};
1142
- libSuperTest('http://localhost:9080/')
1143
- .post('1.0/FableTest/Schema/Validate')
1144
- .send(tmpRecord)
1145
- .end(
1146
- function(pError, pResponse)
1147
- {
1148
- // Expect response to be the record we just created.
1149
- var tmpResult = JSON.parse(pResponse.text);
1150
- //console.log(JSON.stringify(tmpResult, null, 4))
1151
- Expect(tmpResult.Valid).to.equal(false);
1152
- Expect(tmpResult.Errors[0].field).to.equal('data.Name');
1153
- Expect(tmpResult.Errors[0].message).to.equal('is required');
1154
- fDone();
1155
- }
1156
- );
1157
- }
1158
- );
1159
- test
1160
- (
1161
- 'validate: validate a valid record',
1162
- function(fDone)
1163
- {
1164
- var tmpRecord = {IDAnimal:4, Type:'Corgi', Name:'Doofer', CreatingIDUser:10};
1165
- libSuperTest('http://localhost:9080/')
1166
- .post('1.0/FableTest/Schema/Validate')
1167
- .send(tmpRecord)
1168
- .end(
1169
- function(pError, pResponse)
1170
- {
1171
- // Expect response to be the record we just created.
1172
- var tmpResult = JSON.parse(pResponse.text);
1173
- //console.log(JSON.stringify(tmpResult, null, 4))
1174
- Expect(tmpResult.Valid).to.equal(true);
1175
- fDone();
1176
- }
1177
- );
1178
- }
1179
- );
1180
- test
1181
- (
1182
- 'validate: validate bad data',
1183
- function(fDone)
1184
- {
1185
- var tmpRecord = 'IAMBAD';
1186
- libSuperTest('http://localhost:9080/')
1187
- .post('1.0/FableTest/Schema/Validate')
1188
- .send(tmpRecord)
1189
- .end(
1190
- function(pError, pResponse)
1191
- {
1192
- // Expect response to be the record we just created.
1193
- var tmpResult = JSON.parse(pResponse.text);
1194
- //console.log(JSON.stringify(tmpResult, null, 4))
1195
- Expect(tmpResult.Valid).to.be.false;
1196
- fDone();
1197
- }
1198
- );
1199
- }
1200
- );
1201
- }
1202
- );
1203
- suite
1204
- (
1205
- 'Unauthorized server routes',
1206
- function()
1207
- {
1208
- test
1209
- (
1210
- 'read: get a specific record',
1211
- function(fDone)
1212
- {
1213
- _MockSessionValidUser.UserRoleIndex = -1;
1214
- libSuperTest('http://localhost:9080/')
1215
- .get('1.0/FableTest/2')
1216
- .end(
1217
- function (pError, pResponse)
1218
- {
1219
- var tmpResult = JSON.parse(pResponse.text);
1220
- Expect(tmpResult.Error).to.contain('You must be appropriately authenticated');
1221
- _MockSessionValidUser.UserRoleIndex = 1;
1222
- fDone();
1223
- }
1224
- );
1225
- }
1226
- );
1227
- }
1228
- );
1229
- suite
1230
- (
1231
- 'Bad user server routes',
1232
- function()
1233
- {
1234
- test
1235
- (
1236
- 'create: create a record',
1237
- function(fDone)
1238
- {
1239
- _MockSessionValidUser.UserID = 0;
1240
- var tmpRecord = {Name:'BatBrains', Type:'Mammoth'};
1241
- libSuperTest('http://localhost:9080/')
1242
- .post('1.0/FableTest')
1243
- .send(tmpRecord)
1244
- .end(
1245
- function(pError, pResponse)
1246
- {
1247
- // Expect response to be the record we just created.
1248
- var tmpResult = JSON.parse(pResponse.text);
1249
- Expect(tmpResult.Error).to.contain('authenticated');
1250
- fDone();
1251
- }
1252
- );
1253
- }
1254
- );
1255
- test
1256
- (
1257
- 'read: get a specific record',
1258
- function(fDone)
1259
- {
1260
- libSuperTest('http://localhost:9080/')
1261
- .get('1.0/FableTest/2')
1262
- .end(
1263
- function (pError, pResponse)
1264
- {
1265
- var tmpResult = JSON.parse(pResponse.text);
1266
- Expect(tmpResult.Error).to.contain('authenticated');
1267
- fDone();
1268
- }
1269
- );
1270
- }
1271
- );
1272
- test
1273
- (
1274
- 'readselect: get all records',
1275
- function(fDone)
1276
- {
1277
- libSuperTest('http://localhost:9080/')
1278
- .get('1.0/FableTestSelect')
1279
- .end(
1280
- function (pError, pResponse)
1281
- {
1282
- console.log(pResponse.text)
1283
- var tmpResults = JSON.parse(pResponse.text);
1284
- Expect(tmpResults.Error).to.contain('authenticated');
1285
- fDone();
1286
- }
1287
- );
1288
- }
1289
- );
1290
- test
1291
- (
1292
- 'update: update a record',
1293
- function(fDone)
1294
- {
1295
- // Change animal 4 ("Spot") to a Corgi
1296
- var tmpRecord = {IDAnimal:4, Type:'Corgi'};
1297
- libSuperTest('http://localhost:9080/')
1298
- .put('1.0/FableTest')
1299
- .send(tmpRecord)
1300
- .end(
1301
- function(pError, pResponse)
1302
- {
1303
- // Expect response to be the record we just created.
1304
- var tmpResult = JSON.parse(pResponse.text);
1305
- Expect(tmpResult.Error).to.contain('authenticated');
1306
- fDone();
1307
- }
1308
- );
1309
- }
1310
- );
1311
- test
1312
- (
1313
- 'schema: get the schema of a record',
1314
- function(fDone)
1315
- {
1316
- libSuperTest('http://localhost:9080/')
1317
- .get('1.0/FableTest/Schema')
1318
- .end(
1319
- function (pError, pResponse)
1320
- {
1321
- var tmpResults = JSON.parse(pResponse.text);
1322
- //console.log('SCHEMA --> '+JSON.stringify(tmpResults, null, 4))
1323
- Expect(tmpResults.Error).to.contain('authenticated');
1324
- fDone();
1325
- }
1326
- );
1327
- }
1328
- );
1329
- test
1330
- (
1331
- 'new: get a new empty record',
1332
- function(fDone)
1333
- {
1334
- libSuperTest('http://localhost:9080/')
1335
- .get('1.0/FableTest/Schema/New')
1336
- .end(
1337
- function (pError, pResponse)
1338
- {
1339
- var tmpResults = JSON.parse(pResponse.text);
1340
- //console.log(JSON.stringify(tmpResults, null, 4))
1341
- Expect(tmpResults.Error).to.contain('authenticated');
1342
- fDone();
1343
- }
1344
- );
1345
- }
1346
- );
1347
- test
1348
- (
1349
- 'validate: validate an invalid record',
1350
- function(fDone)
1351
- {
1352
- var tmpRecord = {IDAnimal:4, Type:'Corgi'};
1353
- libSuperTest('http://localhost:9080/')
1354
- .post('1.0/FableTest/Schema/Validate')
1355
- .send(tmpRecord)
1356
- .end(
1357
- function(pError, pResponse)
1358
- {
1359
- // Expect response to be the record we just created.
1360
- var tmpResult = JSON.parse(pResponse.text);
1361
- //console.log(JSON.stringify(tmpResult, null, 4))
1362
- Expect(tmpResult.Error).to.contain('authenticated');
1363
- fDone();
1364
-
1365
- }
1366
- );
1367
- }
1368
- );
1369
- test
1370
- (
1371
- 'count: get the count of records',
1372
- function(fDone)
1373
- {
1374
- libSuperTest('http://localhost:9080/')
1375
- .get('1.0/FableTests/Count')
1376
- .end(
1377
- function (pError, pResponse)
1378
- {
1379
- var tmpResult = JSON.parse(pResponse.text);
1380
- Expect(tmpResult.Error).to.contain('authenticated');
1381
- fDone();
1382
- }
1383
- );
1384
- }
1385
- );
1386
- test
1387
- (
1388
- 'delete: delete a record',
1389
- function(fDone)
1390
- {
1391
- // Delete animal 3 ("Red")
1392
- var tmpRecord = {IDAnimal:3};
1393
- libSuperTest('http://localhost:9080/')
1394
- .del('1.0/FableTest')
1395
- .send(tmpRecord)
1396
- .end(
1397
- function(pError, pResponse)
1398
- {
1399
- // Expect response to be the count of deleted records.
1400
- var tmpResult = JSON.parse(pResponse.text);
1401
- Expect(tmpResult.Error).to.contain('authenticated');
1402
- _MockSessionValidUser.UserID = 10;
1403
- fDone();
1404
- }
1405
- );
1406
- }
1407
- );
1408
- }
1409
- );
1410
- suite
1411
- (
1412
- 'Not logged in server routes',
1413
- function()
1414
- {
1415
- test
1416
- (
1417
- 'read: get a specific record',
1418
- function(fDone)
1419
- {
1420
- _MockSessionValidUser.LoggedIn = false;
1421
- libSuperTest('http://localhost:9080/')
1422
- .get('1.0/FableTest/2')
1423
- .end(
1424
- function (pError, pResponse)
1425
- {
1426
- var tmpResult = JSON.parse(pResponse.text);
1427
- Expect(tmpResult.Error).to.contain('You must be authenticated');
1428
- _MockSessionValidUser.LoggedIn = true;
1429
- fDone();
1430
- }
1431
- );
1432
- }
1433
- );
1434
- }
1435
- );
1436
- suite
1437
- (
1438
- 'Filter parser',
1439
- function()
1440
- {
1441
- test
1442
- (
1443
- 'Filter parse',
1444
- function(fDone)
1445
- {
1446
- var tmpQuery = _MeadowEndpoints.DAL.query;
1447
- _MeadowEndpoints.parseFilter('FBV~UUIDAnimal~EQ~1000000', tmpQuery);
1448
- Expect(tmpQuery.parameters.filter[0].Column).to.equal('UUIDAnimal');
1449
- fDone();
1450
- }
1451
- );
1452
- }
1453
- );
1454
- suite
1455
- (
1456
- 'Changing route requirement',
1457
- function()
1458
- {
1459
- test
1460
- (
1461
- 'read: get a specific record',
1462
- function(fDone)
1463
- {
1464
- Expect(_MeadowEndpoints.endpointAuthorizationLevels.Read).to.equal(0);
1465
- fDone();
1466
- }
1467
- );
1468
- }
1469
- );
1470
- suite
1471
- (
1472
- 'Behavior modifications',
1473
- function()
1474
- {
1475
- test
1476
- (
1477
- 'read: modified get of a specific record',
1478
- function(fDone)
1479
- {
1480
- // Override the query configuration
1481
- _MeadowEndpoints.behaviorModifications.setBehavior('Read-QueryConfiguration', [
1482
- function(pRequest, fComplete)
1483
- {
1484
- //implicitly test behvaior-cascade
1485
- return fComplete(false);
1486
- },
1487
- function(pRequest, fComplete)
1488
- {
1489
- // Turn up logging on the request.
1490
- pRequest.Query.setLogLevel(5);
1491
- fComplete(false);
1492
- } ]);
1493
- libSuperTest('http://localhost:9080/')
1494
- .get('1.0/FableTest/2')
1495
- .end(
1496
- function (pError, pResponse)
1497
- {
1498
- var tmpResult = JSON.parse(pResponse.text);
1499
- //console.log(JSON.stringify(tmpResult, null, 4))
1500
- Expect(tmpResult.Name).to.equal('Red Riding Hood');
1501
- fDone();
1502
- }
1503
- );
1504
- }
1505
- );
1506
- test
1507
- (
1508
- 'read: inject data into the record',
1509
- function(fDone)
1510
- {
1511
- // Override the query configuration
1512
- _MeadowEndpoints.behaviorModifications.setBehavior('Read-PostOperation',
1513
- function(pRequest, fComplete)
1514
- {
1515
- // Create a custom property on the record.
1516
- pRequest.Record.CustomProperty = 'Custom '+pRequest.Record.Type+' ID '+pRequest.Record.IDAnimal;
1517
- fComplete(false);
1518
- });
1519
- _MockSessionValidUser.LoggedIn = true;
1520
- libSuperTest('http://localhost:9080/')
1521
- .get('1.0/FableTest/2')
1522
- .end(
1523
- function (pError, pResponse)
1524
- {
1525
- var tmpResult = JSON.parse(pResponse.text);
1526
- //console.log(JSON.stringify(tmpResult, null, 4))
1527
- Expect(tmpResult.CustomProperty).to.equal('Custom Girl ID 2');
1528
- fDone();
1529
- }
1530
- );
1531
- }
1532
- );
1533
- test
1534
- (
1535
- 'read-max: get the max record ID',
1536
- function(fDone)
1537
- {
1538
- libSuperTest('http://localhost:9080/')
1539
- .get('1.0/FableTest/Max/IDAnimal')
1540
- .end(
1541
- function (pError, pResponse)
1542
- {
1543
- var tmpResult = JSON.parse(pResponse.text);
1544
- Expect(tmpResult.IDAnimal).to.equal(6);
1545
- fDone();
1546
- }
1547
- );
1548
- }
1549
- );
1550
- test
1551
- (
1552
- 'read-max: get the max name',
1553
- function(fDone)
1554
- {
1555
- libSuperTest('http://localhost:9080/')
1556
- .get('1.0/FableTest/Max/Name')
1557
- .end(
1558
- function (pError, pResponse)
1559
- {
1560
- var tmpResult = JSON.parse(pResponse.text);
1561
- Expect(tmpResult.Name).to.equal('Spot');
1562
- fDone();
1563
- }
1564
- );
1565
- }
1566
- );
1567
- }
1568
- );
1569
- suite
1570
- (
1571
- 'Direct invocation',
1572
- function()
1573
- {
1574
- var tmpCreatedRecordGUID;
1575
-
1576
- test
1577
- (
1578
- 'invoke: setup method is called',
1579
- function(fDone)
1580
- {
1581
- _MockSessionValidUser.UserRoleIndex = 2;
1582
- let setupCallCount = 0;
1583
- let passedRequest, passedResponse, passedOriginalRequest;
1584
- _MeadowEndpoints.setInvokeSetupCallback((req, res, origReq) =>
1585
- {
1586
- ++setupCallCount;
1587
- passedRequest = req;
1588
- passedResponse = res;
1589
- passedOriginalRequest = origReq;
1590
- });
1591
- const originalRequest = {UserSession: _MockSessionValidUser};
1592
- _MeadowEndpoints.invokeEndpoint('Read', {IDRecord: 2}, originalRequest,
1593
- function(pError, pResponse)
1594
- {
1595
- Expect(setupCallCount).to.equal(1);
1596
- Expect(passedOriginalRequest).to.equal(originalRequest);
1597
- Expect(passedRequest).to.be.an('object');
1598
- Expect(passedResponse).to.be.an('object');
1599
-
1600
- fDone();
1601
- }
1602
- );
1603
- }
1604
- );
1605
- test
1606
- (
1607
- 'invoke create: create a record',
1608
- function(fDone)
1609
- {
1610
- var tmpRecord = {Name:'BatBrains', Type:'Mammoth'};
1611
- _MockSessionValidUser.UserRoleIndex = 2;
1612
- _MeadowEndpoints.invokeEndpoint('Create', tmpRecord, {UserSession: _MockSessionValidUser},
1613
- function(pError, pResponse)
1614
- {
1615
- // Expect response to be the record we just created.
1616
- Expect(pResponse.body.Name)
1617
- .to.equal(tmpRecord.Name);
1618
-
1619
- tmpCreatedRecordGUID = pResponse.body.GUIDAnimal;
1620
-
1621
- fDone();
1622
- }
1623
- );
1624
- }
1625
- );
1626
- test
1627
- (
1628
- 'invoke create: create a record with a bad record passed in',
1629
- function(fDone)
1630
- {
1631
- var tmpRecord = ' ';
1632
- _MockSessionValidUser.UserRoleIndex = 2;
1633
- _MeadowEndpoints.invokeEndpoint('Create', tmpRecord,
1634
- function(pError, pResponse)
1635
- {
1636
- // Expect response to be the record we just created.
1637
- var tmpResult = JSON.parse(pResponse.text);
1638
- Expect(tmpResult.Error).to.contain('a valid record is required');
1639
- fDone();
1640
- }
1641
- );
1642
- }
1643
- );
1644
- test
1645
- (
1646
- 'invoke read: get a specific record',
1647
- function(fDone)
1648
- {
1649
- _MeadowEndpoints.invokeEndpoint('Read', {IDRecord: 2}, {UserSession: _MockSessionValidUser},
1650
- function (pError, pResponse)
1651
- {
1652
- var tmpResult = JSON.parse(pResponse.text);
1653
- Expect(tmpResult.Type).to.equal('Girl');
1654
- fDone();
1655
- }
1656
- );
1657
- }
1658
- );
1659
- test
1660
- (
1661
- 'invoke read: get a specific record by GUID',
1662
- function(fDone)
1663
- {
1664
- _MeadowEndpoints.invokeEndpoint('Read', {GUIDRecord: tmpCreatedRecordGUID}, {UserSession: _MockSessionValidUser},
1665
- function (pError, pResponse)
1666
- {
1667
- var tmpResult = JSON.parse(pResponse.text);
1668
- Expect(tmpResult.Type).to.equal('Mammoth');
1669
- fDone();
1670
- }
1671
- );
1672
- }
1673
- );
1674
- test
1675
- (
1676
- 'read: get a specific record with a bad parameter',
1677
- function(fDone)
1678
- {
1679
- _MeadowEndpoints.invokeEndpoint('Read', {},
1680
- function (pError, pResponse)
1681
- {
1682
- var tmpResult = JSON.parse(pResponse.text);
1683
- //console.log(tmpResult);
1684
- Expect(tmpResult.Error).to.be.an('undefined'); //
1685
- fDone();
1686
- }
1687
- );
1688
- }
1689
- );
1690
- test
1691
- (
1692
- 'invoke readselect: get all records',
1693
- function(fDone)
1694
- {
1695
- _MeadowEndpoints.invokeEndpoint('ReadSelectList', {}, {UserSession: _MockSessionValidUser},
1696
- function (pError, pResponse)
1697
- {
1698
- console.log(pResponse.body)
1699
- Expect(pResponse.body)
1700
- .to.be.an('array');
1701
- //var tmpResults = JSON.parse(pResponse.text);
1702
- //Expect(tmpResults.Error).to.contain('authenticated');
1703
- fDone();
1704
- }
1705
- );
1706
- }
1707
- );
1708
- test
1709
- (
1710
- 'invoke readsby: get all records by Type',
1711
- function(fDone)
1712
- {
1713
- _MeadowEndpoints.invokeEndpoint('ReadsBy', {ByField: 'Type', ByValue: 'Mammoth'}, {UserSession: _MockSessionValidUser},
1714
- function (pError, pResponse)
1715
- {
1716
- //console.log(pResponse.body);
1717
-
1718
- var tmpResults = pResponse.body; //JSON.parse(pResponse.text);
1719
- Expect(tmpResults.length).to.equal(2);
1720
- Expect(tmpResults[0].Type).to.equal('Mammoth');
1721
- fDone();
1722
- }
1723
- );
1724
- }
1725
- );
1726
- test
1727
- (
1728
- 'invoke readsby: get all records by Type IN LIST',
1729
- function(fDone)
1730
- {
1731
- _MeadowEndpoints.invokeEndpoint('ReadsBy', {ByField: 'Type', ByValue: ['Mammoth', 'Dog']}, {UserSession: _MockSessionValidUser},
1732
- function (pError, pResponse)
1733
- {
1734
- //console.log(pResponse.body);
1735
-
1736
- var tmpResults = pResponse.body; //JSON.parse(pResponse.text);
1737
- Expect(tmpResults.length).to.equal(2);
1738
- Expect(tmpResults[0].Type).to.equal('Mammoth');
1739
- fDone();
1740
- }
1741
- );
1742
- }
1743
- );
1744
- test
1745
- (
1746
- 'invoke readsby: get all records by Type AND Name',
1747
- function(fDone)
1748
- {
1749
- _MeadowEndpoints.invokeEndpoint('ReadsBy', {Filters: [
1750
- {ByField: 'Type', ByValue: 'Mammoth'},
1751
- {ByField: 'Name', ByValue: 'BatBrains'}
1752
- ]}, {UserSession: _MockSessionValidUser},
1753
- function (pError, pResponse)
1754
- {
1755
- //console.log(pResponse.body);
1756
-
1757
- var tmpResults = pResponse.body; //JSON.parse(pResponse.text);
1758
- Expect(tmpResults.length).to.equal(2);
1759
- Expect(tmpResults[0].Type).to.equal('Mammoth');
1760
- fDone();
1761
- }
1762
- );
1763
- }
1764
- );
1765
- test
1766
- (
1767
- 'invoke countby: get cout of records by Type',
1768
- function(fDone)
1769
- {
1770
- _MeadowEndpoints.invokeEndpoint('CountBy', {ByField: 'Type', ByValue: 'Mammoth'}, {UserSession: _MockSessionValidUser},
1771
- function (pError, pResponse)
1772
- {
1773
- var tmpResults = pResponse.body; //JSON.parse(pResponse.text);
1774
- Expect(tmpResults.Count).to.equal(2);
1775
- fDone();
1776
- }
1777
- );
1778
- }
1779
- );
1780
- test
1781
- (
1782
- 'invoke readsby: get paged records by Type',
1783
- function(fDone)
1784
- {
1785
- _MeadowEndpoints.invokeEndpoint('ReadsBy', {ByField: 'Type', ByValue: 'Mammoth', Begin: 1, Cap: 1}, {UserSession: _MockSessionValidUser},
1786
- function (pError, pResponse)
1787
- {
1788
- var tmpResults = pResponse.body;
1789
- Expect(tmpResults.length).to.equal(1);
1790
- Expect(tmpResults[0].Type).to.equal('Mammoth');
1791
- fDone();
1792
- }
1793
- );
1794
- }
1795
- );
1796
- test
1797
- (
1798
- 'invoke readselect: get a page of records',
1799
- function(fDone)
1800
- {
1801
- _MeadowEndpoints.invokeEndpoint('ReadSelectList', {Begin: 2, Cap: 2}, {UserSession: _MockSessionValidUser},
1802
- function (pError, pResponse)
1803
- {
1804
- var tmpResults = pResponse.Records; //JSON.parse(pResponse.text);
1805
- Expect(tmpResults.length).to.equal(2);
1806
- Expect(tmpResults[1].Value).to.equal('FableTest #5');
1807
- fDone();
1808
- }
1809
- );
1810
- }
1811
- );
1812
- test
1813
- (
1814
- 'invoke readselect: get an empty page of records',
1815
- function(fDone)
1816
- {
1817
- _MeadowEndpoints.invokeEndpoint('ReadSelectList', {Begin: 200, Cap: 200}, {UserSession: _MockSessionValidUser},
1818
- function (pError, pResponse)
1819
- {
1820
- var tmpResults = pResponse.Records; //JSON.parse(pResponse.text);
1821
- Expect(tmpResults.length).to.equal(0);
1822
- fDone();
1823
- }
1824
- );
1825
- }
1826
- );
1827
- test
1828
- (
1829
- 'invoke reads: get a page of records',
1830
- function(fDone)
1831
- {
1832
- _MeadowEndpoints.invokeEndpoint('Reads', {Begin: 2, Cap: 2}, {UserSession: _MockSessionValidUser},
1833
- function (pError, pResponse)
1834
- {
1835
- var tmpResults = pResponse.Records; //JSON.parse(pResponse.text);
1836
- Expect(tmpResults.length).to.equal(2);
1837
- Expect(tmpResults[0].Type).to.equal('Corgi');
1838
- Expect(tmpResults[1].Name).to.equal('Gertrude');
1839
- fDone();
1840
- }
1841
- );
1842
- }
1843
- );
1844
- test
1845
- (
1846
- 'invoke update: update a record',
1847
- function(fDone)
1848
- {
1849
- // Change animal 4 ("Spot") to a Corgi
1850
- var tmpRecord = {IDAnimal:4, Type:'Corgi'};
1851
- _MeadowEndpoints.invokeEndpoint('Update', tmpRecord, {UserSession: _MockSessionValidUser},
1852
- function(pError, pResponse)
1853
- {
1854
- // Expect response to be the record we just created.
1855
- var tmpResult = pResponse.Record; //JSON.parse(pResponse.text);
1856
- Expect(tmpResult.Type).to.equal('Corgi');
1857
- Expect(tmpResult.CreatingIDUser).to.equal(1);
1858
- Expect(tmpResult.UpdatingIDUser).to.equal(_MockSessionValidUser.UserID);
1859
- fDone();
1860
- }
1861
- );
1862
- }
1863
- );
1864
- test
1865
- (
1866
- 'invoke delete: delete a record',
1867
- function(fDone)
1868
- {
1869
- // Delete animal 4 ("Corgi")
1870
- var tmpRecord = {IDAnimal:4};
1871
-
1872
- // Override the query configuration
1873
- _MeadowEndpoints.behaviorModifications.setBehavior('Delete-PreOperation',
1874
- function(pRequest, fComplete)
1875
- {
1876
- // Create a custom property on the record.
1877
- Expect(pRequest.Record.IDAnimal).to.equal(tmpRecord.IDAnimal);
1878
- return fComplete(false);
1879
- });
1880
-
1881
- _MeadowEndpoints.invokeEndpoint('Delete', tmpRecord, {UserSession: _MockSessionValidUser},
1882
- function(pError, pResponse)
1883
- {
1884
- //clear out the behavior mapping to not affect other tests
1885
- _MeadowEndpoints.behaviorModifications.setBehavior('Delete-PreOperation', null);
1886
-
1887
- // Expect response to be the count of deleted records.
1888
- var tmpResult = pResponse.body; //JSON.parse(pResponse.text);
1889
- Expect(tmpResult.Count).to.equal(1);
1890
- return fDone();
1891
- }
1892
- );
1893
- }
1894
- );
1895
- test
1896
- (
1897
- 'invoke delete: delete a record with a bad parameter',
1898
- function(fDone)
1899
- {
1900
- // Delete animal 3 ("Red")
1901
- var tmpRecord = {IDAnimal:{MyStuff:4}};
1902
- _MeadowEndpoints.invokeEndpoint('Delete', tmpRecord, {UserSession: _MockSessionValidUser},
1903
- function(pError, pResponse)
1904
- {
1905
- // Expect response to be the count of deleted records.
1906
- var tmpResult = pResponse.body; //JSON.parse(pResponse.text);
1907
- Expect(tmpResult.Error).to.contain('a valid record ID is required');
1908
- fDone();
1909
- }
1910
- );
1911
- }
1912
- );
1913
- test
1914
- (
1915
- 'count: get the count of records',
1916
- function(fDone)
1917
- {
1918
- _MeadowEndpoints.invokeEndpoint('Count', {}, {UserSession: _MockSessionValidUser},
1919
- function (pError, pResponse)
1920
- {
1921
- var tmpResults = pResponse.body; //JSON.parse(pResponse.text);
1922
- Expect(tmpResults.Count).to.equal(5);
1923
- fDone();
1924
- }
1925
- );
1926
- }
1927
- );
1928
- test
1929
- (
1930
- 'schema: get the schema of a record',
1931
- function(fDone)
1932
- {
1933
- _MeadowEndpoints.invokeEndpoint('Schema', {},
1934
- function (pError, pResponse)
1935
- {
1936
- var tmpResults = pResponse.body; //JSON.parse(pResponse.text);
1937
- //console.log('SCHEMA --> '+JSON.stringify(tmpResults, null, 4))
1938
- Expect(tmpResults.title).to.equal('Animal');
1939
- Expect(tmpResults.description).to.contain('creature that lives in');
1940
- fDone();
1941
- }
1942
- );
1943
- }
1944
- );
1945
- test
1946
- (
1947
- 'new: get a new empty record',
1948
- function(fDone)
1949
- {
1950
- _MeadowEndpoints.invokeEndpoint('New', {}, {UserSession: _MockSessionValidUser},
1951
- function (pError, pResponse)
1952
- {
1953
- var tmpResults = pResponse.body; //JSON.parse(pResponse.text);
1954
- //console.log(JSON.stringify(tmpResults, null, 4))
1955
- Expect(tmpResults.IDAnimal).to.equal(null);
1956
- Expect(tmpResults.Name).to.equal('Unknown');
1957
- Expect(tmpResults.Type).to.equal('Unclassified');
1958
- fDone();
1959
- }
1960
- );
1961
- }
1962
- );
1963
- test
1964
- (
1965
- 'validate: validate an invalid record',
1966
- function(fDone)
1967
- {
1968
- var tmpRecord = {IDAnimal:4, Type:'Corgi'};
1969
- _MeadowEndpoints.invokeEndpoint('Validate', tmpRecord, {UserSession: _MockSessionValidUser},
1970
- function(pError, pResponse)
1971
- {
1972
- // Expect response to be the record we just created.
1973
- var tmpResult = pResponse.body; //JSON.parse(pResponse.text);
1974
- //console.log(JSON.stringify(tmpResult, null, 4))
1975
- Expect(tmpResult.Valid).to.equal(false);
1976
- Expect(tmpResult.Errors[0].field).to.equal('data.Name');
1977
- Expect(tmpResult.Errors[0].message).to.equal('is required');
1978
- fDone();
1979
- }
1980
- );
1981
- }
1982
- );
1983
- test
1984
- (
1985
- 'validate: validate a valid record',
1986
- function(fDone)
1987
- {
1988
- var tmpRecord = {IDAnimal:4, Type:'Corgi', Name:'Doofer', CreatingIDUser:10};
1989
- _MeadowEndpoints.invokeEndpoint('Validate', tmpRecord, {UserSession: _MockSessionValidUser},
1990
- function(pError, pResponse)
1991
- {
1992
- // Expect response to be the record we just created.
1993
- var tmpResult = pResponse.body; //JSON.parse(pResponse.text);
1994
- //console.log(JSON.stringify(tmpResult, null, 4))
1995
- Expect(tmpResult.Valid).to.equal(true);
1996
- fDone();
1997
- }
1998
- );
1999
- }
2000
- );
2001
- test
2002
- (
2003
- 'validate: validate bad data',
2004
- function(fDone)
2005
- {
2006
- var tmpRecord = 'IAMBAD';
2007
- _MeadowEndpoints.invokeEndpoint('Validate', tmpRecord, {UserSession: _MockSessionValidUser},
2008
- function(pError, pResponse)
2009
- {
2010
- // Expect response to be the record we just created.
2011
- var tmpResult = pResponse.body; //JSON.parse(pResponse.text);
2012
- //console.log(JSON.stringify(tmpResult, null, 4))
2013
- Expect(tmpResult.Error).to.contain('validate failure');
2014
- fDone();
2015
- }
2016
- );
2017
- }
2018
- );
2019
- }
2020
- );
2021
-
2022
- suite
2023
- (
2024
- 'Endpoint Security - Deny',
2025
- function()
2026
- {
2027
- test
2028
- (
2029
- 'invoke read: get a specific record',
2030
- function(fDone)
2031
- {
2032
- _MockSessionValidUser.LoggedIn = true;
2033
- _MockSessionValidUser.UserRoleIndex = 5; //set it to an undefined role, so the DefaultAPISecurity definitions of 'Deny' get used.
2034
-
2035
- _MeadowEndpoints.invokeEndpoint('Read', {IDRecord: 2}, {UserSession: _MockSessionValidUser},
2036
- function (pError, pResponse)
2037
- {
2038
- Expect(pResponse.body.ErrorCode).to.equal(405);
2039
- Expect(pResponse.body.Error).to.equal('UNAUTHORIZED ACCESS IS NOT ALLOWED');
2040
- return fDone();
2041
- }
2042
- );
2043
- }
2044
- );
2045
- test
2046
- (
2047
- 'invoke create: create a record',
2048
- function(fDone)
2049
- {
2050
- var tmpRecord = {Name:'BatBrains', Type:'Mammoth'};
2051
- _MeadowEndpoints.invokeEndpoint('Create', tmpRecord, {UserSession: _MockSessionValidUser},
2052
- function(pError, pResponse)
2053
- {
2054
- Expect(pResponse.body.ErrorCode).to.equal(405);
2055
- Expect(pResponse.body.Error).to.equal('UNAUTHORIZED ACCESS IS NOT ALLOWED');
2056
-
2057
- return fDone();
2058
- }
2059
- );
2060
- }
2061
- );
2062
- test
2063
- (
2064
- 'invoke create: create a record with a bad record passed in',
2065
- function(fDone)
2066
- {
2067
- var tmpRecord = ' ';
2068
- _MeadowEndpoints.invokeEndpoint('Create', tmpRecord, {UserSession: _MockSessionValidUser},
2069
- function(pError, pResponse)
2070
- {
2071
- // Expect response to be the record we just created.
2072
- var tmpResult = JSON.parse(pResponse.text);
2073
- Expect(tmpResult.Error).to.contain('a valid record is required');
2074
- fDone();
2075
- }
2076
- );
2077
- }
2078
- );
2079
- test
2080
- (
2081
- 'invoke readselect: get all records',
2082
- function(fDone)
2083
- {
2084
- _MeadowEndpoints.invokeEndpoint('ReadSelectList', {}, {UserSession: _MockSessionValidUser},
2085
- function (pError, pResponse)
2086
- {
2087
- Expect(pResponse.body.ErrorCode).to.equal(405);
2088
- Expect(pResponse.body.Error).to.equal('UNAUTHORIZED ACCESS IS NOT ALLOWED');
2089
-
2090
- fDone();
2091
- }
2092
- );
2093
- }
2094
- );
2095
- test
2096
- (
2097
- 'invoke readsby: get all records by Type',
2098
- function(fDone)
2099
- {
2100
- _MeadowEndpoints.invokeEndpoint('ReadsBy', {ByField: 'Type', ByValue: 'Mammoth'}, {UserSession: _MockSessionValidUser},
2101
- function (pError, pResponse)
2102
- {
2103
- Expect(pResponse.body.ErrorCode).to.equal(405);
2104
- Expect(pResponse.body.Error).to.equal('UNAUTHORIZED ACCESS IS NOT ALLOWED');
2105
- fDone();
2106
- }
2107
- );
2108
- }
2109
- );
2110
- test
2111
- (
2112
- 'invoke readsby: get all records by Type IN LIST',
2113
- function(fDone)
2114
- {
2115
- _MeadowEndpoints.invokeEndpoint('ReadsBy', {ByField: 'Type', ByValue: ['Mammoth', 'Dog']}, {UserSession: _MockSessionValidUser},
2116
- function (pError, pResponse)
2117
- {
2118
- Expect(pResponse.body.ErrorCode).to.equal(405);
2119
- Expect(pResponse.body.Error).to.equal('UNAUTHORIZED ACCESS IS NOT ALLOWED');
2120
- fDone();
2121
- }
2122
- );
2123
- }
2124
- );
2125
- test
2126
- (
2127
- 'invoke countby: get cout of records by Type',
2128
- function(fDone)
2129
- {
2130
- _MeadowEndpoints.invokeEndpoint('CountBy', {ByField: 'Type', ByValue: 'Mammoth'}, {UserSession: _MockSessionValidUser},
2131
- function (pError, pResponse)
2132
- {
2133
- Expect(pResponse.body.ErrorCode).to.equal(405);
2134
- Expect(pResponse.body.Error).to.equal('UNAUTHORIZED ACCESS IS NOT ALLOWED');
2135
- fDone();
2136
- }
2137
- );
2138
- }
2139
- );
2140
- test
2141
- (
2142
- 'invoke countby: get cout of records by Type',
2143
- function(fDone)
2144
- {
2145
- _MeadowEndpoints.invokeEndpoint('Count', {}, {UserSession: _MockSessionValidUser},
2146
- function (pError, pResponse)
2147
- {
2148
- Expect(pResponse.body.ErrorCode).to.equal(405);
2149
- Expect(pResponse.body.Error).to.equal('UNAUTHORIZED ACCESS IS NOT ALLOWED');
2150
- fDone();
2151
- }
2152
- );
2153
- }
2154
- );
2155
- test
2156
- (
2157
- 'invoke readselect: get a page of records',
2158
- function(fDone)
2159
- {
2160
- _MeadowEndpoints.invokeEndpoint('ReadSelectList', {Begin: 2, Cap: 2}, {UserSession: _MockSessionValidUser},
2161
- function (pError, pResponse)
2162
- {
2163
- Expect(pResponse.body.ErrorCode).to.equal(405);
2164
- Expect(pResponse.body.Error).to.equal('UNAUTHORIZED ACCESS IS NOT ALLOWED');
2165
- fDone();
2166
- }
2167
- );
2168
- }
2169
- );
2170
- test
2171
- (
2172
- 'invoke readselect: get an empty page of records',
2173
- function(fDone)
2174
- {
2175
- _MeadowEndpoints.invokeEndpoint('ReadSelectList', {Begin: 200, Cap: 200}, {UserSession: _MockSessionValidUser},
2176
- function (pError, pResponse)
2177
- {
2178
- // Because no records were returned, it should show as Authorized
2179
-
2180
- var tmpResults = pResponse.Records; //JSON.parse(pResponse.text);
2181
- Expect(tmpResults.length).to.equal(0);
2182
- fDone();
2183
- }
2184
- );
2185
- }
2186
- );
2187
- test
2188
- (
2189
- 'invoke reads: get a page of records',
2190
- function(fDone)
2191
- {
2192
- _MeadowEndpoints.invokeEndpoint('Reads', {Begin: 2, Cap: 2}, {UserSession: _MockSessionValidUser},
2193
- function (pError, pResponse)
2194
- {
2195
- Expect(pResponse.body.ErrorCode).to.equal(405);
2196
- Expect(pResponse.body.Error).to.equal('UNAUTHORIZED ACCESS IS NOT ALLOWED');
2197
-
2198
- fDone();
2199
- }
2200
- );
2201
- }
2202
- );
2203
- test
2204
- (
2205
- 'invoke update: update a record',
2206
- function(fDone)
2207
- {
2208
- // Change animal 1
2209
- var tmpRecord = {IDAnimal:1, Type:'Corgi'};
2210
- _MeadowEndpoints.invokeEndpoint('Update', tmpRecord, {UserSession: _MockSessionValidUser},
2211
- function(pError, pResponse)
2212
- {
2213
- Expect(pResponse.body.ErrorCode).to.equal(405);
2214
- Expect(pResponse.body.Error).to.equal('UNAUTHORIZED ACCESS IS NOT ALLOWED');
2215
-
2216
- fDone();
2217
- }
2218
- );
2219
- }
2220
- );
2221
- test
2222
- (
2223
- 'invoke update: update a record, override security to authorize the request',
2224
- function(fDone)
2225
- {
2226
- // Change animal 1
2227
- var tmpRecord = {IDAnimal:1, Type:'Corgi'};
2228
- _MeadowEndpoints.invokeEndpoint('Update', tmpRecord, {UserSession: _MockSessionValidUser, Satchel: {AuthorizeOverride: true}},
2229
- function(pError, pResponse)
2230
- {
2231
- // Expect response to be the record we just updated.
2232
- var tmpResult = pResponse.Record; //JSON.parse(pResponse.text);
2233
- Expect(tmpResult.Type).to.equal('Corgi');
107
+ Expect(tmpResult.Title).to.equal('Batman is Batman');
2234
108
  Expect(tmpResult.CreatingIDUser).to.equal(1);
2235
- Expect(tmpResult.UpdatingIDUser).to.equal(_MockSessionValidUser.UserID);
2236
-
2237
- fDone();
2238
- }
2239
- );
2240
- }
2241
- );
2242
- test
2243
- (
2244
- 'invoke delete: delete a record',
2245
- function(fDone)
2246
- {
2247
- // Delete animal 1
2248
- var tmpRecord = {IDAnimal:1};
2249
- _MeadowEndpoints.invokeEndpoint('Delete', tmpRecord, {UserSession: _MockSessionValidUser},
2250
- function(pError, pResponse)
2251
- {
2252
- Expect(pResponse.body.ErrorCode).to.equal(405);
2253
- Expect(pResponse.body.Error).to.equal('UNAUTHORIZED ACCESS IS NOT ALLOWED');
2254
-
2255
- fDone();
2256
- }
2257
- );
2258
- }
2259
- );
2260
- test
2261
- (
2262
- 'bulk creates',
2263
- function(fDone)
2264
- {
2265
- var tmpRecords = [
2266
- {Name:'Billy', Type:'Cat'},
2267
- {Name:'Jim', Type:'Cat'},
2268
- {Name:'Janet', Type:'Cat'},
2269
- {Name:'Sweeps', Type:'Cat'},
2270
- {Name:'Stakes', Type:'Dog'},
2271
- {Name:'Sally', Type:'Dog'},
2272
- {Name:'Bill', Type:'Dog'},
2273
- {Name:'Chris', Type:'Dog'},
2274
- {Name:'Haji', Type:'Snake'}
2275
- ];
2276
- _MockSessionValidUser.UserRoleIndex = 2;
2277
- libSuperTest('http://localhost:9080/')
2278
- .post('1.0/FableTests')
2279
- .send(tmpRecords)
2280
- .end(
2281
- function(pError, pResponse)
2282
- {
2283
- // Expect response to be the record we just created.
2284
- var tmpResult = JSON.parse(pResponse.text);
2285
- //console.log(JSON.stringify(tmpResult,null,4));
2286
- Expect(tmpResult[0].Name).to.equal('Billy');
2287
- Expect(tmpResult[5].Type).to.equal('Dog');
2288
- fDone();
2289
- }
2290
- );
2291
- }
2292
- );
2293
- test
2294
- (
2295
- 'bulk create with a bad record',
2296
- function(fDone)
2297
- {
2298
- var tmpRecords = [
2299
- {Name:'Astro', Type:'Cartoon'},
2300
- {Name:'Boy', Type:'Cartoon'},
2301
- {License:'Whoops', Type:'Cat'},
2302
- {Name:'Froggy', Type:'Cartoon'}
2303
- ];
2304
- _MockSessionValidUser.UserRoleIndex = 2;
2305
- libSuperTest('http://localhost:9080/')
2306
- .post('1.0/FableTests')
2307
- .send(tmpRecords)
2308
- .end(
2309
- function(pError, pResponse)
2310
- {
2311
- // Expect response to be the record we just created.
2312
- var tmpResult = JSON.parse(pResponse.text);
2313
- Expect(tmpResult[0].Type).to.equal('Cartoon');
2314
- fDone();
2315
- }
2316
- );
2317
- }
2318
- );
2319
- test
2320
- (
2321
- 'bulk updates',
2322
- function(fDone)
2323
- {
2324
- var tmpRecords = [
2325
- {IDAnimal: 11, Type:'Hoss'},
2326
- {IDAnimal: 12, Type:'Hoss'},
2327
- {IDAnimal: 14, Type:'Hoss'},
2328
- {IDAnimal: 15, Type:'Hoss'}
2329
- ];
2330
- _MockSessionValidUser.UserRoleIndex = 2;
2331
- libSuperTest('http://localhost:9080/')
2332
- .put('1.0/FableTests')
2333
- .send(tmpRecords)
2334
- .end(
2335
- function(pError, pResponse)
2336
- {
2337
- // Expect response to be the record we just created.
2338
- var tmpResult = JSON.parse(pResponse.text);
2339
- //console.log(JSON.stringify(tmpResult,null,4));
2340
- Expect(tmpResult[0].IDAnimal).to.equal(11);
2341
- Expect(tmpResult[0].Type).to.equal('Hoss');
2342
- Expect(tmpResult[1].Type).to.equal('Hoss');
2343
- Expect(tmpResult[2].Type).to.equal('Hoss');
2344
- Expect(tmpResult[3].Type).to.equal('Hoss');
2345
- fDone();
2346
- }
2347
- );
2348
- }
2349
- );
2350
- test
2351
- (
2352
- 'bulk updates with bad record',
2353
- function(fDone)
2354
- {
2355
- var tmpRecords = [
2356
- {IDAnimal: 11, Type:'Horsse'},
2357
- {IDAnimal: 12, Type:'Horsse'},
2358
- {IDAnimal: 14, Genus:'Hosse'},
2359
- {IDAnimal: 15, Type:'Hosses'}
2360
- ];
2361
- _MockSessionValidUser.UserRoleIndex = 2;
2362
- libSuperTest('http://localhost:9080/')
2363
- .put('1.0/FableTests')
2364
- .send(tmpRecords)
2365
- .end(
2366
- function(pError, pResponse)
2367
- {
2368
- // Expect response to be the record we just created.
2369
- var tmpResult = JSON.parse(pResponse.text);
2370
- //console.log(JSON.stringify(tmpResult,null,4));
2371
- Expect(tmpResult[3].Type).to.equal('Hosses');
2372
- fDone();
2373
- }
2374
- );
2375
- }
2376
- );
2377
- test
2378
- (
2379
- 'invoke readlite: get all records',
2380
- function(fDone)
2381
- {
2382
- _MeadowEndpoints.invokeEndpoint('ReadLiteList', {}, {UserSession: _MockSessionValidUser},
2383
- function (pError, pResponse)
2384
- {
2385
- //console.log(pResponse.body)
2386
- Expect(pResponse.body)
2387
- .to.be.an('array');
2388
- //var tmpResults = JSON.parse(pResponse.text);
2389
- //Expect(tmpResults.Error).to.contain('authenticated');
2390
- fDone();
2391
- }
2392
- );
2393
- }
2394
- );
2395
- test
2396
- (
2397
- 'upsert: create a record',
2398
- function(fDone)
2399
- {
2400
- var tmpRecord = {GUIDAnimal:'0xHAXXXX', Name:'Jason', Type:'Tyranosaurus'};
2401
- _MockSessionValidUser.UserRoleIndex = 2;
2402
- libSuperTest('http://localhost:9080/')
2403
- .put('1.0/FableTest/Upsert')
2404
- .send(tmpRecord)
2405
- .end(
2406
- function(pError, pResponse)
2407
- {
2408
- // Expect response to be the record we just created.
2409
- //console.log(pResponse.text)
2410
- var tmpResult = JSON.parse(pResponse.text);
2411
- Expect(tmpResult.Type).to.equal('Tyranosaurus');
2412
- Expect(tmpResult.CreatingIDUser).to.equal(10);
2413
- fDone();
2414
- }
2415
- );
2416
- }
2417
- );
2418
- test
2419
- (
2420
- 'upsert: Update a record',
2421
- function(fDone)
2422
- {
2423
- var tmpRecord = {GUIDAnimal:'0xHAXXXX', Type:'Stegosaurus'};
2424
- _MockSessionValidUser.UserRoleIndex = 2;
2425
- libSuperTest('http://localhost:9080/')
2426
- .put('1.0/FableTest/Upsert')
2427
- .send(tmpRecord)
2428
- .end(
2429
- function(pError, pResponse)
2430
- {
2431
- // Expect response to be the record we just created.
2432
- console.log(pResponse.text)
2433
- var tmpResult = JSON.parse(pResponse.text);
2434
- Expect(tmpResult.Type).to.equal('Stegosaurus');
2435
- Expect(tmpResult.Name).to.equal('Jason');
2436
- fDone();
2437
- }
2438
- );
2439
- }
2440
- );
2441
- test
2442
- (
2443
- 'bulk upserts',
2444
- function(fDone)
2445
- {
2446
- _MeadowEndpoints.behaviorModifications.setTemplate('SelectList', '<%= Record.Name %>|<%=Record.Type%>');
2447
- var tmpRecords = [
2448
- {GUIDAnimal:'0xHAXXXX', Type:'Triceratops'},
2449
- {GUIDAnimal:'0xDavison', Name:'Davison', Type:'Dog'},
2450
- {GUIDAnimal:'0xMartino', Name:'Martin', Type:'Dog'},
2451
- {Name:'Chino', Type:'Cat'}
2452
- ];
2453
- _MockSessionValidUser.UserRoleIndex = 2;
2454
- libSuperTest('http://localhost:9080/')
2455
- .put('1.0/FableTest/Upserts')
2456
- .send(tmpRecords)
2457
- .end(
2458
- function(pError, pResponse)
2459
- {
2460
- // Expect response to be the record we just created.
2461
- var tmpResult = JSON.parse(pResponse.text);
2462
- console.log(JSON.stringify(tmpResult,null,4));
2463
- Expect(tmpResult[0].Value).to.equal('Jason|Triceratops');
2464
- Expect(tmpResult[1].Value).to.equal('Davison|Dog');
2465
- Expect(tmpResult[2].Value).to.equal('Martin|Dog');
2466
- Expect(tmpResult[3].Value).to.equal('Chino|Cat');
2467
109
  fDone();
2468
110
  }
2469
111
  );
@@ -2472,4 +114,4 @@ suite
2472
114
  }
2473
115
  );
2474
116
  }
2475
- );
117
+ );