Skip to content

Commit 2faa41f

Browse files
adding skipNameCheck for a composable function workaround #168
1 parent 69865fe commit 2faa41f

File tree

6 files changed

+46
-6
lines changed

6 files changed

+46
-6
lines changed

.github/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,7 @@ queryParams | Array | `retrieveMultipleRequest`, `retrieveAllRequest` | `v.1.7.7
305305
returnRepresentation | Boolean | `createRequest`, `updateRequest`, `upsertRequest` | Sets Prefer header request with value "return=representation". Use this property to return just created or updated entity in a single request.
306306
savedQuery | String | `retrieveRequest` | A String representing the GUID value of the saved query.
307307
select | Array | `retrieveRequest`, `retrieveMultipleRequest`, `retrieveAllRequest`, `updateRequest`, `upsertRequest` | An Array (of Strings) representing the $select OData System Query Option to control which attributes will be returned.
308+
skipNameCheck | Boolean | All | `v.1.7.12+` Skips the collection name check in DynamicsWebApi. Helpful when the collection name should stay the same in the URL as it was set in the request.
308309
timeout | Number | All | `v.1.6.10+` Sets a number of milliseconds before a request times out.
309310
token | String | All | Authorization Token. If set, onTokenRefresh will not be called.
310311
top | Number | `retrieveMultipleRequest`, `retrieveAllRequest` | Limit the number of results returned by using the $top system query option. Do not use $top with $count!

lib/requests/sendRequest.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -387,9 +387,8 @@ function _isEntityNameException(entityName) {
387387
return exceptions.indexOf(entityName) > -1;
388388
}
389389

390-
function _checkCollectionName(entityName, config, successCallback, errorCallback) {
391-
392-
if (_isEntityNameException(entityName) || Utility.isNull(entityName)) {
390+
function _checkCollectionName(entityName, config, skipNameCheck, successCallback, errorCallback) {
391+
if (!!skipNameCheck || _isEntityNameException(entityName) || Utility.isNull(entityName)) {
393392
successCallback(entityName);
394393
return;
395394
}
@@ -427,7 +426,7 @@ function makeRequest(method, request, functionName, config, responseParams, reso
427426
RequestConverter.convertRequest(request, functionName, config);
428427
}
429428
else {
430-
_checkCollectionName(request.collection, config, function (collectionName) {
429+
_checkCollectionName(request.collection, config, request.skipNameCheck, function (collectionName) {
431430
request.collection = collectionName;
432431
var result = RequestConverter.convertRequest(request, functionName, config);
433432
var requestId = request.requestId;

lib/utilities/RequestConverter.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,7 @@ function convertRequestOptions(request, functionName, url, joinSymbol, config) {
274274
function convertRequest(request, functionName, config) {
275275
var url = "";
276276
var result;
277+
277278
if (!request.url) {
278279
if (!request._unboundRequest && !request.collection) {
279280
ErrorHelper.parameterCheck(request.collection, "DynamicsWebApi." + functionName, "request.collection");
@@ -328,6 +329,7 @@ function convertRequest(request, functionName, config) {
328329
result.async = true;
329330
}
330331

332+
331333
return { url: result.url, headers: result.headers, async: result.async };
332334
}
333335

tests/main-tests.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1627,6 +1627,40 @@ describe("promises -", function () {
16271627
});
16281628
});
16291629

1630+
describe("unbound - composable (skipNameCheck)", function () {
1631+
var scope;
1632+
before(function () {
1633+
var response = mocks.responses.response200;
1634+
scope = nock(mocks.webApiUrl)
1635+
.get("/FUN(param1=@p1)?$select=something&@p1=0000")
1636+
.reply(response.status, response.responseText, response.responseHeaders);
1637+
});
1638+
1639+
after(function () {
1640+
nock.cleanAll();
1641+
});
1642+
1643+
it("(with parameters) returns a correct response", function (done) {
1644+
dynamicsWebApiTest.retrieveRequest({
1645+
collection: "FUN",
1646+
key: "param1=@p1",
1647+
select: ["something"],
1648+
queryParams: ["@p1=0000"],
1649+
skipNameCheck: true
1650+
}).then(function (object) {
1651+
expect(object).to.deep.equal(mocks.data.testEntity);
1652+
done();
1653+
})
1654+
.catch(function (object) {
1655+
done(object);
1656+
});
1657+
});
1658+
1659+
it("all requests have been made", function () {
1660+
expect(scope.isDone()).to.be.true;
1661+
});
1662+
});
1663+
16301664
describe("bound", function () {
16311665
var scope;
16321666
before(function () {

types/dynamics-web-api-callbacks.d.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Type definitions for dynamics-web-api-callbacks v1.7.11
1+
// Type definitions for dynamics-web-api-callbacks v1.7.12
22
// Project: https://github.com/AleksandrRogov/DynamicsWebApi
33
// Definitions by: Aleksandr Rogov https://github.com/AleksandrRogov/
44

@@ -876,6 +876,8 @@ declare namespace DynamicsWebApi {
876876
interface Request extends RequestBase {
877877
/**The name of the Entity Collection or Entity Logical name. */
878878
collection?: string;
879+
/**Skips the collection name check in DynamicsWebApi */
880+
skipNameCheck?: boolean;
879881
}
880882

881883
interface CRUDRequest extends Request {

types/dynamics-web-api.d.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Type definitions for dynamics-web-api v1.7.11
1+
// Type definitions for dynamics-web-api v1.7.12
22
// Project: https://github.com/AleksandrRogov/DynamicsWebApi/
33
// Definitions by: Aleksandr Rogov https://github.com/AleksandrRogov/
44

@@ -564,6 +564,8 @@ declare namespace DynamicsWebApi {
564564
interface Request extends RequestBase {
565565
/**The name of the Entity Collection or Entity Logical name. */
566566
collection?: string;
567+
/**Skips the collection name check in DynamicsWebApi */
568+
skipNameCheck?: boolean;
567569
}
568570

569571
interface CRUDRequest extends Request {

0 commit comments

Comments
 (0)