meadow-endpoints 3.0.6 → 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.
- package/{Dockerfile → Dockerfile_LUXURYCode} +43 -1
- package/README.md +48 -14
- package/debug/Animal.json +62 -0
- package/debug/Harness-Configuration.json +31 -0
- package/debug/Harness.js +7 -108
- package/debug/KillHarness.sh +10 -0
- package/dist/meadowendpoints.js +4402 -0
- package/dist/meadowendpoints.min.js +92 -0
- package/dist/meadowendpoints.min.js.map +1 -0
- package/gulpfile.js +83 -0
- package/package.json +29 -16
- package/source/Meadow-Endpoints-Browser-Shim.js +14 -0
- package/source/Meadow-Endpoints.js +176 -562
- package/source/controller/Meadow-Endpoints-Controller-Base.js +161 -0
- package/source/controller/components/Meadow-Endpoints-Controller-BehaviorInjection.js +125 -0
- package/source/controller/components/Meadow-Endpoints-Controller-Error-StatusCodes.txt +189 -0
- package/source/controller/components/Meadow-Endpoints-Controller-Error.js +118 -0
- package/source/controller/components/Meadow-Endpoints-Controller-Log.js +103 -0
- package/source/controller/utility/Meadow-Endpoints-Filter-Parser.js +225 -0
- package/source/controller/utility/Meadow-Endpoints-Session-Marshaler.js +48 -0
- package/source/controller/utility/Meadow-Endpoints-Stream-RecordArray.js +66 -0
- package/source/endpoints/count/Meadow-Endpoint-Count.js +49 -0
- package/source/endpoints/count/Meadow-Endpoint-CountBy.js +40 -0
- package/source/endpoints/create/Meadow-Endpoint-BulkCreate.js +53 -0
- package/source/endpoints/create/Meadow-Endpoint-Create.js +58 -0
- package/source/endpoints/create/Meadow-Operation-Create.js +83 -0
- package/source/endpoints/delete/Meadow-Endpoint-Delete.js +93 -0
- package/source/endpoints/delete/Meadow-Endpoint-Undelete.js +108 -0
- package/source/endpoints/read/Meadow-Endpoint-Read.js +72 -0
- package/source/endpoints/read/Meadow-Endpoint-ReadDistinctList.js +92 -0
- package/source/endpoints/read/Meadow-Endpoint-ReadLiteList.js +85 -0
- package/source/endpoints/read/Meadow-Endpoint-ReadMax.js +55 -0
- package/source/endpoints/read/Meadow-Endpoint-ReadSelectList.js +89 -0
- package/source/endpoints/read/Meadow-Endpoint-Reads.js +75 -0
- package/source/endpoints/read/Meadow-Endpoint-ReadsBy.js +100 -0
- package/source/{crud → endpoints/read}/Meadow-Marshal-DistinctList.js +4 -13
- package/source/{crud → endpoints/read}/Meadow-Marshal-LiteList.js +5 -14
- package/source/endpoints/schema/Meadow-Endpoint-New.js +36 -0
- package/source/endpoints/schema/Meadow-Endpoint-Schema.js +36 -0
- package/source/endpoints/schema/Meadow-Endpoint-Validate.js +41 -0
- package/source/endpoints/update/Meadow-Endpoint-BulkUpdate.js +50 -0
- package/source/endpoints/update/Meadow-Endpoint-Update.js +58 -0
- package/source/endpoints/update/Meadow-Operation-Update.js +115 -0
- package/source/endpoints/upsert/Meadow-Endpoint-BulkUpsert.js +52 -0
- package/source/endpoints/upsert/Meadow-Endpoint-Upsert.js +57 -0
- package/source/endpoints/upsert/Meadow-Operation-Upsert.js +137 -0
- package/test/MeadowEndpoints_basic_tests.js +50 -2375
- package/test_support/bookstore-api-endpoint-exercises.paw +0 -0
- package/test_support/bookstore-configuration.json +28 -0
- package/test_support/bookstore-import-books-run.js +1 -0
- package/test_support/bookstore-import-books.js +215 -0
- package/test_support/bookstore-serve-meadow-endpoint-apis-IPC.js +138 -0
- package/test_support/bookstore-serve-meadow-endpoint-apis-run.js +6 -0
- package/test_support/bookstore-serve-meadow-endpoint-apis.js +129 -0
- package/test_support/data/books.csv +10001 -0
- package/test_support/model/ddl/BookStore.ddl +66 -0
- package/test_support/model/generated_diagram/README.md +1 -0
- package/test_support/model/generated_diagram/Stricture_Output.dot +13 -0
- package/test_support/model/generated_diagram/Stricture_Output.png +0 -0
- package/test_support/model/generated_documentation/Dictionary.md +18 -0
- package/test_support/model/generated_documentation/Model-Author.md +20 -0
- package/test_support/model/generated_documentation/Model-Book.md +26 -0
- package/test_support/model/generated_documentation/Model-BookAuthorJoin.md +14 -0
- package/test_support/model/generated_documentation/Model-BookPrice.md +25 -0
- package/test_support/model/generated_documentation/Model-Review.md +22 -0
- package/test_support/model/generated_documentation/ModelChangeTracking.md +17 -0
- package/test_support/model/generated_documentation/README.md +1 -0
- package/test_support/model/manual_scripts/DropTables.sql +5 -0
- package/test_support/model/manual_scripts/README.md +2 -0
- package/test_support/model/sql_create/BookStore-CreateDatabase.mysql.sql +116 -0
- package/test_support/model/sql_create/README.md +1 -0
- package/test_support/test_old/Tests.js +3243 -0
- package/test_support/test_old/untitled.js +88 -0
- package/source/Meadow-Authenticator.js +0 -31
- package/source/Meadow-Authorizers.js +0 -214
- package/source/Meadow-BehaviorModifications.js +0 -170
- package/source/Meadow-CommonServices.js +0 -206
- package/source/Meadow-MarshallSessionData.js +0 -64
- package/source/Restify-RouteParser.js +0 -114
- package/source/authorizers/Meadow-Authorizer-Allow.js +0 -17
- package/source/authorizers/Meadow-Authorizer-Deny.js +0 -17
- package/source/authorizers/Meadow-Authorizer-Mine.js +0 -47
- package/source/authorizers/Meadow-Authorizer-MyCustomer.js +0 -48
- package/source/crud/Meadow-Endpoint-BulkCreate.js +0 -67
- package/source/crud/Meadow-Endpoint-BulkUpdate.js +0 -74
- package/source/crud/Meadow-Endpoint-BulkUpsert.js +0 -76
- package/source/crud/Meadow-Endpoint-Count.js +0 -93
- package/source/crud/Meadow-Endpoint-CountBy.js +0 -101
- package/source/crud/Meadow-Endpoint-Create.js +0 -77
- package/source/crud/Meadow-Endpoint-Delete.js +0 -139
- package/source/crud/Meadow-Endpoint-Read.js +0 -109
- package/source/crud/Meadow-Endpoint-ReadDistinctList.js +0 -146
- package/source/crud/Meadow-Endpoint-ReadLiteList.js +0 -139
- package/source/crud/Meadow-Endpoint-ReadMax.js +0 -86
- package/source/crud/Meadow-Endpoint-ReadSelectList.js +0 -145
- package/source/crud/Meadow-Endpoint-Reads.js +0 -129
- package/source/crud/Meadow-Endpoint-ReadsBy.js +0 -155
- package/source/crud/Meadow-Endpoint-Update.js +0 -80
- package/source/crud/Meadow-Endpoint-Upsert.js +0 -78
- package/source/crud/Meadow-Operation-Create.js +0 -105
- package/source/crud/Meadow-Operation-Update.js +0 -145
- package/source/crud/Meadow-Operation-Upsert.js +0 -106
- package/source/crud/Meadow-StreamRecordArray.js +0 -45
- package/source/schema/Meadow-Endpoint-New.js +0 -37
- package/source/schema/Meadow-Endpoint-Schema.js +0 -37
- package/source/schema/Meadow-Endpoint-Validate.js +0 -43
- package/test/Animal.json +0 -140
- package/test/MeadowEndpoints_disabledAuth_tests.js +0 -1325
- package/test/MeadowEndpoints_trustedSession_tests.js +0 -1731
- package/test/load/artillery-low.yml +0 -10
- package/test/load/cloud9setup.sh +0 -25
- package/test/load/package.json +0 -19
- package/test/load/test-schema-initializedatabase.sql +0 -29
- package/test/load/test-schema.json +0 -119
- package/test/load/test-server.js +0 -157
- package/test/scripts/InitializeDatabase-C9.sql +0 -7
- /package/{test/schemas → test_support/model}/json_schema/BookStore-Extended.json +0 -0
- /package/{test/schemas → test_support/model}/json_schema/BookStore-PICT.json +0 -0
- /package/{test/schemas → test_support/model}/json_schema/BookStore.json +0 -0
- /package/{test/schemas → test_support/model}/json_schema/README.md +0 -0
- /package/{test/schemas → test_support/model}/meadow_schema/BookStore-MeadowSchema-Author.json +0 -0
- /package/{test/schemas → test_support/model}/meadow_schema/BookStore-MeadowSchema-Book.json +0 -0
- /package/{test/schemas → test_support/model}/meadow_schema/BookStore-MeadowSchema-BookAuthorJoin.json +0 -0
- /package/{test/schemas → test_support/model}/meadow_schema/BookStore-MeadowSchema-BookPrice.json +0 -0
- /package/{test/schemas → test_support/model}/meadow_schema/BookStore-MeadowSchema-Review.json +0 -0
- /package/{test/schemas → test_support/model}/meadow_schema/README.md +0 -0
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Unit tests for
|
|
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
|
-
|
|
13
|
+
const libAsync = require('async');
|
|
14
14
|
|
|
15
|
-
|
|
16
|
-
|
|
15
|
+
const libBookServer = require('../test_support/bookstore-serve-meadow-endpoint-apis.js');
|
|
16
|
+
let _BookServer = false;
|
|
17
17
|
|
|
18
|
-
|
|
19
|
-
{
|
|
20
|
-
Product: 'MockOratorAlternate',
|
|
21
|
-
ProductVersion: '0.0.0',
|
|
18
|
+
let _INITIALIZATION_COMPLETE = false;
|
|
22
19
|
|
|
23
|
-
|
|
20
|
+
const libMeadowEndpoints = require('../source/Meadow-Endpoints.js');
|
|
24
21
|
|
|
25
|
-
|
|
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
|
-
|
|
26
|
+
'Meadow-Endpoints-Core',
|
|
27
|
+
() =>
|
|
98
28
|
{
|
|
99
|
-
|
|
100
|
-
var _SpooledUp = false;
|
|
101
|
-
var _Orator;
|
|
102
|
-
|
|
103
|
-
var getAnimalInsert = function(pName, pType)
|
|
29
|
+
suiteSetup ((fSetupComplete) =>
|
|
104
30
|
{
|
|
105
|
-
|
|
106
|
-
};
|
|
107
|
-
|
|
108
|
-
setup
|
|
109
|
-
(
|
|
110
|
-
function(fDone)
|
|
31
|
+
if (!_INITIALIZATION_COMPLETE)
|
|
111
32
|
{
|
|
112
|
-
//
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
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
|
-
|
|
213
|
-
|
|
45
|
+
console.log('Setup complete!')
|
|
46
|
+
_INITIALIZATION_COMPLETE = true;
|
|
47
|
+
return fSetupComplete(pError);
|
|
48
|
+
});
|
|
214
49
|
}
|
|
215
|
-
);
|
|
50
|
+
});
|
|
216
51
|
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
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
|
-
|
|
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
|
-
'
|
|
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
|
-
|
|
340
|
-
|
|
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
|
-
'
|
|
78
|
+
'read: get a specific record',
|
|
391
79
|
function(fDone)
|
|
392
80
|
{
|
|
393
|
-
|
|
394
|
-
|
|
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.
|
|
404
|
-
Expect(tmpResult.CreatingIDUser).to.equal(37);
|
|
87
|
+
Expect(tmpResult.Title).to.equal('The Hunger Games');
|
|
405
88
|
fDone();
|
|
406
89
|
}
|
|
407
90
|
);
|
|
@@ -412,2025 +95,17 @@ suite
|
|
|
412
95
|
'create: create a record',
|
|
413
96
|
function(fDone)
|
|
414
97
|
{
|
|
415
|
-
var tmpRecord = {
|
|
416
|
-
|
|
417
|
-
|
|
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.
|
|
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: delete a record with a bad parameter',
|
|
1012
|
-
function(fDone)
|
|
1013
|
-
{
|
|
1014
|
-
// Delete animal 3 ("Red")
|
|
1015
|
-
var tmpRecord = {IDAnimal:{MyStuff: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.Error).to.contain('a valid record ID is required');
|
|
1025
|
-
fDone();
|
|
1026
|
-
}
|
|
1027
|
-
);
|
|
1028
|
-
}
|
|
1029
|
-
);
|
|
1030
|
-
test
|
|
1031
|
-
(
|
|
1032
|
-
'count: get the count of records',
|
|
1033
|
-
function(fDone)
|
|
1034
|
-
{
|
|
1035
|
-
libSuperTest('http://localhost:9080/')
|
|
1036
|
-
.get('1.0/FableTests/Count')
|
|
1037
|
-
.end(
|
|
1038
|
-
function (pError, pResponse)
|
|
1039
|
-
{
|
|
1040
|
-
var tmpResults = JSON.parse(pResponse.text);
|
|
1041
|
-
Expect(tmpResults.Count).to.equal(5);
|
|
1042
|
-
fDone();
|
|
1043
|
-
}
|
|
1044
|
-
);
|
|
1045
|
-
}
|
|
1046
|
-
);
|
|
1047
|
-
test
|
|
1048
|
-
(
|
|
1049
|
-
'count: get the count of filtered records',
|
|
1050
|
-
function(fDone)
|
|
1051
|
-
{
|
|
1052
|
-
libSuperTest('http://localhost:9080/')
|
|
1053
|
-
.get('1.0/FableTests/Count/FilteredTo/FBV~Type~EQ~Girl')
|
|
1054
|
-
.end(
|
|
1055
|
-
function (pError, pResponse)
|
|
1056
|
-
{
|
|
1057
|
-
var tmpResults = JSON.parse(pResponse.text);
|
|
1058
|
-
Expect(tmpResults.Count).to.equal(1);
|
|
1059
|
-
fDone();
|
|
1060
|
-
}
|
|
1061
|
-
);
|
|
1062
|
-
}
|
|
1063
|
-
);
|
|
1064
|
-
test
|
|
1065
|
-
(
|
|
1066
|
-
'schema: get the schema of a record',
|
|
1067
|
-
function(fDone)
|
|
1068
|
-
{
|
|
1069
|
-
libSuperTest('http://localhost:9080/')
|
|
1070
|
-
.get('1.0/FableTest/Schema')
|
|
1071
|
-
.end(
|
|
1072
|
-
function (pError, pResponse)
|
|
1073
|
-
{
|
|
1074
|
-
var tmpResults = JSON.parse(pResponse.text);
|
|
1075
|
-
//console.log('SCHEMA --> '+JSON.stringify(tmpResults, null, 4))
|
|
1076
|
-
Expect(tmpResults.title).to.equal('Animal');
|
|
1077
|
-
Expect(tmpResults.description).to.contain('creature that lives in');
|
|
1078
|
-
fDone();
|
|
1079
|
-
}
|
|
1080
|
-
);
|
|
1081
|
-
}
|
|
1082
|
-
);
|
|
1083
|
-
test
|
|
1084
|
-
(
|
|
1085
|
-
'new: get a new empty record',
|
|
1086
|
-
function(fDone)
|
|
1087
|
-
{
|
|
1088
|
-
libSuperTest('http://localhost:9080/')
|
|
1089
|
-
.get('1.0/FableTest/Schema/New')
|
|
1090
|
-
.end(
|
|
1091
|
-
function (pError, pResponse)
|
|
1092
|
-
{
|
|
1093
|
-
var tmpResults = JSON.parse(pResponse.text);
|
|
1094
|
-
//console.log(JSON.stringify(tmpResults, null, 4))
|
|
1095
|
-
Expect(tmpResults.IDAnimal).to.equal(null);
|
|
1096
|
-
Expect(tmpResults.Name).to.equal('Unknown');
|
|
1097
|
-
Expect(tmpResults.Type).to.equal('Unclassified');
|
|
1098
|
-
fDone();
|
|
1099
|
-
}
|
|
1100
|
-
);
|
|
1101
|
-
}
|
|
1102
|
-
);
|
|
1103
|
-
test
|
|
1104
|
-
(
|
|
1105
|
-
'validate: validate an invalid record',
|
|
1106
|
-
function(fDone)
|
|
1107
|
-
{
|
|
1108
|
-
var tmpRecord = {IDAnimal:4, Type:'Corgi'};
|
|
1109
|
-
libSuperTest('http://localhost:9080/')
|
|
1110
|
-
.post('1.0/FableTest/Schema/Validate')
|
|
1111
|
-
.send(tmpRecord)
|
|
1112
|
-
.end(
|
|
1113
|
-
function(pError, pResponse)
|
|
1114
|
-
{
|
|
1115
|
-
// Expect response to be the record we just created.
|
|
1116
|
-
var tmpResult = JSON.parse(pResponse.text);
|
|
1117
|
-
//console.log(JSON.stringify(tmpResult, null, 4))
|
|
1118
|
-
Expect(tmpResult.Valid).to.equal(false);
|
|
1119
|
-
Expect(tmpResult.Errors[0].field).to.equal('data.Name');
|
|
1120
|
-
Expect(tmpResult.Errors[0].message).to.equal('is required');
|
|
1121
|
-
fDone();
|
|
1122
|
-
}
|
|
1123
|
-
);
|
|
1124
|
-
}
|
|
1125
|
-
);
|
|
1126
|
-
test
|
|
1127
|
-
(
|
|
1128
|
-
'validate: validate a valid record',
|
|
1129
|
-
function(fDone)
|
|
1130
|
-
{
|
|
1131
|
-
var tmpRecord = {IDAnimal:4, Type:'Corgi', Name:'Doofer', CreatingIDUser:10};
|
|
1132
|
-
libSuperTest('http://localhost:9080/')
|
|
1133
|
-
.post('1.0/FableTest/Schema/Validate')
|
|
1134
|
-
.send(tmpRecord)
|
|
1135
|
-
.end(
|
|
1136
|
-
function(pError, pResponse)
|
|
1137
|
-
{
|
|
1138
|
-
// Expect response to be the record we just created.
|
|
1139
|
-
var tmpResult = JSON.parse(pResponse.text);
|
|
1140
|
-
//console.log(JSON.stringify(tmpResult, null, 4))
|
|
1141
|
-
Expect(tmpResult.Valid).to.equal(true);
|
|
1142
|
-
fDone();
|
|
1143
|
-
}
|
|
1144
|
-
);
|
|
1145
|
-
}
|
|
1146
|
-
);
|
|
1147
|
-
test
|
|
1148
|
-
(
|
|
1149
|
-
'validate: validate bad data',
|
|
1150
|
-
function(fDone)
|
|
1151
|
-
{
|
|
1152
|
-
var tmpRecord = 'IAMBAD';
|
|
1153
|
-
libSuperTest('http://localhost:9080/')
|
|
1154
|
-
.post('1.0/FableTest/Schema/Validate')
|
|
1155
|
-
.send(tmpRecord)
|
|
1156
|
-
.end(
|
|
1157
|
-
function(pError, pResponse)
|
|
1158
|
-
{
|
|
1159
|
-
// Expect response to be the record we just created.
|
|
1160
|
-
var tmpResult = JSON.parse(pResponse.text);
|
|
1161
|
-
//console.log(JSON.stringify(tmpResult, null, 4))
|
|
1162
|
-
Expect(tmpResult.Valid).to.be.false;
|
|
1163
|
-
fDone();
|
|
1164
|
-
}
|
|
1165
|
-
);
|
|
1166
|
-
}
|
|
1167
|
-
);
|
|
1168
|
-
}
|
|
1169
|
-
);
|
|
1170
|
-
suite
|
|
1171
|
-
(
|
|
1172
|
-
'Unauthorized server routes',
|
|
1173
|
-
function()
|
|
1174
|
-
{
|
|
1175
|
-
test
|
|
1176
|
-
(
|
|
1177
|
-
'read: get a specific record',
|
|
1178
|
-
function(fDone)
|
|
1179
|
-
{
|
|
1180
|
-
_MockSessionValidUser.UserRoleIndex = -1;
|
|
1181
|
-
libSuperTest('http://localhost:9080/')
|
|
1182
|
-
.get('1.0/FableTest/2')
|
|
1183
|
-
.end(
|
|
1184
|
-
function (pError, pResponse)
|
|
1185
|
-
{
|
|
1186
|
-
var tmpResult = JSON.parse(pResponse.text);
|
|
1187
|
-
Expect(tmpResult.Error).to.contain('You must be appropriately authenticated');
|
|
1188
|
-
_MockSessionValidUser.UserRoleIndex = 1;
|
|
1189
|
-
fDone();
|
|
1190
|
-
}
|
|
1191
|
-
);
|
|
1192
|
-
}
|
|
1193
|
-
);
|
|
1194
|
-
}
|
|
1195
|
-
);
|
|
1196
|
-
suite
|
|
1197
|
-
(
|
|
1198
|
-
'Bad user server routes',
|
|
1199
|
-
function()
|
|
1200
|
-
{
|
|
1201
|
-
test
|
|
1202
|
-
(
|
|
1203
|
-
'create: create a record',
|
|
1204
|
-
function(fDone)
|
|
1205
|
-
{
|
|
1206
|
-
_MockSessionValidUser.UserID = 0;
|
|
1207
|
-
var tmpRecord = {Name:'BatBrains', Type:'Mammoth'};
|
|
1208
|
-
libSuperTest('http://localhost:9080/')
|
|
1209
|
-
.post('1.0/FableTest')
|
|
1210
|
-
.send(tmpRecord)
|
|
1211
|
-
.end(
|
|
1212
|
-
function(pError, pResponse)
|
|
1213
|
-
{
|
|
1214
|
-
// Expect response to be the record we just created.
|
|
1215
|
-
var tmpResult = JSON.parse(pResponse.text);
|
|
1216
|
-
Expect(tmpResult.Error).to.contain('authenticated');
|
|
1217
|
-
fDone();
|
|
1218
|
-
}
|
|
1219
|
-
);
|
|
1220
|
-
}
|
|
1221
|
-
);
|
|
1222
|
-
test
|
|
1223
|
-
(
|
|
1224
|
-
'read: get a specific record',
|
|
1225
|
-
function(fDone)
|
|
1226
|
-
{
|
|
1227
|
-
libSuperTest('http://localhost:9080/')
|
|
1228
|
-
.get('1.0/FableTest/2')
|
|
1229
|
-
.end(
|
|
1230
|
-
function (pError, pResponse)
|
|
1231
|
-
{
|
|
1232
|
-
var tmpResult = JSON.parse(pResponse.text);
|
|
1233
|
-
Expect(tmpResult.Error).to.contain('authenticated');
|
|
1234
|
-
fDone();
|
|
1235
|
-
}
|
|
1236
|
-
);
|
|
1237
|
-
}
|
|
1238
|
-
);
|
|
1239
|
-
test
|
|
1240
|
-
(
|
|
1241
|
-
'readselect: get all records',
|
|
1242
|
-
function(fDone)
|
|
1243
|
-
{
|
|
1244
|
-
libSuperTest('http://localhost:9080/')
|
|
1245
|
-
.get('1.0/FableTestSelect')
|
|
1246
|
-
.end(
|
|
1247
|
-
function (pError, pResponse)
|
|
1248
|
-
{
|
|
1249
|
-
console.log(pResponse.text)
|
|
1250
|
-
var tmpResults = JSON.parse(pResponse.text);
|
|
1251
|
-
Expect(tmpResults.Error).to.contain('authenticated');
|
|
1252
|
-
fDone();
|
|
1253
|
-
}
|
|
1254
|
-
);
|
|
1255
|
-
}
|
|
1256
|
-
);
|
|
1257
|
-
test
|
|
1258
|
-
(
|
|
1259
|
-
'update: update a record',
|
|
1260
|
-
function(fDone)
|
|
1261
|
-
{
|
|
1262
|
-
// Change animal 4 ("Spot") to a Corgi
|
|
1263
|
-
var tmpRecord = {IDAnimal:4, Type:'Corgi'};
|
|
1264
|
-
libSuperTest('http://localhost:9080/')
|
|
1265
|
-
.put('1.0/FableTest')
|
|
1266
|
-
.send(tmpRecord)
|
|
1267
|
-
.end(
|
|
1268
|
-
function(pError, pResponse)
|
|
1269
|
-
{
|
|
1270
|
-
// Expect response to be the record we just created.
|
|
1271
|
-
var tmpResult = JSON.parse(pResponse.text);
|
|
1272
|
-
Expect(tmpResult.Error).to.contain('authenticated');
|
|
1273
|
-
fDone();
|
|
1274
|
-
}
|
|
1275
|
-
);
|
|
1276
|
-
}
|
|
1277
|
-
);
|
|
1278
|
-
test
|
|
1279
|
-
(
|
|
1280
|
-
'schema: get the schema of a record',
|
|
1281
|
-
function(fDone)
|
|
1282
|
-
{
|
|
1283
|
-
libSuperTest('http://localhost:9080/')
|
|
1284
|
-
.get('1.0/FableTest/Schema')
|
|
1285
|
-
.end(
|
|
1286
|
-
function (pError, pResponse)
|
|
1287
|
-
{
|
|
1288
|
-
var tmpResults = JSON.parse(pResponse.text);
|
|
1289
|
-
//console.log('SCHEMA --> '+JSON.stringify(tmpResults, null, 4))
|
|
1290
|
-
Expect(tmpResults.Error).to.contain('authenticated');
|
|
1291
|
-
fDone();
|
|
1292
|
-
}
|
|
1293
|
-
);
|
|
1294
|
-
}
|
|
1295
|
-
);
|
|
1296
|
-
test
|
|
1297
|
-
(
|
|
1298
|
-
'new: get a new empty record',
|
|
1299
|
-
function(fDone)
|
|
1300
|
-
{
|
|
1301
|
-
libSuperTest('http://localhost:9080/')
|
|
1302
|
-
.get('1.0/FableTest/Schema/New')
|
|
1303
|
-
.end(
|
|
1304
|
-
function (pError, pResponse)
|
|
1305
|
-
{
|
|
1306
|
-
var tmpResults = JSON.parse(pResponse.text);
|
|
1307
|
-
//console.log(JSON.stringify(tmpResults, null, 4))
|
|
1308
|
-
Expect(tmpResults.Error).to.contain('authenticated');
|
|
1309
|
-
fDone();
|
|
1310
|
-
}
|
|
1311
|
-
);
|
|
1312
|
-
}
|
|
1313
|
-
);
|
|
1314
|
-
test
|
|
1315
|
-
(
|
|
1316
|
-
'validate: validate an invalid record',
|
|
1317
|
-
function(fDone)
|
|
1318
|
-
{
|
|
1319
|
-
var tmpRecord = {IDAnimal:4, Type:'Corgi'};
|
|
1320
|
-
libSuperTest('http://localhost:9080/')
|
|
1321
|
-
.post('1.0/FableTest/Schema/Validate')
|
|
1322
|
-
.send(tmpRecord)
|
|
1323
|
-
.end(
|
|
1324
|
-
function(pError, pResponse)
|
|
1325
|
-
{
|
|
1326
|
-
// Expect response to be the record we just created.
|
|
1327
|
-
var tmpResult = JSON.parse(pResponse.text);
|
|
1328
|
-
//console.log(JSON.stringify(tmpResult, null, 4))
|
|
1329
|
-
Expect(tmpResult.Error).to.contain('authenticated');
|
|
1330
|
-
fDone();
|
|
1331
|
-
|
|
1332
|
-
}
|
|
1333
|
-
);
|
|
1334
|
-
}
|
|
1335
|
-
);
|
|
1336
|
-
test
|
|
1337
|
-
(
|
|
1338
|
-
'count: get the count of records',
|
|
1339
|
-
function(fDone)
|
|
1340
|
-
{
|
|
1341
|
-
libSuperTest('http://localhost:9080/')
|
|
1342
|
-
.get('1.0/FableTests/Count')
|
|
1343
|
-
.end(
|
|
1344
|
-
function (pError, pResponse)
|
|
1345
|
-
{
|
|
1346
|
-
var tmpResult = JSON.parse(pResponse.text);
|
|
1347
|
-
Expect(tmpResult.Error).to.contain('authenticated');
|
|
1348
|
-
fDone();
|
|
1349
|
-
}
|
|
1350
|
-
);
|
|
1351
|
-
}
|
|
1352
|
-
);
|
|
1353
|
-
test
|
|
1354
|
-
(
|
|
1355
|
-
'delete: delete a record',
|
|
1356
|
-
function(fDone)
|
|
1357
|
-
{
|
|
1358
|
-
// Delete animal 3 ("Red")
|
|
1359
|
-
var tmpRecord = {IDAnimal:3};
|
|
1360
|
-
libSuperTest('http://localhost:9080/')
|
|
1361
|
-
.del('1.0/FableTest')
|
|
1362
|
-
.send(tmpRecord)
|
|
1363
|
-
.end(
|
|
1364
|
-
function(pError, pResponse)
|
|
1365
|
-
{
|
|
1366
|
-
// Expect response to be the count of deleted records.
|
|
1367
|
-
var tmpResult = JSON.parse(pResponse.text);
|
|
1368
|
-
Expect(tmpResult.Error).to.contain('authenticated');
|
|
1369
|
-
_MockSessionValidUser.UserID = 10;
|
|
1370
|
-
fDone();
|
|
1371
|
-
}
|
|
1372
|
-
);
|
|
1373
|
-
}
|
|
1374
|
-
);
|
|
1375
|
-
}
|
|
1376
|
-
);
|
|
1377
|
-
suite
|
|
1378
|
-
(
|
|
1379
|
-
'Not logged in server routes',
|
|
1380
|
-
function()
|
|
1381
|
-
{
|
|
1382
|
-
test
|
|
1383
|
-
(
|
|
1384
|
-
'read: get a specific record',
|
|
1385
|
-
function(fDone)
|
|
1386
|
-
{
|
|
1387
|
-
_MockSessionValidUser.LoggedIn = false;
|
|
1388
|
-
libSuperTest('http://localhost:9080/')
|
|
1389
|
-
.get('1.0/FableTest/2')
|
|
1390
|
-
.end(
|
|
1391
|
-
function (pError, pResponse)
|
|
1392
|
-
{
|
|
1393
|
-
var tmpResult = JSON.parse(pResponse.text);
|
|
1394
|
-
Expect(tmpResult.Error).to.contain('You must be authenticated');
|
|
1395
|
-
_MockSessionValidUser.LoggedIn = true;
|
|
1396
|
-
fDone();
|
|
1397
|
-
}
|
|
1398
|
-
);
|
|
1399
|
-
}
|
|
1400
|
-
);
|
|
1401
|
-
}
|
|
1402
|
-
);
|
|
1403
|
-
suite
|
|
1404
|
-
(
|
|
1405
|
-
'Filter parser',
|
|
1406
|
-
function()
|
|
1407
|
-
{
|
|
1408
|
-
test
|
|
1409
|
-
(
|
|
1410
|
-
'Filter parse',
|
|
1411
|
-
function(fDone)
|
|
1412
|
-
{
|
|
1413
|
-
var tmpQuery = _MeadowEndpoints.DAL.query;
|
|
1414
|
-
_MeadowEndpoints.parseFilter('FBV~UUIDAnimal~EQ~1000000', tmpQuery);
|
|
1415
|
-
Expect(tmpQuery.parameters.filter[0].Column).to.equal('UUIDAnimal');
|
|
1416
|
-
fDone();
|
|
1417
|
-
}
|
|
1418
|
-
);
|
|
1419
|
-
}
|
|
1420
|
-
);
|
|
1421
|
-
suite
|
|
1422
|
-
(
|
|
1423
|
-
'Changing route requirement',
|
|
1424
|
-
function()
|
|
1425
|
-
{
|
|
1426
|
-
test
|
|
1427
|
-
(
|
|
1428
|
-
'read: get a specific record',
|
|
1429
|
-
function(fDone)
|
|
1430
|
-
{
|
|
1431
|
-
Expect(_MeadowEndpoints.endpointAuthorizationLevels.Read).to.equal(0);
|
|
1432
|
-
fDone();
|
|
1433
|
-
}
|
|
1434
|
-
);
|
|
1435
|
-
}
|
|
1436
|
-
);
|
|
1437
|
-
suite
|
|
1438
|
-
(
|
|
1439
|
-
'Behavior modifications',
|
|
1440
|
-
function()
|
|
1441
|
-
{
|
|
1442
|
-
test
|
|
1443
|
-
(
|
|
1444
|
-
'read: modified get of a specific record',
|
|
1445
|
-
function(fDone)
|
|
1446
|
-
{
|
|
1447
|
-
// Override the query configuration
|
|
1448
|
-
_MeadowEndpoints.behaviorModifications.setBehavior('Read-QueryConfiguration', [
|
|
1449
|
-
function(pRequest, fComplete)
|
|
1450
|
-
{
|
|
1451
|
-
//implicitly test behvaior-cascade
|
|
1452
|
-
return fComplete(false);
|
|
1453
|
-
},
|
|
1454
|
-
function(pRequest, fComplete)
|
|
1455
|
-
{
|
|
1456
|
-
// Turn up logging on the request.
|
|
1457
|
-
pRequest.Query.setLogLevel(5);
|
|
1458
|
-
fComplete(false);
|
|
1459
|
-
} ]);
|
|
1460
|
-
libSuperTest('http://localhost:9080/')
|
|
1461
|
-
.get('1.0/FableTest/2')
|
|
1462
|
-
.end(
|
|
1463
|
-
function (pError, pResponse)
|
|
1464
|
-
{
|
|
1465
|
-
var tmpResult = JSON.parse(pResponse.text);
|
|
1466
|
-
//console.log(JSON.stringify(tmpResult, null, 4))
|
|
1467
|
-
Expect(tmpResult.Name).to.equal('Red Riding Hood');
|
|
1468
|
-
fDone();
|
|
1469
|
-
}
|
|
1470
|
-
);
|
|
1471
|
-
}
|
|
1472
|
-
);
|
|
1473
|
-
test
|
|
1474
|
-
(
|
|
1475
|
-
'read: inject data into the record',
|
|
1476
|
-
function(fDone)
|
|
1477
|
-
{
|
|
1478
|
-
// Override the query configuration
|
|
1479
|
-
_MeadowEndpoints.behaviorModifications.setBehavior('Read-PostOperation',
|
|
1480
|
-
function(pRequest, fComplete)
|
|
1481
|
-
{
|
|
1482
|
-
// Create a custom property on the record.
|
|
1483
|
-
pRequest.Record.CustomProperty = 'Custom '+pRequest.Record.Type+' ID '+pRequest.Record.IDAnimal;
|
|
1484
|
-
fComplete(false);
|
|
1485
|
-
});
|
|
1486
|
-
_MockSessionValidUser.LoggedIn = true;
|
|
1487
|
-
libSuperTest('http://localhost:9080/')
|
|
1488
|
-
.get('1.0/FableTest/2')
|
|
1489
|
-
.end(
|
|
1490
|
-
function (pError, pResponse)
|
|
1491
|
-
{
|
|
1492
|
-
var tmpResult = JSON.parse(pResponse.text);
|
|
1493
|
-
//console.log(JSON.stringify(tmpResult, null, 4))
|
|
1494
|
-
Expect(tmpResult.CustomProperty).to.equal('Custom Girl ID 2');
|
|
1495
|
-
fDone();
|
|
1496
|
-
}
|
|
1497
|
-
);
|
|
1498
|
-
}
|
|
1499
|
-
);
|
|
1500
|
-
test
|
|
1501
|
-
(
|
|
1502
|
-
'read-max: get the max record ID',
|
|
1503
|
-
function(fDone)
|
|
1504
|
-
{
|
|
1505
|
-
libSuperTest('http://localhost:9080/')
|
|
1506
|
-
.get('1.0/FableTest/Max/IDAnimal')
|
|
1507
|
-
.end(
|
|
1508
|
-
function (pError, pResponse)
|
|
1509
|
-
{
|
|
1510
|
-
var tmpResult = JSON.parse(pResponse.text);
|
|
1511
|
-
Expect(tmpResult.IDAnimal).to.equal(6);
|
|
1512
|
-
fDone();
|
|
1513
|
-
}
|
|
1514
|
-
);
|
|
1515
|
-
}
|
|
1516
|
-
);
|
|
1517
|
-
test
|
|
1518
|
-
(
|
|
1519
|
-
'read-max: get the max name',
|
|
1520
|
-
function(fDone)
|
|
1521
|
-
{
|
|
1522
|
-
libSuperTest('http://localhost:9080/')
|
|
1523
|
-
.get('1.0/FableTest/Max/Name')
|
|
1524
|
-
.end(
|
|
1525
|
-
function (pError, pResponse)
|
|
1526
|
-
{
|
|
1527
|
-
var tmpResult = JSON.parse(pResponse.text);
|
|
1528
|
-
Expect(tmpResult.Name).to.equal('Spot');
|
|
1529
|
-
fDone();
|
|
1530
|
-
}
|
|
1531
|
-
);
|
|
1532
|
-
}
|
|
1533
|
-
);
|
|
1534
|
-
}
|
|
1535
|
-
);
|
|
1536
|
-
suite
|
|
1537
|
-
(
|
|
1538
|
-
'Direct invocation',
|
|
1539
|
-
function()
|
|
1540
|
-
{
|
|
1541
|
-
var tmpCreatedRecordGUID;
|
|
1542
|
-
|
|
1543
|
-
test
|
|
1544
|
-
(
|
|
1545
|
-
'invoke: setup method is called',
|
|
1546
|
-
function(fDone)
|
|
1547
|
-
{
|
|
1548
|
-
_MockSessionValidUser.UserRoleIndex = 2;
|
|
1549
|
-
let setupCallCount = 0;
|
|
1550
|
-
let passedRequest, passedResponse, passedOriginalRequest;
|
|
1551
|
-
_MeadowEndpoints.setInvokeSetupCallback((req, res, origReq) =>
|
|
1552
|
-
{
|
|
1553
|
-
++setupCallCount;
|
|
1554
|
-
passedRequest = req;
|
|
1555
|
-
passedResponse = res;
|
|
1556
|
-
passedOriginalRequest = origReq;
|
|
1557
|
-
});
|
|
1558
|
-
const originalRequest = {UserSession: _MockSessionValidUser};
|
|
1559
|
-
_MeadowEndpoints.invokeEndpoint('Read', {IDRecord: 2}, originalRequest,
|
|
1560
|
-
function(pError, pResponse)
|
|
1561
|
-
{
|
|
1562
|
-
Expect(setupCallCount).to.equal(1);
|
|
1563
|
-
Expect(passedOriginalRequest).to.equal(originalRequest);
|
|
1564
|
-
Expect(passedRequest).to.be.an('object');
|
|
1565
|
-
Expect(passedResponse).to.be.an('object');
|
|
1566
|
-
|
|
1567
|
-
fDone();
|
|
1568
|
-
}
|
|
1569
|
-
);
|
|
1570
|
-
}
|
|
1571
|
-
);
|
|
1572
|
-
test
|
|
1573
|
-
(
|
|
1574
|
-
'invoke create: create a record',
|
|
1575
|
-
function(fDone)
|
|
1576
|
-
{
|
|
1577
|
-
var tmpRecord = {Name:'BatBrains', Type:'Mammoth'};
|
|
1578
|
-
_MockSessionValidUser.UserRoleIndex = 2;
|
|
1579
|
-
_MeadowEndpoints.invokeEndpoint('Create', tmpRecord, {UserSession: _MockSessionValidUser},
|
|
1580
|
-
function(pError, pResponse)
|
|
1581
|
-
{
|
|
1582
|
-
// Expect response to be the record we just created.
|
|
1583
|
-
Expect(pResponse.body.Name)
|
|
1584
|
-
.to.equal(tmpRecord.Name);
|
|
1585
|
-
|
|
1586
|
-
tmpCreatedRecordGUID = pResponse.body.GUIDAnimal;
|
|
1587
|
-
|
|
1588
|
-
fDone();
|
|
1589
|
-
}
|
|
1590
|
-
);
|
|
1591
|
-
}
|
|
1592
|
-
);
|
|
1593
|
-
test
|
|
1594
|
-
(
|
|
1595
|
-
'invoke create: create a record with a bad record passed in',
|
|
1596
|
-
function(fDone)
|
|
1597
|
-
{
|
|
1598
|
-
var tmpRecord = ' ';
|
|
1599
|
-
_MockSessionValidUser.UserRoleIndex = 2;
|
|
1600
|
-
_MeadowEndpoints.invokeEndpoint('Create', tmpRecord,
|
|
1601
|
-
function(pError, pResponse)
|
|
1602
|
-
{
|
|
1603
|
-
// Expect response to be the record we just created.
|
|
1604
|
-
var tmpResult = JSON.parse(pResponse.text);
|
|
1605
|
-
Expect(tmpResult.Error).to.contain('a valid record is required');
|
|
1606
|
-
fDone();
|
|
1607
|
-
}
|
|
1608
|
-
);
|
|
1609
|
-
}
|
|
1610
|
-
);
|
|
1611
|
-
test
|
|
1612
|
-
(
|
|
1613
|
-
'invoke read: get a specific record',
|
|
1614
|
-
function(fDone)
|
|
1615
|
-
{
|
|
1616
|
-
_MeadowEndpoints.invokeEndpoint('Read', {IDRecord: 2}, {UserSession: _MockSessionValidUser},
|
|
1617
|
-
function (pError, pResponse)
|
|
1618
|
-
{
|
|
1619
|
-
var tmpResult = JSON.parse(pResponse.text);
|
|
1620
|
-
Expect(tmpResult.Type).to.equal('Girl');
|
|
1621
|
-
fDone();
|
|
1622
|
-
}
|
|
1623
|
-
);
|
|
1624
|
-
}
|
|
1625
|
-
);
|
|
1626
|
-
test
|
|
1627
|
-
(
|
|
1628
|
-
'invoke read: get a specific record by GUID',
|
|
1629
|
-
function(fDone)
|
|
1630
|
-
{
|
|
1631
|
-
_MeadowEndpoints.invokeEndpoint('Read', {GUIDRecord: tmpCreatedRecordGUID}, {UserSession: _MockSessionValidUser},
|
|
1632
|
-
function (pError, pResponse)
|
|
1633
|
-
{
|
|
1634
|
-
var tmpResult = JSON.parse(pResponse.text);
|
|
1635
|
-
Expect(tmpResult.Type).to.equal('Mammoth');
|
|
1636
|
-
fDone();
|
|
1637
|
-
}
|
|
1638
|
-
);
|
|
1639
|
-
}
|
|
1640
|
-
);
|
|
1641
|
-
test
|
|
1642
|
-
(
|
|
1643
|
-
'read: get a specific record with a bad parameter',
|
|
1644
|
-
function(fDone)
|
|
1645
|
-
{
|
|
1646
|
-
_MeadowEndpoints.invokeEndpoint('Read', {},
|
|
1647
|
-
function (pError, pResponse)
|
|
1648
|
-
{
|
|
1649
|
-
var tmpResult = JSON.parse(pResponse.text);
|
|
1650
|
-
//console.log(tmpResult);
|
|
1651
|
-
Expect(tmpResult.Error).to.be.an('undefined'); //
|
|
1652
|
-
fDone();
|
|
1653
|
-
}
|
|
1654
|
-
);
|
|
1655
|
-
}
|
|
1656
|
-
);
|
|
1657
|
-
test
|
|
1658
|
-
(
|
|
1659
|
-
'invoke readselect: get all records',
|
|
1660
|
-
function(fDone)
|
|
1661
|
-
{
|
|
1662
|
-
_MeadowEndpoints.invokeEndpoint('ReadSelectList', {}, {UserSession: _MockSessionValidUser},
|
|
1663
|
-
function (pError, pResponse)
|
|
1664
|
-
{
|
|
1665
|
-
console.log(pResponse.body)
|
|
1666
|
-
Expect(pResponse.body)
|
|
1667
|
-
.to.be.an('array');
|
|
1668
|
-
//var tmpResults = JSON.parse(pResponse.text);
|
|
1669
|
-
//Expect(tmpResults.Error).to.contain('authenticated');
|
|
1670
|
-
fDone();
|
|
1671
|
-
}
|
|
1672
|
-
);
|
|
1673
|
-
}
|
|
1674
|
-
);
|
|
1675
|
-
test
|
|
1676
|
-
(
|
|
1677
|
-
'invoke readsby: get all records by Type',
|
|
1678
|
-
function(fDone)
|
|
1679
|
-
{
|
|
1680
|
-
_MeadowEndpoints.invokeEndpoint('ReadsBy', {ByField: 'Type', ByValue: 'Mammoth'}, {UserSession: _MockSessionValidUser},
|
|
1681
|
-
function (pError, pResponse)
|
|
1682
|
-
{
|
|
1683
|
-
//console.log(pResponse.body);
|
|
1684
|
-
|
|
1685
|
-
var tmpResults = pResponse.body; //JSON.parse(pResponse.text);
|
|
1686
|
-
Expect(tmpResults.length).to.equal(2);
|
|
1687
|
-
Expect(tmpResults[0].Type).to.equal('Mammoth');
|
|
1688
|
-
fDone();
|
|
1689
|
-
}
|
|
1690
|
-
);
|
|
1691
|
-
}
|
|
1692
|
-
);
|
|
1693
|
-
test
|
|
1694
|
-
(
|
|
1695
|
-
'invoke readsby: get all records by Type IN LIST',
|
|
1696
|
-
function(fDone)
|
|
1697
|
-
{
|
|
1698
|
-
_MeadowEndpoints.invokeEndpoint('ReadsBy', {ByField: 'Type', ByValue: ['Mammoth', 'Dog']}, {UserSession: _MockSessionValidUser},
|
|
1699
|
-
function (pError, pResponse)
|
|
1700
|
-
{
|
|
1701
|
-
//console.log(pResponse.body);
|
|
1702
|
-
|
|
1703
|
-
var tmpResults = pResponse.body; //JSON.parse(pResponse.text);
|
|
1704
|
-
Expect(tmpResults.length).to.equal(2);
|
|
1705
|
-
Expect(tmpResults[0].Type).to.equal('Mammoth');
|
|
1706
|
-
fDone();
|
|
1707
|
-
}
|
|
1708
|
-
);
|
|
1709
|
-
}
|
|
1710
|
-
);
|
|
1711
|
-
test
|
|
1712
|
-
(
|
|
1713
|
-
'invoke readsby: get all records by Type AND Name',
|
|
1714
|
-
function(fDone)
|
|
1715
|
-
{
|
|
1716
|
-
_MeadowEndpoints.invokeEndpoint('ReadsBy', {Filters: [
|
|
1717
|
-
{ByField: 'Type', ByValue: 'Mammoth'},
|
|
1718
|
-
{ByField: 'Name', ByValue: 'BatBrains'}
|
|
1719
|
-
]}, {UserSession: _MockSessionValidUser},
|
|
1720
|
-
function (pError, pResponse)
|
|
1721
|
-
{
|
|
1722
|
-
//console.log(pResponse.body);
|
|
1723
|
-
|
|
1724
|
-
var tmpResults = pResponse.body; //JSON.parse(pResponse.text);
|
|
1725
|
-
Expect(tmpResults.length).to.equal(2);
|
|
1726
|
-
Expect(tmpResults[0].Type).to.equal('Mammoth');
|
|
1727
|
-
fDone();
|
|
1728
|
-
}
|
|
1729
|
-
);
|
|
1730
|
-
}
|
|
1731
|
-
);
|
|
1732
|
-
test
|
|
1733
|
-
(
|
|
1734
|
-
'invoke countby: get cout of records by Type',
|
|
1735
|
-
function(fDone)
|
|
1736
|
-
{
|
|
1737
|
-
_MeadowEndpoints.invokeEndpoint('CountBy', {ByField: 'Type', ByValue: 'Mammoth'}, {UserSession: _MockSessionValidUser},
|
|
1738
|
-
function (pError, pResponse)
|
|
1739
|
-
{
|
|
1740
|
-
var tmpResults = pResponse.body; //JSON.parse(pResponse.text);
|
|
1741
|
-
Expect(tmpResults.Count).to.equal(2);
|
|
1742
|
-
fDone();
|
|
1743
|
-
}
|
|
1744
|
-
);
|
|
1745
|
-
}
|
|
1746
|
-
);
|
|
1747
|
-
test
|
|
1748
|
-
(
|
|
1749
|
-
'invoke readsby: get paged records by Type',
|
|
1750
|
-
function(fDone)
|
|
1751
|
-
{
|
|
1752
|
-
_MeadowEndpoints.invokeEndpoint('ReadsBy', {ByField: 'Type', ByValue: 'Mammoth', Begin: 1, Cap: 1}, {UserSession: _MockSessionValidUser},
|
|
1753
|
-
function (pError, pResponse)
|
|
1754
|
-
{
|
|
1755
|
-
var tmpResults = pResponse.body;
|
|
1756
|
-
Expect(tmpResults.length).to.equal(1);
|
|
1757
|
-
Expect(tmpResults[0].Type).to.equal('Mammoth');
|
|
1758
|
-
fDone();
|
|
1759
|
-
}
|
|
1760
|
-
);
|
|
1761
|
-
}
|
|
1762
|
-
);
|
|
1763
|
-
test
|
|
1764
|
-
(
|
|
1765
|
-
'invoke readselect: get a page of records',
|
|
1766
|
-
function(fDone)
|
|
1767
|
-
{
|
|
1768
|
-
_MeadowEndpoints.invokeEndpoint('ReadSelectList', {Begin: 2, Cap: 2}, {UserSession: _MockSessionValidUser},
|
|
1769
|
-
function (pError, pResponse)
|
|
1770
|
-
{
|
|
1771
|
-
var tmpResults = pResponse.Records; //JSON.parse(pResponse.text);
|
|
1772
|
-
Expect(tmpResults.length).to.equal(2);
|
|
1773
|
-
Expect(tmpResults[1].Value).to.equal('FableTest #5');
|
|
1774
|
-
fDone();
|
|
1775
|
-
}
|
|
1776
|
-
);
|
|
1777
|
-
}
|
|
1778
|
-
);
|
|
1779
|
-
test
|
|
1780
|
-
(
|
|
1781
|
-
'invoke readselect: get an empty page of records',
|
|
1782
|
-
function(fDone)
|
|
1783
|
-
{
|
|
1784
|
-
_MeadowEndpoints.invokeEndpoint('ReadSelectList', {Begin: 200, Cap: 200}, {UserSession: _MockSessionValidUser},
|
|
1785
|
-
function (pError, pResponse)
|
|
1786
|
-
{
|
|
1787
|
-
var tmpResults = pResponse.Records; //JSON.parse(pResponse.text);
|
|
1788
|
-
Expect(tmpResults.length).to.equal(0);
|
|
1789
|
-
fDone();
|
|
1790
|
-
}
|
|
1791
|
-
);
|
|
1792
|
-
}
|
|
1793
|
-
);
|
|
1794
|
-
test
|
|
1795
|
-
(
|
|
1796
|
-
'invoke reads: get a page of records',
|
|
1797
|
-
function(fDone)
|
|
1798
|
-
{
|
|
1799
|
-
_MeadowEndpoints.invokeEndpoint('Reads', {Begin: 2, Cap: 2}, {UserSession: _MockSessionValidUser},
|
|
1800
|
-
function (pError, pResponse)
|
|
1801
|
-
{
|
|
1802
|
-
var tmpResults = pResponse.Records; //JSON.parse(pResponse.text);
|
|
1803
|
-
Expect(tmpResults.length).to.equal(2);
|
|
1804
|
-
Expect(tmpResults[0].Type).to.equal('Corgi');
|
|
1805
|
-
Expect(tmpResults[1].Name).to.equal('Gertrude');
|
|
1806
|
-
fDone();
|
|
1807
|
-
}
|
|
1808
|
-
);
|
|
1809
|
-
}
|
|
1810
|
-
);
|
|
1811
|
-
test
|
|
1812
|
-
(
|
|
1813
|
-
'invoke update: update a record',
|
|
1814
|
-
function(fDone)
|
|
1815
|
-
{
|
|
1816
|
-
// Change animal 4 ("Spot") to a Corgi
|
|
1817
|
-
var tmpRecord = {IDAnimal:4, Type:'Corgi'};
|
|
1818
|
-
_MeadowEndpoints.invokeEndpoint('Update', tmpRecord, {UserSession: _MockSessionValidUser},
|
|
1819
|
-
function(pError, pResponse)
|
|
1820
|
-
{
|
|
1821
|
-
// Expect response to be the record we just created.
|
|
1822
|
-
var tmpResult = pResponse.Record; //JSON.parse(pResponse.text);
|
|
1823
|
-
Expect(tmpResult.Type).to.equal('Corgi');
|
|
1824
|
-
Expect(tmpResult.CreatingIDUser).to.equal(1);
|
|
1825
|
-
Expect(tmpResult.UpdatingIDUser).to.equal(_MockSessionValidUser.UserID);
|
|
1826
|
-
fDone();
|
|
1827
|
-
}
|
|
1828
|
-
);
|
|
1829
|
-
}
|
|
1830
|
-
);
|
|
1831
|
-
test
|
|
1832
|
-
(
|
|
1833
|
-
'invoke delete: delete a record',
|
|
1834
|
-
function(fDone)
|
|
1835
|
-
{
|
|
1836
|
-
// Delete animal 4 ("Corgi")
|
|
1837
|
-
var tmpRecord = {IDAnimal:4};
|
|
1838
|
-
|
|
1839
|
-
// Override the query configuration
|
|
1840
|
-
_MeadowEndpoints.behaviorModifications.setBehavior('Delete-PreOperation',
|
|
1841
|
-
function(pRequest, fComplete)
|
|
1842
|
-
{
|
|
1843
|
-
// Create a custom property on the record.
|
|
1844
|
-
Expect(pRequest.Record.IDAnimal).to.equal(tmpRecord.IDAnimal);
|
|
1845
|
-
return fComplete(false);
|
|
1846
|
-
});
|
|
1847
|
-
|
|
1848
|
-
_MeadowEndpoints.invokeEndpoint('Delete', tmpRecord, {UserSession: _MockSessionValidUser},
|
|
1849
|
-
function(pError, pResponse)
|
|
1850
|
-
{
|
|
1851
|
-
//clear out the behavior mapping to not affect other tests
|
|
1852
|
-
_MeadowEndpoints.behaviorModifications.setBehavior('Delete-PreOperation', null);
|
|
1853
|
-
|
|
1854
|
-
// Expect response to be the count of deleted records.
|
|
1855
|
-
var tmpResult = pResponse.body; //JSON.parse(pResponse.text);
|
|
1856
|
-
Expect(tmpResult.Count).to.equal(1);
|
|
1857
|
-
return fDone();
|
|
1858
|
-
}
|
|
1859
|
-
);
|
|
1860
|
-
}
|
|
1861
|
-
);
|
|
1862
|
-
test
|
|
1863
|
-
(
|
|
1864
|
-
'invoke delete: delete a record with a bad parameter',
|
|
1865
|
-
function(fDone)
|
|
1866
|
-
{
|
|
1867
|
-
// Delete animal 3 ("Red")
|
|
1868
|
-
var tmpRecord = {IDAnimal:{MyStuff:4}};
|
|
1869
|
-
_MeadowEndpoints.invokeEndpoint('Delete', tmpRecord, {UserSession: _MockSessionValidUser},
|
|
1870
|
-
function(pError, pResponse)
|
|
1871
|
-
{
|
|
1872
|
-
// Expect response to be the count of deleted records.
|
|
1873
|
-
var tmpResult = pResponse.body; //JSON.parse(pResponse.text);
|
|
1874
|
-
Expect(tmpResult.Error).to.contain('a valid record ID is required');
|
|
1875
|
-
fDone();
|
|
1876
|
-
}
|
|
1877
|
-
);
|
|
1878
|
-
}
|
|
1879
|
-
);
|
|
1880
|
-
test
|
|
1881
|
-
(
|
|
1882
|
-
'count: get the count of records',
|
|
1883
|
-
function(fDone)
|
|
1884
|
-
{
|
|
1885
|
-
_MeadowEndpoints.invokeEndpoint('Count', {}, {UserSession: _MockSessionValidUser},
|
|
1886
|
-
function (pError, pResponse)
|
|
1887
|
-
{
|
|
1888
|
-
var tmpResults = pResponse.body; //JSON.parse(pResponse.text);
|
|
1889
|
-
Expect(tmpResults.Count).to.equal(5);
|
|
1890
|
-
fDone();
|
|
1891
|
-
}
|
|
1892
|
-
);
|
|
1893
|
-
}
|
|
1894
|
-
);
|
|
1895
|
-
test
|
|
1896
|
-
(
|
|
1897
|
-
'schema: get the schema of a record',
|
|
1898
|
-
function(fDone)
|
|
1899
|
-
{
|
|
1900
|
-
_MeadowEndpoints.invokeEndpoint('Schema', {},
|
|
1901
|
-
function (pError, pResponse)
|
|
1902
|
-
{
|
|
1903
|
-
var tmpResults = pResponse.body; //JSON.parse(pResponse.text);
|
|
1904
|
-
//console.log('SCHEMA --> '+JSON.stringify(tmpResults, null, 4))
|
|
1905
|
-
Expect(tmpResults.title).to.equal('Animal');
|
|
1906
|
-
Expect(tmpResults.description).to.contain('creature that lives in');
|
|
1907
|
-
fDone();
|
|
1908
|
-
}
|
|
1909
|
-
);
|
|
1910
|
-
}
|
|
1911
|
-
);
|
|
1912
|
-
test
|
|
1913
|
-
(
|
|
1914
|
-
'new: get a new empty record',
|
|
1915
|
-
function(fDone)
|
|
1916
|
-
{
|
|
1917
|
-
_MeadowEndpoints.invokeEndpoint('New', {}, {UserSession: _MockSessionValidUser},
|
|
1918
|
-
function (pError, pResponse)
|
|
1919
|
-
{
|
|
1920
|
-
var tmpResults = pResponse.body; //JSON.parse(pResponse.text);
|
|
1921
|
-
//console.log(JSON.stringify(tmpResults, null, 4))
|
|
1922
|
-
Expect(tmpResults.IDAnimal).to.equal(null);
|
|
1923
|
-
Expect(tmpResults.Name).to.equal('Unknown');
|
|
1924
|
-
Expect(tmpResults.Type).to.equal('Unclassified');
|
|
1925
|
-
fDone();
|
|
1926
|
-
}
|
|
1927
|
-
);
|
|
1928
|
-
}
|
|
1929
|
-
);
|
|
1930
|
-
test
|
|
1931
|
-
(
|
|
1932
|
-
'validate: validate an invalid record',
|
|
1933
|
-
function(fDone)
|
|
1934
|
-
{
|
|
1935
|
-
var tmpRecord = {IDAnimal:4, Type:'Corgi'};
|
|
1936
|
-
_MeadowEndpoints.invokeEndpoint('Validate', tmpRecord, {UserSession: _MockSessionValidUser},
|
|
1937
|
-
function(pError, pResponse)
|
|
1938
|
-
{
|
|
1939
|
-
// Expect response to be the record we just created.
|
|
1940
|
-
var tmpResult = pResponse.body; //JSON.parse(pResponse.text);
|
|
1941
|
-
//console.log(JSON.stringify(tmpResult, null, 4))
|
|
1942
|
-
Expect(tmpResult.Valid).to.equal(false);
|
|
1943
|
-
Expect(tmpResult.Errors[0].field).to.equal('data.Name');
|
|
1944
|
-
Expect(tmpResult.Errors[0].message).to.equal('is required');
|
|
1945
|
-
fDone();
|
|
1946
|
-
}
|
|
1947
|
-
);
|
|
1948
|
-
}
|
|
1949
|
-
);
|
|
1950
|
-
test
|
|
1951
|
-
(
|
|
1952
|
-
'validate: validate a valid record',
|
|
1953
|
-
function(fDone)
|
|
1954
|
-
{
|
|
1955
|
-
var tmpRecord = {IDAnimal:4, Type:'Corgi', Name:'Doofer', CreatingIDUser:10};
|
|
1956
|
-
_MeadowEndpoints.invokeEndpoint('Validate', tmpRecord, {UserSession: _MockSessionValidUser},
|
|
1957
|
-
function(pError, pResponse)
|
|
1958
|
-
{
|
|
1959
|
-
// Expect response to be the record we just created.
|
|
1960
|
-
var tmpResult = pResponse.body; //JSON.parse(pResponse.text);
|
|
1961
|
-
//console.log(JSON.stringify(tmpResult, null, 4))
|
|
1962
|
-
Expect(tmpResult.Valid).to.equal(true);
|
|
1963
|
-
fDone();
|
|
1964
|
-
}
|
|
1965
|
-
);
|
|
1966
|
-
}
|
|
1967
|
-
);
|
|
1968
|
-
test
|
|
1969
|
-
(
|
|
1970
|
-
'validate: validate bad data',
|
|
1971
|
-
function(fDone)
|
|
1972
|
-
{
|
|
1973
|
-
var tmpRecord = 'IAMBAD';
|
|
1974
|
-
_MeadowEndpoints.invokeEndpoint('Validate', tmpRecord, {UserSession: _MockSessionValidUser},
|
|
1975
|
-
function(pError, pResponse)
|
|
1976
|
-
{
|
|
1977
|
-
// Expect response to be the record we just created.
|
|
1978
|
-
var tmpResult = pResponse.body; //JSON.parse(pResponse.text);
|
|
1979
|
-
//console.log(JSON.stringify(tmpResult, null, 4))
|
|
1980
|
-
Expect(tmpResult.Error).to.contain('validate failure');
|
|
1981
|
-
fDone();
|
|
1982
|
-
}
|
|
1983
|
-
);
|
|
1984
|
-
}
|
|
1985
|
-
);
|
|
1986
|
-
}
|
|
1987
|
-
);
|
|
1988
|
-
|
|
1989
|
-
suite
|
|
1990
|
-
(
|
|
1991
|
-
'Endpoint Security - Deny',
|
|
1992
|
-
function()
|
|
1993
|
-
{
|
|
1994
|
-
test
|
|
1995
|
-
(
|
|
1996
|
-
'invoke read: get a specific record',
|
|
1997
|
-
function(fDone)
|
|
1998
|
-
{
|
|
1999
|
-
_MockSessionValidUser.LoggedIn = true;
|
|
2000
|
-
_MockSessionValidUser.UserRoleIndex = 5; //set it to an undefined role, so the DefaultAPISecurity definitions of 'Deny' get used.
|
|
2001
|
-
|
|
2002
|
-
_MeadowEndpoints.invokeEndpoint('Read', {IDRecord: 2}, {UserSession: _MockSessionValidUser},
|
|
2003
|
-
function (pError, pResponse)
|
|
2004
|
-
{
|
|
2005
|
-
Expect(pResponse.body.ErrorCode).to.equal(405);
|
|
2006
|
-
Expect(pResponse.body.Error).to.equal('UNAUTHORIZED ACCESS IS NOT ALLOWED');
|
|
2007
|
-
return fDone();
|
|
2008
|
-
}
|
|
2009
|
-
);
|
|
2010
|
-
}
|
|
2011
|
-
);
|
|
2012
|
-
test
|
|
2013
|
-
(
|
|
2014
|
-
'invoke create: create a record',
|
|
2015
|
-
function(fDone)
|
|
2016
|
-
{
|
|
2017
|
-
var tmpRecord = {Name:'BatBrains', Type:'Mammoth'};
|
|
2018
|
-
_MeadowEndpoints.invokeEndpoint('Create', tmpRecord, {UserSession: _MockSessionValidUser},
|
|
2019
|
-
function(pError, pResponse)
|
|
2020
|
-
{
|
|
2021
|
-
Expect(pResponse.body.ErrorCode).to.equal(405);
|
|
2022
|
-
Expect(pResponse.body.Error).to.equal('UNAUTHORIZED ACCESS IS NOT ALLOWED');
|
|
2023
|
-
|
|
2024
|
-
return fDone();
|
|
2025
|
-
}
|
|
2026
|
-
);
|
|
2027
|
-
}
|
|
2028
|
-
);
|
|
2029
|
-
test
|
|
2030
|
-
(
|
|
2031
|
-
'invoke create: create a record with a bad record passed in',
|
|
2032
|
-
function(fDone)
|
|
2033
|
-
{
|
|
2034
|
-
var tmpRecord = ' ';
|
|
2035
|
-
_MeadowEndpoints.invokeEndpoint('Create', tmpRecord, {UserSession: _MockSessionValidUser},
|
|
2036
|
-
function(pError, pResponse)
|
|
2037
|
-
{
|
|
2038
|
-
// Expect response to be the record we just created.
|
|
2039
|
-
var tmpResult = JSON.parse(pResponse.text);
|
|
2040
|
-
Expect(tmpResult.Error).to.contain('a valid record is required');
|
|
2041
|
-
fDone();
|
|
2042
|
-
}
|
|
2043
|
-
);
|
|
2044
|
-
}
|
|
2045
|
-
);
|
|
2046
|
-
test
|
|
2047
|
-
(
|
|
2048
|
-
'invoke readselect: get all records',
|
|
2049
|
-
function(fDone)
|
|
2050
|
-
{
|
|
2051
|
-
_MeadowEndpoints.invokeEndpoint('ReadSelectList', {}, {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
|
-
fDone();
|
|
2058
|
-
}
|
|
2059
|
-
);
|
|
2060
|
-
}
|
|
2061
|
-
);
|
|
2062
|
-
test
|
|
2063
|
-
(
|
|
2064
|
-
'invoke readsby: get all records by Type',
|
|
2065
|
-
function(fDone)
|
|
2066
|
-
{
|
|
2067
|
-
_MeadowEndpoints.invokeEndpoint('ReadsBy', {ByField: 'Type', ByValue: 'Mammoth'}, {UserSession: _MockSessionValidUser},
|
|
2068
|
-
function (pError, pResponse)
|
|
2069
|
-
{
|
|
2070
|
-
Expect(pResponse.body.ErrorCode).to.equal(405);
|
|
2071
|
-
Expect(pResponse.body.Error).to.equal('UNAUTHORIZED ACCESS IS NOT ALLOWED');
|
|
2072
|
-
fDone();
|
|
2073
|
-
}
|
|
2074
|
-
);
|
|
2075
|
-
}
|
|
2076
|
-
);
|
|
2077
|
-
test
|
|
2078
|
-
(
|
|
2079
|
-
'invoke readsby: get all records by Type IN LIST',
|
|
2080
|
-
function(fDone)
|
|
2081
|
-
{
|
|
2082
|
-
_MeadowEndpoints.invokeEndpoint('ReadsBy', {ByField: 'Type', ByValue: ['Mammoth', 'Dog']}, {UserSession: _MockSessionValidUser},
|
|
2083
|
-
function (pError, pResponse)
|
|
2084
|
-
{
|
|
2085
|
-
Expect(pResponse.body.ErrorCode).to.equal(405);
|
|
2086
|
-
Expect(pResponse.body.Error).to.equal('UNAUTHORIZED ACCESS IS NOT ALLOWED');
|
|
2087
|
-
fDone();
|
|
2088
|
-
}
|
|
2089
|
-
);
|
|
2090
|
-
}
|
|
2091
|
-
);
|
|
2092
|
-
test
|
|
2093
|
-
(
|
|
2094
|
-
'invoke countby: get cout of records by Type',
|
|
2095
|
-
function(fDone)
|
|
2096
|
-
{
|
|
2097
|
-
_MeadowEndpoints.invokeEndpoint('CountBy', {ByField: 'Type', ByValue: 'Mammoth'}, {UserSession: _MockSessionValidUser},
|
|
2098
|
-
function (pError, pResponse)
|
|
2099
|
-
{
|
|
2100
|
-
Expect(pResponse.body.ErrorCode).to.equal(405);
|
|
2101
|
-
Expect(pResponse.body.Error).to.equal('UNAUTHORIZED ACCESS IS NOT ALLOWED');
|
|
2102
|
-
fDone();
|
|
2103
|
-
}
|
|
2104
|
-
);
|
|
2105
|
-
}
|
|
2106
|
-
);
|
|
2107
|
-
test
|
|
2108
|
-
(
|
|
2109
|
-
'invoke countby: get cout of records by Type',
|
|
2110
|
-
function(fDone)
|
|
2111
|
-
{
|
|
2112
|
-
_MeadowEndpoints.invokeEndpoint('Count', {}, {UserSession: _MockSessionValidUser},
|
|
2113
|
-
function (pError, pResponse)
|
|
2114
|
-
{
|
|
2115
|
-
Expect(pResponse.body.ErrorCode).to.equal(405);
|
|
2116
|
-
Expect(pResponse.body.Error).to.equal('UNAUTHORIZED ACCESS IS NOT ALLOWED');
|
|
2117
|
-
fDone();
|
|
2118
|
-
}
|
|
2119
|
-
);
|
|
2120
|
-
}
|
|
2121
|
-
);
|
|
2122
|
-
test
|
|
2123
|
-
(
|
|
2124
|
-
'invoke readselect: get a page of records',
|
|
2125
|
-
function(fDone)
|
|
2126
|
-
{
|
|
2127
|
-
_MeadowEndpoints.invokeEndpoint('ReadSelectList', {Begin: 2, Cap: 2}, {UserSession: _MockSessionValidUser},
|
|
2128
|
-
function (pError, pResponse)
|
|
2129
|
-
{
|
|
2130
|
-
Expect(pResponse.body.ErrorCode).to.equal(405);
|
|
2131
|
-
Expect(pResponse.body.Error).to.equal('UNAUTHORIZED ACCESS IS NOT ALLOWED');
|
|
2132
|
-
fDone();
|
|
2133
|
-
}
|
|
2134
|
-
);
|
|
2135
|
-
}
|
|
2136
|
-
);
|
|
2137
|
-
test
|
|
2138
|
-
(
|
|
2139
|
-
'invoke readselect: get an empty page of records',
|
|
2140
|
-
function(fDone)
|
|
2141
|
-
{
|
|
2142
|
-
_MeadowEndpoints.invokeEndpoint('ReadSelectList', {Begin: 200, Cap: 200}, {UserSession: _MockSessionValidUser},
|
|
2143
|
-
function (pError, pResponse)
|
|
2144
|
-
{
|
|
2145
|
-
// Because no records were returned, it should show as Authorized
|
|
2146
|
-
|
|
2147
|
-
var tmpResults = pResponse.Records; //JSON.parse(pResponse.text);
|
|
2148
|
-
Expect(tmpResults.length).to.equal(0);
|
|
2149
|
-
fDone();
|
|
2150
|
-
}
|
|
2151
|
-
);
|
|
2152
|
-
}
|
|
2153
|
-
);
|
|
2154
|
-
test
|
|
2155
|
-
(
|
|
2156
|
-
'invoke reads: get a page of records',
|
|
2157
|
-
function(fDone)
|
|
2158
|
-
{
|
|
2159
|
-
_MeadowEndpoints.invokeEndpoint('Reads', {Begin: 2, Cap: 2}, {UserSession: _MockSessionValidUser},
|
|
2160
|
-
function (pError, pResponse)
|
|
2161
|
-
{
|
|
2162
|
-
Expect(pResponse.body.ErrorCode).to.equal(405);
|
|
2163
|
-
Expect(pResponse.body.Error).to.equal('UNAUTHORIZED ACCESS IS NOT ALLOWED');
|
|
2164
|
-
|
|
2165
|
-
fDone();
|
|
2166
|
-
}
|
|
2167
|
-
);
|
|
2168
|
-
}
|
|
2169
|
-
);
|
|
2170
|
-
test
|
|
2171
|
-
(
|
|
2172
|
-
'invoke update: update a record',
|
|
2173
|
-
function(fDone)
|
|
2174
|
-
{
|
|
2175
|
-
// Change animal 1
|
|
2176
|
-
var tmpRecord = {IDAnimal:1, Type:'Corgi'};
|
|
2177
|
-
_MeadowEndpoints.invokeEndpoint('Update', tmpRecord, {UserSession: _MockSessionValidUser},
|
|
2178
|
-
function(pError, pResponse)
|
|
2179
|
-
{
|
|
2180
|
-
Expect(pResponse.body.ErrorCode).to.equal(405);
|
|
2181
|
-
Expect(pResponse.body.Error).to.equal('UNAUTHORIZED ACCESS IS NOT ALLOWED');
|
|
2182
|
-
|
|
2183
|
-
fDone();
|
|
2184
|
-
}
|
|
2185
|
-
);
|
|
2186
|
-
}
|
|
2187
|
-
);
|
|
2188
|
-
test
|
|
2189
|
-
(
|
|
2190
|
-
'invoke update: update a record, override security to authorize the request',
|
|
2191
|
-
function(fDone)
|
|
2192
|
-
{
|
|
2193
|
-
// Change animal 1
|
|
2194
|
-
var tmpRecord = {IDAnimal:1, Type:'Corgi'};
|
|
2195
|
-
_MeadowEndpoints.invokeEndpoint('Update', tmpRecord, {UserSession: _MockSessionValidUser, Satchel: {AuthorizeOverride: true}},
|
|
2196
|
-
function(pError, pResponse)
|
|
2197
|
-
{
|
|
2198
|
-
// Expect response to be the record we just updated.
|
|
2199
|
-
var tmpResult = pResponse.Record; //JSON.parse(pResponse.text);
|
|
2200
|
-
Expect(tmpResult.Type).to.equal('Corgi');
|
|
107
|
+
Expect(tmpResult.Title).to.equal('Batman is Batman');
|
|
2201
108
|
Expect(tmpResult.CreatingIDUser).to.equal(1);
|
|
2202
|
-
Expect(tmpResult.UpdatingIDUser).to.equal(_MockSessionValidUser.UserID);
|
|
2203
|
-
|
|
2204
|
-
fDone();
|
|
2205
|
-
}
|
|
2206
|
-
);
|
|
2207
|
-
}
|
|
2208
|
-
);
|
|
2209
|
-
test
|
|
2210
|
-
(
|
|
2211
|
-
'invoke delete: delete a record',
|
|
2212
|
-
function(fDone)
|
|
2213
|
-
{
|
|
2214
|
-
// Delete animal 1
|
|
2215
|
-
var tmpRecord = {IDAnimal:1};
|
|
2216
|
-
_MeadowEndpoints.invokeEndpoint('Delete', tmpRecord, {UserSession: _MockSessionValidUser},
|
|
2217
|
-
function(pError, pResponse)
|
|
2218
|
-
{
|
|
2219
|
-
Expect(pResponse.body.ErrorCode).to.equal(405);
|
|
2220
|
-
Expect(pResponse.body.Error).to.equal('UNAUTHORIZED ACCESS IS NOT ALLOWED');
|
|
2221
|
-
|
|
2222
|
-
fDone();
|
|
2223
|
-
}
|
|
2224
|
-
);
|
|
2225
|
-
}
|
|
2226
|
-
);
|
|
2227
|
-
test
|
|
2228
|
-
(
|
|
2229
|
-
'bulk creates',
|
|
2230
|
-
function(fDone)
|
|
2231
|
-
{
|
|
2232
|
-
var tmpRecords = [
|
|
2233
|
-
{Name:'Billy', Type:'Cat'},
|
|
2234
|
-
{Name:'Jim', Type:'Cat'},
|
|
2235
|
-
{Name:'Janet', Type:'Cat'},
|
|
2236
|
-
{Name:'Sweeps', Type:'Cat'},
|
|
2237
|
-
{Name:'Stakes', Type:'Dog'},
|
|
2238
|
-
{Name:'Sally', Type:'Dog'},
|
|
2239
|
-
{Name:'Bill', Type:'Dog'},
|
|
2240
|
-
{Name:'Chris', Type:'Dog'},
|
|
2241
|
-
{Name:'Haji', Type:'Snake'}
|
|
2242
|
-
];
|
|
2243
|
-
_MockSessionValidUser.UserRoleIndex = 2;
|
|
2244
|
-
libSuperTest('http://localhost:9080/')
|
|
2245
|
-
.post('1.0/FableTests')
|
|
2246
|
-
.send(tmpRecords)
|
|
2247
|
-
.end(
|
|
2248
|
-
function(pError, pResponse)
|
|
2249
|
-
{
|
|
2250
|
-
// Expect response to be the record we just created.
|
|
2251
|
-
var tmpResult = JSON.parse(pResponse.text);
|
|
2252
|
-
//console.log(JSON.stringify(tmpResult,null,4));
|
|
2253
|
-
Expect(tmpResult[0].Name).to.equal('Billy');
|
|
2254
|
-
Expect(tmpResult[5].Type).to.equal('Dog');
|
|
2255
|
-
fDone();
|
|
2256
|
-
}
|
|
2257
|
-
);
|
|
2258
|
-
}
|
|
2259
|
-
);
|
|
2260
|
-
test
|
|
2261
|
-
(
|
|
2262
|
-
'bulk create with a bad record',
|
|
2263
|
-
function(fDone)
|
|
2264
|
-
{
|
|
2265
|
-
var tmpRecords = [
|
|
2266
|
-
{Name:'Astro', Type:'Cartoon'},
|
|
2267
|
-
{Name:'Boy', Type:'Cartoon'},
|
|
2268
|
-
{License:'Whoops', Type:'Cat'},
|
|
2269
|
-
{Name:'Froggy', Type:'Cartoon'}
|
|
2270
|
-
];
|
|
2271
|
-
_MockSessionValidUser.UserRoleIndex = 2;
|
|
2272
|
-
libSuperTest('http://localhost:9080/')
|
|
2273
|
-
.post('1.0/FableTests')
|
|
2274
|
-
.send(tmpRecords)
|
|
2275
|
-
.end(
|
|
2276
|
-
function(pError, pResponse)
|
|
2277
|
-
{
|
|
2278
|
-
// Expect response to be the record we just created.
|
|
2279
|
-
var tmpResult = JSON.parse(pResponse.text);
|
|
2280
|
-
Expect(tmpResult[0].Type).to.equal('Cartoon');
|
|
2281
|
-
fDone();
|
|
2282
|
-
}
|
|
2283
|
-
);
|
|
2284
|
-
}
|
|
2285
|
-
);
|
|
2286
|
-
test
|
|
2287
|
-
(
|
|
2288
|
-
'bulk updates',
|
|
2289
|
-
function(fDone)
|
|
2290
|
-
{
|
|
2291
|
-
var tmpRecords = [
|
|
2292
|
-
{IDAnimal: 11, Type:'Hoss'},
|
|
2293
|
-
{IDAnimal: 12, Type:'Hoss'},
|
|
2294
|
-
{IDAnimal: 14, Type:'Hoss'},
|
|
2295
|
-
{IDAnimal: 15, Type:'Hoss'}
|
|
2296
|
-
];
|
|
2297
|
-
_MockSessionValidUser.UserRoleIndex = 2;
|
|
2298
|
-
libSuperTest('http://localhost:9080/')
|
|
2299
|
-
.put('1.0/FableTests')
|
|
2300
|
-
.send(tmpRecords)
|
|
2301
|
-
.end(
|
|
2302
|
-
function(pError, pResponse)
|
|
2303
|
-
{
|
|
2304
|
-
// Expect response to be the record we just created.
|
|
2305
|
-
var tmpResult = JSON.parse(pResponse.text);
|
|
2306
|
-
//console.log(JSON.stringify(tmpResult,null,4));
|
|
2307
|
-
Expect(tmpResult[0].IDAnimal).to.equal(11);
|
|
2308
|
-
Expect(tmpResult[0].Type).to.equal('Hoss');
|
|
2309
|
-
Expect(tmpResult[1].Type).to.equal('Hoss');
|
|
2310
|
-
Expect(tmpResult[2].Type).to.equal('Hoss');
|
|
2311
|
-
Expect(tmpResult[3].Type).to.equal('Hoss');
|
|
2312
|
-
fDone();
|
|
2313
|
-
}
|
|
2314
|
-
);
|
|
2315
|
-
}
|
|
2316
|
-
);
|
|
2317
|
-
test
|
|
2318
|
-
(
|
|
2319
|
-
'bulk updates with bad record',
|
|
2320
|
-
function(fDone)
|
|
2321
|
-
{
|
|
2322
|
-
var tmpRecords = [
|
|
2323
|
-
{IDAnimal: 11, Type:'Horsse'},
|
|
2324
|
-
{IDAnimal: 12, Type:'Horsse'},
|
|
2325
|
-
{IDAnimal: 14, Genus:'Hosse'},
|
|
2326
|
-
{IDAnimal: 15, Type:'Hosses'}
|
|
2327
|
-
];
|
|
2328
|
-
_MockSessionValidUser.UserRoleIndex = 2;
|
|
2329
|
-
libSuperTest('http://localhost:9080/')
|
|
2330
|
-
.put('1.0/FableTests')
|
|
2331
|
-
.send(tmpRecords)
|
|
2332
|
-
.end(
|
|
2333
|
-
function(pError, pResponse)
|
|
2334
|
-
{
|
|
2335
|
-
// Expect response to be the record we just created.
|
|
2336
|
-
var tmpResult = JSON.parse(pResponse.text);
|
|
2337
|
-
//console.log(JSON.stringify(tmpResult,null,4));
|
|
2338
|
-
Expect(tmpResult[3].Type).to.equal('Hosses');
|
|
2339
|
-
fDone();
|
|
2340
|
-
}
|
|
2341
|
-
);
|
|
2342
|
-
}
|
|
2343
|
-
);
|
|
2344
|
-
test
|
|
2345
|
-
(
|
|
2346
|
-
'invoke readlite: get all records',
|
|
2347
|
-
function(fDone)
|
|
2348
|
-
{
|
|
2349
|
-
_MeadowEndpoints.invokeEndpoint('ReadLiteList', {}, {UserSession: _MockSessionValidUser},
|
|
2350
|
-
function (pError, pResponse)
|
|
2351
|
-
{
|
|
2352
|
-
//console.log(pResponse.body)
|
|
2353
|
-
Expect(pResponse.body)
|
|
2354
|
-
.to.be.an('array');
|
|
2355
|
-
//var tmpResults = JSON.parse(pResponse.text);
|
|
2356
|
-
//Expect(tmpResults.Error).to.contain('authenticated');
|
|
2357
|
-
fDone();
|
|
2358
|
-
}
|
|
2359
|
-
);
|
|
2360
|
-
}
|
|
2361
|
-
);
|
|
2362
|
-
test
|
|
2363
|
-
(
|
|
2364
|
-
'upsert: create a record',
|
|
2365
|
-
function(fDone)
|
|
2366
|
-
{
|
|
2367
|
-
var tmpRecord = {GUIDAnimal:'0xHAXXXX', Name:'Jason', Type:'Tyranosaurus'};
|
|
2368
|
-
_MockSessionValidUser.UserRoleIndex = 2;
|
|
2369
|
-
libSuperTest('http://localhost:9080/')
|
|
2370
|
-
.put('1.0/FableTest/Upsert')
|
|
2371
|
-
.send(tmpRecord)
|
|
2372
|
-
.end(
|
|
2373
|
-
function(pError, pResponse)
|
|
2374
|
-
{
|
|
2375
|
-
// Expect response to be the record we just created.
|
|
2376
|
-
//console.log(pResponse.text)
|
|
2377
|
-
var tmpResult = JSON.parse(pResponse.text);
|
|
2378
|
-
Expect(tmpResult.Type).to.equal('Tyranosaurus');
|
|
2379
|
-
Expect(tmpResult.CreatingIDUser).to.equal(10);
|
|
2380
|
-
fDone();
|
|
2381
|
-
}
|
|
2382
|
-
);
|
|
2383
|
-
}
|
|
2384
|
-
);
|
|
2385
|
-
test
|
|
2386
|
-
(
|
|
2387
|
-
'upsert: Update a record',
|
|
2388
|
-
function(fDone)
|
|
2389
|
-
{
|
|
2390
|
-
var tmpRecord = {GUIDAnimal:'0xHAXXXX', Type:'Stegosaurus'};
|
|
2391
|
-
_MockSessionValidUser.UserRoleIndex = 2;
|
|
2392
|
-
libSuperTest('http://localhost:9080/')
|
|
2393
|
-
.put('1.0/FableTest/Upsert')
|
|
2394
|
-
.send(tmpRecord)
|
|
2395
|
-
.end(
|
|
2396
|
-
function(pError, pResponse)
|
|
2397
|
-
{
|
|
2398
|
-
// Expect response to be the record we just created.
|
|
2399
|
-
console.log(pResponse.text)
|
|
2400
|
-
var tmpResult = JSON.parse(pResponse.text);
|
|
2401
|
-
Expect(tmpResult.Type).to.equal('Stegosaurus');
|
|
2402
|
-
Expect(tmpResult.Name).to.equal('Jason');
|
|
2403
|
-
fDone();
|
|
2404
|
-
}
|
|
2405
|
-
);
|
|
2406
|
-
}
|
|
2407
|
-
);
|
|
2408
|
-
test
|
|
2409
|
-
(
|
|
2410
|
-
'bulk upserts',
|
|
2411
|
-
function(fDone)
|
|
2412
|
-
{
|
|
2413
|
-
_MeadowEndpoints.behaviorModifications.setTemplate('SelectList', '<%= Record.Name %>|<%=Record.Type%>');
|
|
2414
|
-
var tmpRecords = [
|
|
2415
|
-
{GUIDAnimal:'0xHAXXXX', Type:'Triceratops'},
|
|
2416
|
-
{GUIDAnimal:'0xDavison', Name:'Davison', Type:'Dog'},
|
|
2417
|
-
{GUIDAnimal:'0xMartino', Name:'Martin', Type:'Dog'},
|
|
2418
|
-
{Name:'Chino', Type:'Cat'}
|
|
2419
|
-
];
|
|
2420
|
-
_MockSessionValidUser.UserRoleIndex = 2;
|
|
2421
|
-
libSuperTest('http://localhost:9080/')
|
|
2422
|
-
.put('1.0/FableTest/Upserts')
|
|
2423
|
-
.send(tmpRecords)
|
|
2424
|
-
.end(
|
|
2425
|
-
function(pError, pResponse)
|
|
2426
|
-
{
|
|
2427
|
-
// Expect response to be the record we just created.
|
|
2428
|
-
var tmpResult = JSON.parse(pResponse.text);
|
|
2429
|
-
console.log(JSON.stringify(tmpResult,null,4));
|
|
2430
|
-
Expect(tmpResult[0].Value).to.equal('Jason|Triceratops');
|
|
2431
|
-
Expect(tmpResult[1].Value).to.equal('Davison|Dog');
|
|
2432
|
-
Expect(tmpResult[2].Value).to.equal('Martin|Dog');
|
|
2433
|
-
Expect(tmpResult[3].Value).to.equal('Chino|Cat');
|
|
2434
109
|
fDone();
|
|
2435
110
|
}
|
|
2436
111
|
);
|
|
@@ -2439,4 +114,4 @@ suite
|
|
|
2439
114
|
}
|
|
2440
115
|
);
|
|
2441
116
|
}
|
|
2442
|
-
);
|
|
117
|
+
);
|