Skip to content

Commit 85ce46a

Browse files
authored
fix: Proper return type for v2 unbound action (#970)
1 parent 9e23954 commit 85ce46a

File tree

5 files changed

+28
-8
lines changed

5 files changed

+28
-8
lines changed

.changeset/lazy-oranges-approve.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@sap-ux/fe-mockserver-core': patch
3+
---
4+
5+
Proper return type for v2 unbound action

packages/fe-mockserver-core/src/data/dataAccess.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,7 @@ export class DataAccess implements DataAccessInterface {
251251
if (actionDefinition) {
252252
if (actionDefinition.sourceType !== '') {
253253
const targetEntitySet = this.metadata.getEntitySetByType(actionDefinition.sourceType);
254+
const returnEntitySet = this.metadata.getEntitySetByType(actionDefinition.returnType);
254255
if (targetEntitySet) {
255256
if (actionData) {
256257
actionData._type = actionDefinition.name;
@@ -272,10 +273,10 @@ export class DataAccess implements DataAccessInterface {
272273
// Enrich data with __metadata for v2
273274
if (Array.isArray(outData)) {
274275
outData = outData.map((element) => {
275-
return enrichElement(targetEntitySet, element);
276+
return enrichElement(returnEntitySet ?? targetEntitySet, element);
276277
});
277278
} else if (outData != null) {
278-
outData = enrichElement(targetEntitySet, outData);
279+
outData = enrichElement(returnEntitySet ?? targetEntitySet, outData);
279280
}
280281
}
281282
return outData;

packages/fe-mockserver-core/test/unit/v2/__snapshots__/functionImport.test.ts.snap

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,25 @@ exports[`Function Import are parsed properly 1`] = `
99
]
1010
`;
1111

12+
exports[`Function Import are parsed properly 2`] = `
13+
[
14+
{
15+
"CommentMandatory": false,
16+
"DecisionKey": "Approve",
17+
"DecisionText": "Approve",
18+
"InstanceID": "'000007298690'",
19+
"Nature": "POSITIVE",
20+
},
21+
{
22+
"CommentMandatory": true,
23+
"DecisionKey": "Reject",
24+
"DecisionText": "Reject",
25+
"InstanceID": "'000007298690'",
26+
"Nature": "NEGATIVE",
27+
},
28+
]
29+
`;
30+
1231
exports[`Function Import will fail by default 1`] = `
1332
[
1433
{

packages/fe-mockserver-core/test/unit/v2/functionImport.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ describe('Function Import', () => {
5555
expect(request.queryPath).toMatchSnapshot();
5656
const actionData = await dataAccess.performAction(request);
5757
expect(actionData).toBeTruthy();
58+
expect(actionData).toMatchSnapshot();
5859
});
5960

6061
test('will fail by default', async () => {

packages/fe-mockserver-core/test/unit/v2/services/FunctionImport/EntityContainer.js

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,13 @@ module.exports = {
44
var instanceID = odataRequest.allParams.get('InstanceID').replace(/''/g, '');
55
return [
66
{
7-
__metadata: {
8-
type: 'TASKPROCESSING.DecisionOption'
9-
},
107
InstanceID: instanceID,
118
DecisionKey: 'Approve',
129
DecisionText: 'Approve',
1310
CommentMandatory: false,
1411
Nature: 'POSITIVE'
1512
},
1613
{
17-
__metadata: {
18-
type: 'TASKPROCESSING.DecisionOption'
19-
},
2014
InstanceID: instanceID,
2115
DecisionKey: 'Reject',
2216
DecisionText: 'Reject',

0 commit comments

Comments
 (0)