Skip to content

Commit b1cbc11

Browse files
fix parse formatted values for expand objects
1 parent c5cdcc4 commit b1cbc11

File tree

3 files changed

+44
-8
lines changed

3 files changed

+44
-8
lines changed

lib/requests/helpers/parseResponse.js

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,16 @@ function parseData(object, parseParams) {
6565
for (var i = 0; i < keys.length; i++) {
6666
var currentKey = keys[i];
6767

68-
if (object[currentKey] != null && object[currentKey].constructor === Array) {
69-
for (var j = 0; j < object[currentKey].length; j++) {
70-
object[currentKey][j] = parseData(object[currentKey][j]);
71-
}
72-
}
68+
if (object[currentKey] != null) {
69+
if (object[currentKey].constructor === Array) {
70+
for (var j = 0; j < object[currentKey].length; j++) {
71+
object[currentKey][j] = parseData(object[currentKey][j]);
72+
}
73+
}
74+
else if (typeof (object[currentKey]) === "object") {
75+
parseData(object[currentKey]);
76+
}
77+
}
7378

7479
//parse formatted values
7580
var formattedKeyValue = getFormattedKeyValue(currentKey, object[currentKey]);

tests/common-tests.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2065,6 +2065,11 @@ describe("parseResponse", function () {
20652065
expect(response).to.be.deep.equal(mocks.responses.responseFormattedEntity());
20662066
});
20672067

2068+
it("parses formatted values - expand formatted values", function () {
2069+
var response = parseResponse(mocks.responses.responseFormattedWithExpand200.responseText, [], [{}]);
2070+
expect(response).to.be.deep.equal(mocks.responses.responseFormattedEntityWithExpand());
2071+
});
2072+
20682073
it("parses formatted values - array", function () {
20692074
var response = parseResponse(mocks.responses.multipleFormattedResponse.responseText, [], [{}]);
20702075
expect(response).to.be.deep.equal(mocks.responses.multipleFormatted());

tests/stubs.js

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,20 @@ var dataStubs = {
4949
"[email protected]": "formatted",
5050
"[email protected]": "formatted",
5151
"[email protected]": "formatted"
52-
},
52+
},
53+
testEntityFormattedWithExpand: {
54+
name: "record",
55+
subject: "test",
56+
option: "value",
57+
dwa_NavigationProperty: {
58+
optionProp: "value",
59+
"[email protected]": "formatted"
60+
},
61+
"@odata.context": "context",
62+
"[email protected]": "formatted",
63+
"[email protected]": "formatted",
64+
"[email protected]": "formatted"
65+
},
5366
testEntityFormattedAliased: {
5467
name: "record",
5568
subject: "test",
@@ -568,7 +581,11 @@ var responseStubs = {
568581
responseFormatted200: {
569582
status: 200,
570583
responseText: JSON.stringify(dataStubs.testEntityFormatted)
571-
},
584+
},
585+
responseFormattedWithExpand200: {
586+
status: 200,
587+
responseText: JSON.stringify(dataStubs.testEntityFormattedWithExpand)
588+
},
572589
responseFormattedAliased200: {
573590
status: 200,
574591
responseText: JSON.stringify(dataStubs.testEntityFormattedAliased)
@@ -973,7 +990,16 @@ var responseStubs = {
973990
stub.option_NavigationProperty = stub["[email protected]"];
974991
stub.option_LogicalName = stub["[email protected]"];
975992
return stub;
976-
},
993+
},
994+
responseFormattedEntityWithExpand: function () {
995+
var stub = dataStubs.testEntityFormattedWithExpand;
996+
stub.oDataContext = stub["@odata.context"];
997+
stub.dwa_NavigationProperty.optionProp_Formatted = stub.dwa_NavigationProperty["[email protected]"];
998+
stub.option_Formatted = stub["[email protected]"];
999+
stub.option_NavigationProperty = stub["[email protected]"];
1000+
stub.option_LogicalName = stub["[email protected]"];
1001+
return stub;
1002+
},
9771003
responseFormattedAliasedEntity: function () {
9781004
var stub = dataStubs.testEntityFormattedAliased;
9791005
stub.oDataContext = stub["@odata.context"];

0 commit comments

Comments
 (0)