meadow-endpoints 2.0.20 → 2.0.22

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "meadow-endpoints",
3
- "version": "2.0.20",
3
+ "version": "2.0.22",
4
4
  "description": "Automatic API endpoints for Meadow data.",
5
5
  "main": "source/Meadow-Endpoints.js",
6
6
  "scripts": {
@@ -43,7 +43,7 @@ var doAPIDeleteEndpoint = function(pRequest, pResponse, fNext)
43
43
  tmpIDRecord = pRequest.body[pRequest.DAL.defaultIdentifier];
44
44
  }
45
45
  // Although the delete request does allow multiple deletes, we require an identifier.
46
- if (tmpIDRecord < 1)
46
+ if (!parseInt(tmpIDRecord) || tmpIDRecord < 1)
47
47
  {
48
48
  return pRequest.CommonServices.sendError('Record delete failure - a valid record ID is required in the passed-in record.', pRequest, pResponse, fNext);
49
49
  }
@@ -41,7 +41,7 @@ var doAPIUpdateEndpoint = function(pRequest, pResponse, fNext)
41
41
  {
42
42
  return pRequest.CommonServices.sendError('Record update failure - a valid record is required.', pRequest, pResponse, fNext);
43
43
  }
44
- if (pRequest.body[pRequest.DAL.defaultIdentifier] < 1)
44
+ if (!parseInt(pRequest.body[pRequest.DAL.defaultIdentifier]) || pRequest.body[pRequest.DAL.defaultIdentifier] < 1)
45
45
  {
46
46
  return pRequest.CommonServices.sendError('Record update failure - a valid record ID is required in the passed-in record.', pRequest, pResponse, fNext);
47
47
  }
@@ -30,7 +30,8 @@ var marshalLiteList = (pRecords, pRequest, pFieldList) =>
30
30
  {
31
31
  if (pField.indexOf('ID') === 0 ||
32
32
  pField.indexOf('GUID') === 0 ||
33
- pField == 'CreatingIDUser') //we should always include owner info
33
+ pField == 'CreatingIDUser' || // we should always include owner info
34
+ pField == 'Error') // we should propagate errors through (ex. bulk upsert)
34
35
  {
35
36
  tmpFieldList.push(pField);
36
37
  }
@@ -18,7 +18,7 @@ var doUpdate = function(pRecordToModify, pRequest, pResponse, fCallback, pOption
18
18
  pRequest.MeadowOperation = (typeof(pRequest.MeadowOperation) === 'string') ? pRequest.MeadowOperation : 'Update';
19
19
 
20
20
  // If there is not a default identifier or cached record, fail
21
- if ((pRecordToModify[pRequest.DAL.defaultIdentifier] < 1) && (typeof(pOptionalCachedUpdatingRecord) === 'undefined'))
21
+ if ((!parseInt(pRecordToModify[pRequest.DAL.defaultIdentifier]) || pRecordToModify[pRequest.DAL.defaultIdentifier] < 1) && (typeof(pOptionalCachedUpdatingRecord) === 'undefined'))
22
22
  {
23
23
  return fCallback('Record update failure - a valid record ID is required in the passed-in record.');
24
24
  }
@@ -111,7 +111,7 @@ var doUpdate = function(pRecordToModify, pRequest, pResponse, fCallback, pOption
111
111
  {
112
112
  if (!pRecord)
113
113
  {
114
- return fStageComplete('Error updating a record.');
114
+ return fStageComplete(pError || 'Error updating a record.');
115
115
  }
116
116
 
117
117
  pRequest.Record = pRecord;
@@ -961,6 +961,48 @@ suite
961
961
  }
962
962
  );
963
963
  test
964
+ (
965
+ 'update: update a record with a missing ID',
966
+ function(fDone)
967
+ {
968
+ // Update animal but don't provide ID
969
+ var tmpRecord = { Type:'Corgi' };
970
+ libSuperTest('http://localhost:9080/')
971
+ .del('1.0/FableTest')
972
+ .send(tmpRecord)
973
+ .end(
974
+ function(pError, pResponse)
975
+ {
976
+ // Expect response to be the count of deleted records.
977
+ var tmpResult = JSON.parse(pResponse.text);
978
+ Expect(tmpResult.Error).to.contain('a valid record ID is required');
979
+ fDone();
980
+ }
981
+ );
982
+ }
983
+ );
984
+ test
985
+ (
986
+ 'update: update a record with a malformed ID',
987
+ function(fDone)
988
+ {
989
+ // Update animal but don't provide ID
990
+ var tmpRecord = { IDAnimal: { ID: 3 }, Type:'Corgi' };
991
+ libSuperTest('http://localhost:9080/')
992
+ .del('1.0/FableTest')
993
+ .send(tmpRecord)
994
+ .end(
995
+ function(pError, pResponse)
996
+ {
997
+ // Expect response to be the count of deleted records.
998
+ var tmpResult = JSON.parse(pResponse.text);
999
+ Expect(tmpResult.Error).to.contain('a valid record ID is required');
1000
+ fDone();
1001
+ }
1002
+ );
1003
+ }
1004
+ );
1005
+ test
964
1006
  (
965
1007
  'update: update a record',
966
1008
  function(fDone)
@@ -1006,7 +1048,28 @@ suite
1006
1048
  );
1007
1049
  test
1008
1050
  (
1009
- 'delete: delete a record with a bad parameter',
1051
+ 'delete: delete a record with a missing ID',
1052
+ function(fDone)
1053
+ {
1054
+ // Delete animal but don't provide ID
1055
+ var tmpRecord = { Type: 'Corgi' };
1056
+ libSuperTest('http://localhost:9080/')
1057
+ .del('1.0/FableTest')
1058
+ .send(tmpRecord)
1059
+ .end(
1060
+ function(pError, pResponse)
1061
+ {
1062
+ // Expect response to be the count of deleted records.
1063
+ var tmpResult = JSON.parse(pResponse.text);
1064
+ Expect(tmpResult.Error).to.contain('a valid record ID is required');
1065
+ fDone();
1066
+ }
1067
+ );
1068
+ }
1069
+ );
1070
+ test
1071
+ (
1072
+ 'delete: delete a record with a bad ID',
1010
1073
  function(fDone)
1011
1074
  {
1012
1075
  // Delete animal 3 ("Red")
@@ -2433,6 +2496,35 @@ suite
2433
2496
  );
2434
2497
  }
2435
2498
  );
2499
+ test
2500
+ (
2501
+ 'problematic bulk upserts',
2502
+ function(fDone)
2503
+ {
2504
+ _MeadowEndpoints.behaviorModifications.setTemplate('SelectList', '<%= Record.Name %>|<%=Record.Type%>');
2505
+ var tmpRecords = [
2506
+ {GUIDAnimal:'0xHAXXXX', TypeOh:'Triceratops'},
2507
+ {GUIDAnimal:'0xDavison', Nameology:'Davison', Type:'Dog'},
2508
+ {GUIDAnimal:'0xMartino', Name:'Martin', Type:'Dog'}, // this one still works
2509
+ ];
2510
+ _MockSessionValidUser.UserRoleIndex = 2;
2511
+ libSuperTest('http://localhost:9080/')
2512
+ .put('1.0/FableTest/Upserts')
2513
+ .send(tmpRecords)
2514
+ .end(
2515
+ function(pError, pResponse)
2516
+ {
2517
+ // Expect response to be the record we just created.
2518
+ var tmpResult = JSON.parse(pResponse.text);
2519
+ console.log(JSON.stringify(tmpResult,null,4));
2520
+ Expect(tmpResult[0].Error).to.be.a('string');
2521
+ Expect(tmpResult[1].Error).to.be.a('string');
2522
+ Expect(tmpResult[2].Error).to.not.exist;
2523
+ fDone();
2524
+ }
2525
+ );
2526
+ }
2527
+ );
2436
2528
  }
2437
2529
  );
2438
2530
  }