@sap_oss/wdio-qmate-service 1.0.0 → 1.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/README.md +2 -1
- package/{test/core/package-lock.json → docs/bestPractices/spec.md} +0 -0
- package/docs/doc.md +176 -353
- package/docs/gettingStarted/setup.md +2 -2
- package/docs/index.md +1 -1
- package/docs/sections/bestPractices/authentication.md +151 -0
- package/docs/sections/bestPractices/dataHandling.md +61 -0
- package/docs/sections/bestPractices/selectors.md +44 -0
- package/docs/{contact.md → sections/contact.md} +0 -0
- package/docs/sections/features/advancedDataHandling.md +252 -0
- package/docs/sections/features/config.md +171 -0
- package/docs/sections/features/dataHandling.md +83 -0
- package/docs/{gettingStarted → sections/features}/selectors.md +0 -0
- package/docs/sections/features/spec.md +0 -0
- package/docs/sections/gettingStarted/config.md +18 -0
- package/docs/sections/gettingStarted/execution.md +7 -0
- package/docs/sections/gettingStarted/setup.md +9 -0
- package/docs/sections/gettingStarted/spec.md +31 -0
- package/docs/sections/gettingStarted/specs.md +19 -0
- package/docs/sections/support/bugReporting.md +19 -0
- package/docs/sections/support/knownIssuesAndLimitations.md +0 -0
- package/docs/sections/support/troubleshooting.md +16 -0
- package/docs/sources/images/fiori_form.PNG +0 -0
- package/docs/sources/images/sapCloud_form.PNG +0 -0
- package/lib/index.js +59 -82
- package/lib/index.js.map +1 -1
- package/lib/reuse/authenticator/authHandler.js +12 -23
- package/lib/reuse/authenticator/authHandler.js.map +1 -1
- package/lib/reuse/authenticator/basicUrlAuthenticator.js +21 -32
- package/lib/reuse/authenticator/basicUrlAuthenticator.js.map +1 -1
- package/lib/reuse/authenticator/customAuthenticator.js +42 -55
- package/lib/reuse/authenticator/customAuthenticator.js.map +1 -1
- package/lib/reuse/authenticator/formAuthenticator.js +37 -50
- package/lib/reuse/authenticator/formAuthenticator.js.map +1 -1
- package/lib/reuse/authenticator/plainAuthenticator.js +5 -16
- package/lib/reuse/authenticator/plainAuthenticator.js.map +1 -1
- package/lib/reuse/helper/jsDocGen.js +4 -12
- package/lib/reuse/helper/jsDocGen.js.map +1 -1
- package/lib/reuse/index.js +20 -5
- package/lib/reuse/index.js.map +1 -1
- package/lib/reuse/modules/common/navigation.js +10 -23
- package/lib/reuse/modules/common/navigation.js.map +1 -1
- package/lib/reuse/modules/common/userInteraction.js +40 -73
- package/lib/reuse/modules/common/userInteraction.js.map +1 -1
- package/lib/reuse/modules/nonUi5/assertion.js +31 -52
- package/lib/reuse/modules/nonUi5/assertion.js.map +1 -1
- package/lib/reuse/modules/nonUi5/element.js +266 -331
- package/lib/reuse/modules/nonUi5/element.js.map +1 -1
- package/lib/reuse/modules/nonUi5/navigation.js +10 -21
- package/lib/reuse/modules/nonUi5/navigation.js.map +1 -1
- package/lib/reuse/modules/nonUi5/userInteraction.js +176 -215
- package/lib/reuse/modules/nonUi5/userInteraction.js.map +1 -1
- package/lib/reuse/modules/service/odata.d.ts +106 -94
- package/lib/reuse/modules/service/odata.js +209 -204
- package/lib/reuse/modules/service/odata.js.map +1 -1
- package/lib/reuse/modules/service/rest.js +64 -81
- package/lib/reuse/modules/service/rest.js.map +1 -1
- package/lib/reuse/modules/ui5/assertion.js +217 -268
- package/lib/reuse/modules/ui5/assertion.js.map +1 -1
- package/lib/reuse/modules/ui5/confirmationDialog.js +17 -42
- package/lib/reuse/modules/ui5/confirmationDialog.js.map +1 -1
- package/lib/reuse/modules/ui5/control.js +12 -33
- package/lib/reuse/modules/ui5/control.js.map +1 -1
- package/lib/reuse/modules/ui5/date.js +70 -89
- package/lib/reuse/modules/ui5/date.js.map +1 -1
- package/lib/reuse/modules/ui5/element.js +121 -156
- package/lib/reuse/modules/ui5/element.js.map +1 -1
- package/lib/reuse/modules/ui5/errorDialog.js +4 -17
- package/lib/reuse/modules/ui5/errorDialog.js.map +1 -1
- package/lib/reuse/modules/ui5/footerBar.js +28 -63
- package/lib/reuse/modules/ui5/footerBar.js.map +1 -1
- package/lib/reuse/modules/ui5/mockserver.js +390 -427
- package/lib/reuse/modules/ui5/mockserver.js.map +1 -1
- package/lib/reuse/modules/ui5/navigation.js +105 -132
- package/lib/reuse/modules/ui5/navigation.js.map +1 -1
- package/lib/reuse/modules/ui5/navigationBar.js +58 -77
- package/lib/reuse/modules/ui5/navigationBar.js.map +1 -1
- package/lib/reuse/modules/ui5/qunit.js +16 -27
- package/lib/reuse/modules/ui5/qunit.js.map +1 -1
- package/lib/reuse/modules/ui5/session.js +200 -236
- package/lib/reuse/modules/ui5/session.js.map +1 -1
- package/lib/reuse/modules/ui5/table.js +79 -98
- package/lib/reuse/modules/ui5/table.js.map +1 -1
- package/lib/reuse/modules/ui5/userInteraction.js +264 -335
- package/lib/reuse/modules/ui5/userInteraction.js.map +1 -1
- package/lib/reuse/modules/util/browser.js +131 -178
- package/lib/reuse/modules/util/browser.js.map +1 -1
- package/lib/reuse/modules/util/data.js +3 -2
- package/lib/reuse/modules/util/data.js.map +1 -1
- package/lib/reuse/modules/util/file.js +71 -90
- package/lib/reuse/modules/util/file.js.map +1 -1
- package/lib/reuse/modules/util/function.js +68 -87
- package/lib/reuse/modules/util/function.js.map +1 -1
- package/lib/reuse/modules/util/system.js +22 -33
- package/lib/reuse/modules/util/system.js.map +1 -1
- package/lib/scripts/dataExchange/dataExchange.js +145 -160
- package/lib/scripts/dataExchange/dataExchange.js.map +1 -1
- package/lib/scripts/dataExchange/dataExchangeUtil.js +93 -114
- package/lib/scripts/dataExchange/dataExchangeUtil.js.map +1 -1
- package/lib/scripts/hooks/after.js +3 -14
- package/lib/scripts/hooks/after.js.map +1 -1
- package/lib/scripts/hooks/before.js +9 -20
- package/lib/scripts/hooks/before.js.map +1 -1
- package/lib/scripts/hooks/beforeSession.js +7 -18
- package/lib/scripts/hooks/beforeSession.js.map +1 -1
- package/lib/scripts/hooks/onComplete.js +2 -13
- package/lib/scripts/hooks/onComplete.js.map +1 -1
- package/lib/scripts/hooks/onPrepare.js +9 -20
- package/lib/scripts/hooks/onPrepare.js.map +1 -1
- package/lib/scripts/hooks/utils/addLocatorCommands.js +109 -172
- package/lib/scripts/hooks/utils/addLocatorCommands.js.map +1 -1
- package/lib/scripts/hooks/utils/browserLog.js +18 -31
- package/lib/scripts/hooks/utils/browserLog.js.map +1 -1
- package/lib/scripts/hooks/utils/dataExchangeCommands.js +13 -24
- package/lib/scripts/hooks/utils/dataExchangeCommands.js.map +1 -1
- package/lib/scripts/hooks/utils/decryption.d.ts +1 -1
- package/lib/scripts/hooks/utils/decryption.js +33 -14
- package/lib/scripts/hooks/utils/decryption.js.map +1 -1
- package/lib/scripts/hooks/utils/lib.js +249 -272
- package/lib/scripts/hooks/utils/lib.js.map +1 -1
- package/lib/scripts/hooks/utils/locatorCommands.js +154 -183
- package/lib/scripts/hooks/utils/locatorCommands.js.map +1 -1
- package/mkdocs.yml +16 -3
- package/package.json +14 -11
- package/test/authenticator/staticLogin/specs/custom.spec.js +30 -1
- package/test/reuse/nonUi5/element/getById.spec.js +17 -0
- package/test/reuse/service/odata/get.spec.js +61 -0
- package/test/reuse/service/odata/getEntitySet.spec.js +87 -0
- package/test/reuse/service/odata/test.odata.conf.js +15 -0
- package/test/reuse/ui5/confirmationDialog/clickButton.spec.js +87 -0
- package/test/reuse/ui5/confirmationDialog/test.confirmationDialog.conf.js +2 -1
- package/test/reuse/ui5/element/test.element.conf.js +2 -1
- package/test/reuse/ui5/element/waitForAll.spec.js +46 -0
- package/test/reuse/ui5/userInteraction/clearAndFillSmartFieldInputAndRetry.spec.js +28 -0
- package/test/reuse/ui5/userInteraction/test.userInteraction.conf.js +1 -0
- package/test/reuse/util/browser/switchToNewWindow.spec.js +2 -2
- package/test/reuse/util/console/console.spec.js +27 -0
- package/test/reuse/util/console/test.console.conf.js +12 -0
- package/test/reuse/util/data/data/test.secure.json +7 -3
- package/test/reuse/util/data/getSecureData.spec.js +9 -3
- package/test/reuse/util/file/pdfParser.spec.js +33 -8
- package/test/reuse/util/system/system.spec.js +16 -0
- package/test/reuse/util/system/test.system.conf.js +12 -0
- package/tsconfig.json +1 -1
|
@@ -4,15 +4,6 @@
|
|
|
4
4
|
// E.g. `await lib.mockServerActionInBrowser(function (mockserver, method, fnAfterCallbackAsString, oParams, done){...})`
|
|
5
5
|
// It is not required to check the type (function or string) - toString() function can be applied to a string too.
|
|
6
6
|
"use strict";
|
|
7
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
8
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
9
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
10
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
11
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
12
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
13
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
14
|
-
});
|
|
15
|
-
};
|
|
16
7
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
8
|
exports.Mockserver = void 0;
|
|
18
9
|
/**
|
|
@@ -31,10 +22,8 @@ class Mockserver {
|
|
|
31
22
|
* @param {Integer} interval - The intervals to use when waiting UI5 to load.
|
|
32
23
|
* @example await ui5.mockserver.waitForUi5ApplicationLoad(100);
|
|
33
24
|
*/
|
|
34
|
-
waitForUi5ApplicationLoad(interval = 100) {
|
|
35
|
-
|
|
36
|
-
yield this.lib.waitUI5ToStabilize(); // Note: interval is hardcoded in lib.js
|
|
37
|
-
});
|
|
25
|
+
async waitForUi5ApplicationLoad(interval = 100) {
|
|
26
|
+
await this.lib.waitUI5ToStabilize(); // Note: interval is hardcoded in lib.js
|
|
38
27
|
}
|
|
39
28
|
;
|
|
40
29
|
/**
|
|
@@ -47,12 +36,10 @@ class Mockserver {
|
|
|
47
36
|
* @param {String} oParams - Additional parameters you would like to inject in your client script function
|
|
48
37
|
* @example await ui5.mockserver.interactWithMockServer("path/to/project/localService/main/mockserver", fnCallback, oParams);
|
|
49
38
|
*/
|
|
50
|
-
interactWithMockServer(mockServerPath, fnCallback, oParams) {
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
return yield ui5.mockserver.waitForUi5ApplicationLoad();
|
|
55
|
-
});
|
|
39
|
+
async interactWithMockServer(mockServerPath, fnCallback, oParams) {
|
|
40
|
+
// fnCallback-> function(mockServerInstance, oParams, done){...}
|
|
41
|
+
await this.lib.mockServerActionInBrowser(fnCallback, mockServerPath, oParams);
|
|
42
|
+
return await ui5.mockserver.waitForUi5ApplicationLoad();
|
|
56
43
|
}
|
|
57
44
|
;
|
|
58
45
|
/**
|
|
@@ -65,22 +52,20 @@ class Mockserver {
|
|
|
65
52
|
* @param {Object} oParams - Additional parameters you would like to inject in your client script function
|
|
66
53
|
* @example await ui5.mockserver.attachFunctionBefore("GET", "path/to/project/localService/main/mockserver", fnBeforeCallback, oParams);
|
|
67
54
|
*/
|
|
68
|
-
attachFunctionBefore(method, mockServerPath, fnBeforeCallback, oParams) {
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
console.error("Mockserver not yet initialized or method getMockServer is missing");
|
|
75
|
-
done();
|
|
76
|
-
}
|
|
77
|
-
const beforeCallback = "beforeCallback = " + fnBeforeCallbackString;
|
|
78
|
-
const fnFunction = eval(beforeCallback);
|
|
79
|
-
mockServerInst.attachBefore(method, fnFunction);
|
|
55
|
+
async attachFunctionBefore(method, mockServerPath, fnBeforeCallback, oParams) {
|
|
56
|
+
const fnBeforeCallbackString = fnBeforeCallback.toString();
|
|
57
|
+
await this.lib.mockServerActionInBrowser(function (mockserver, method, fnBeforeCallbackString, oParams, done) {
|
|
58
|
+
const mockServerInst = mockserver.getMockServer();
|
|
59
|
+
if (!mockServerInst) {
|
|
60
|
+
console.error("Mockserver not yet initialized or method getMockServer is missing");
|
|
80
61
|
done();
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
|
|
62
|
+
}
|
|
63
|
+
const beforeCallback = "beforeCallback = " + fnBeforeCallbackString;
|
|
64
|
+
const fnFunction = eval(beforeCallback);
|
|
65
|
+
mockServerInst.attachBefore(method, fnFunction);
|
|
66
|
+
done();
|
|
67
|
+
}, mockServerPath, method, fnBeforeCallbackString, oParams);
|
|
68
|
+
return await ui5.mockserver.waitForUi5ApplicationLoad();
|
|
84
69
|
}
|
|
85
70
|
;
|
|
86
71
|
/**
|
|
@@ -93,22 +78,20 @@ class Mockserver {
|
|
|
93
78
|
* @param {Object} oParams - Additional parameters you would like to inject in your client script function
|
|
94
79
|
* @example await ui5.mockserver.attachFunctionAfter("GET", "path/to/project/localService/main/mockserver", fnAfterCallback);
|
|
95
80
|
*/
|
|
96
|
-
attachFunctionAfter(method, mockServerPath, fnAfterCallback, oParams) {
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
console.error("Mockserver not yet initialized or method getMockServer is missing");
|
|
103
|
-
done();
|
|
104
|
-
}
|
|
105
|
-
var afterCallback = "afterCallback = " + fnAfterCallbackString;
|
|
106
|
-
var fnFunction = eval(afterCallback);
|
|
107
|
-
mockServerInst.attachAfter(method, fnFunction);
|
|
81
|
+
async attachFunctionAfter(method, mockServerPath, fnAfterCallback, oParams) {
|
|
82
|
+
const fnAfterCallbackString = fnAfterCallback.toString();
|
|
83
|
+
await this.lib.mockServerActionInBrowser(function (mockserver, method, fnAfterCallbackString, oParams, done) {
|
|
84
|
+
var mockServerInst = mockserver.getMockServer();
|
|
85
|
+
if (!mockServerInst) {
|
|
86
|
+
console.error("Mockserver not yet initialized or method getMockServer is missing");
|
|
108
87
|
done();
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
|
|
88
|
+
}
|
|
89
|
+
var afterCallback = "afterCallback = " + fnAfterCallbackString;
|
|
90
|
+
var fnFunction = eval(afterCallback);
|
|
91
|
+
mockServerInst.attachAfter(method, fnFunction);
|
|
92
|
+
done();
|
|
93
|
+
}, mockServerPath, method, fnAfterCallbackString, oParams);
|
|
94
|
+
return await ui5.mockserver.waitForUi5ApplicationLoad();
|
|
112
95
|
}
|
|
113
96
|
;
|
|
114
97
|
/**
|
|
@@ -125,137 +108,135 @@ class Mockserver {
|
|
|
125
108
|
* @param {String} responseLocation - Mocks the location response messages header
|
|
126
109
|
* @example await ui5.mockserver.addNewRequest("GET","path/to/project/localService/main/mockserver", "*.Headers.*", "path/to/project/localService/main/mockdata/test.json", 200, true, JSON.stringify(msg));
|
|
127
110
|
*/
|
|
128
|
-
addNewRequest(method, mockServerPath, urlPathRegex, responseJsonPath, returnCode, isText, responseMessages, responseLocation) {
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
responseData = JSON.stringify(responseJsonPath);
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
catch (error) {
|
|
137
|
-
throw new Error("Something went wrong with the conversion" + error);
|
|
138
|
-
}
|
|
139
|
-
// If undefined dont add any messages
|
|
140
|
-
if (!responseMessages) {
|
|
141
|
-
responseMessages = false;
|
|
111
|
+
async addNewRequest(method, mockServerPath, urlPathRegex, responseJsonPath, returnCode, isText, responseMessages, responseLocation) {
|
|
112
|
+
var responseData = responseJsonPath;
|
|
113
|
+
try {
|
|
114
|
+
if (typeof responseJsonPath !== "string" && typeof responseJsonPath === "object") {
|
|
115
|
+
responseData = JSON.stringify(responseJsonPath);
|
|
142
116
|
}
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
117
|
+
}
|
|
118
|
+
catch (error) {
|
|
119
|
+
throw new Error("Something went wrong with the conversion" + error);
|
|
120
|
+
}
|
|
121
|
+
// If undefined dont add any messages
|
|
122
|
+
if (!responseMessages) {
|
|
123
|
+
responseMessages = false;
|
|
124
|
+
}
|
|
125
|
+
// If undefined dont add any location
|
|
126
|
+
if (!responseLocation) {
|
|
127
|
+
responseLocation = false;
|
|
128
|
+
}
|
|
129
|
+
await this.lib.mockServerActionInBrowser(function (mockserver, method, urlPathRegex, responseJsonPath, responseMessages, responseLocation, returnCode, isText, done) {
|
|
130
|
+
var mockServerInst = mockserver.getMockServer();
|
|
131
|
+
if (!mockServerInst)
|
|
132
|
+
throw new Error("Mockserver not yet initialized or method getMockServer is missing");
|
|
133
|
+
var fnResponse = function (oXhr) {
|
|
134
|
+
// If connection close dont redo response
|
|
135
|
+
if (oXhr.readyState && oXhr.readyState === 4)
|
|
136
|
+
return true;
|
|
137
|
+
var oData = null;
|
|
138
|
+
try {
|
|
139
|
+
if (isText && isText !== "false") {
|
|
140
|
+
oData = responseJsonPath;
|
|
141
|
+
}
|
|
142
|
+
else {
|
|
143
|
+
oData = JSON.parse(responseJsonPath);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
catch (e) {
|
|
147
|
+
if (typeof responseJsonPath === "string" && !RegExp(".?([^\/\s]+\/)(.*)").test(responseJsonPath)) {
|
|
148
|
+
oData = responseJsonPath;
|
|
149
|
+
}
|
|
150
|
+
else {
|
|
157
151
|
if (isText && isText !== "false") {
|
|
158
|
-
|
|
152
|
+
// @ts-ignore
|
|
153
|
+
var oResponse = jQuery.sap.sjax({
|
|
154
|
+
url: responseJsonPath,
|
|
155
|
+
dataType: "text"
|
|
156
|
+
});
|
|
159
157
|
}
|
|
160
158
|
else {
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
oData = responseJsonPath;
|
|
159
|
+
// @ts-ignore
|
|
160
|
+
oResponse = jQuery.sap.sjax({
|
|
161
|
+
url: responseJsonPath,
|
|
162
|
+
dataType: "json"
|
|
163
|
+
});
|
|
167
164
|
}
|
|
168
|
-
|
|
169
|
-
if (isText && isText !== "false") {
|
|
170
|
-
|
|
171
|
-
var oResponse = jQuery.sap.sjax({
|
|
172
|
-
url: responseJsonPath,
|
|
173
|
-
dataType: "text"
|
|
174
|
-
});
|
|
175
|
-
}
|
|
176
|
-
else {
|
|
177
|
-
// @ts-ignore
|
|
178
|
-
oResponse = jQuery.sap.sjax({
|
|
179
|
-
url: responseJsonPath,
|
|
180
|
-
dataType: "json"
|
|
181
|
-
});
|
|
165
|
+
if (oResponse.success) {
|
|
166
|
+
if (isText && isText !== "false" && oResponse.data) {
|
|
167
|
+
oData = oResponse.data;
|
|
182
168
|
}
|
|
183
|
-
if (oResponse.
|
|
184
|
-
if (
|
|
169
|
+
else if (oResponse.data.d) {
|
|
170
|
+
if (oResponse.data.d.results) {
|
|
185
171
|
oData = oResponse.data;
|
|
186
172
|
}
|
|
187
173
|
else if (oResponse.data.d) {
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
}
|
|
191
|
-
else if (oResponse.data.d) {
|
|
192
|
-
// Function Import or single data
|
|
193
|
-
oData = oResponse.data;
|
|
194
|
-
}
|
|
195
|
-
else {
|
|
196
|
-
console.error("The mock data are invalid");
|
|
197
|
-
}
|
|
174
|
+
// Function Import or single data
|
|
175
|
+
oData = oResponse.data;
|
|
198
176
|
}
|
|
199
177
|
else {
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
178
|
+
console.error("The mock data are invalid");
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
else {
|
|
182
|
+
if (Array.isArray(oResponse.data)) {
|
|
183
|
+
oData = oResponse.data;
|
|
184
|
+
}
|
|
185
|
+
else {
|
|
186
|
+
console.error("The mock data could not be loaded due to wrong format!");
|
|
206
187
|
}
|
|
207
188
|
}
|
|
208
189
|
}
|
|
209
190
|
}
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
191
|
+
}
|
|
192
|
+
var resHeader = {};
|
|
193
|
+
resHeader["content-encoding"] = "identity";
|
|
194
|
+
// @ts-ignore
|
|
195
|
+
let parsedReturnCode = parseInt(returnCode);
|
|
196
|
+
if (isNaN(parsedReturnCode)) {
|
|
197
|
+
parsedReturnCode = 200;
|
|
198
|
+
}
|
|
199
|
+
if (isText && isText !== "false") {
|
|
200
|
+
if (responseMessages && responseMessages !== "false") {
|
|
201
|
+
resHeader["sap-message"] = responseMessages;
|
|
216
202
|
}
|
|
217
|
-
if (
|
|
218
|
-
|
|
219
|
-
resHeader["sap-message"] = responseMessages;
|
|
220
|
-
}
|
|
221
|
-
if (responseLocation && responseLocation !== "false") {
|
|
222
|
-
resHeader["location"] = responseLocation;
|
|
223
|
-
}
|
|
224
|
-
resHeader["Content-Type"] = "text/plain;charset=utf-8";
|
|
225
|
-
oXhr.respond(parsedReturnCode, resHeader, oData);
|
|
203
|
+
if (responseLocation && responseLocation !== "false") {
|
|
204
|
+
resHeader["location"] = responseLocation;
|
|
226
205
|
}
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
}
|
|
234
|
-
resHeader["Content-Type"] = "application/json;charset=utf-8";
|
|
235
|
-
oXhr.respond(parsedReturnCode, resHeader, JSON.stringify(oData));
|
|
206
|
+
resHeader["Content-Type"] = "text/plain;charset=utf-8";
|
|
207
|
+
oXhr.respond(parsedReturnCode, resHeader, oData);
|
|
208
|
+
}
|
|
209
|
+
else {
|
|
210
|
+
if (responseMessages && responseMessages !== "false") {
|
|
211
|
+
resHeader["sap-message"] = responseMessages;
|
|
236
212
|
}
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
var aRequests = mockServerInst.getRequests();
|
|
240
|
-
const isOverride = false;
|
|
241
|
-
if (!isOverride) {
|
|
242
|
-
if (!urlPathRegex) {
|
|
243
|
-
console.error("path regex wasn't provided");
|
|
244
|
-
done();
|
|
213
|
+
if (responseLocation && responseLocation !== "false") {
|
|
214
|
+
resHeader["location"] = responseLocation;
|
|
245
215
|
}
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
aRequests.push({
|
|
249
|
-
method: method,
|
|
250
|
-
path: new RegExp(urlPathEscRegex),
|
|
251
|
-
response: fnResponse
|
|
252
|
-
});
|
|
253
|
-
mockServerInst.setRequests(aRequests);
|
|
216
|
+
resHeader["Content-Type"] = "application/json;charset=utf-8";
|
|
217
|
+
oXhr.respond(parsedReturnCode, resHeader, JSON.stringify(oData));
|
|
254
218
|
}
|
|
255
|
-
|
|
256
|
-
}
|
|
257
|
-
|
|
258
|
-
|
|
219
|
+
return true;
|
|
220
|
+
};
|
|
221
|
+
var aRequests = mockServerInst.getRequests();
|
|
222
|
+
const isOverride = false;
|
|
223
|
+
if (!isOverride) {
|
|
224
|
+
if (!urlPathRegex) {
|
|
225
|
+
console.error("path regex wasn't provided");
|
|
226
|
+
done();
|
|
227
|
+
}
|
|
228
|
+
//Remove regexp slashes so we read them if needed
|
|
229
|
+
var urlPathEscRegex = urlPathRegex.substring(1, urlPathRegex.length - 1);
|
|
230
|
+
aRequests.push({
|
|
231
|
+
method: method,
|
|
232
|
+
path: new RegExp(urlPathEscRegex),
|
|
233
|
+
response: fnResponse
|
|
234
|
+
});
|
|
235
|
+
mockServerInst.setRequests(aRequests);
|
|
236
|
+
}
|
|
237
|
+
done();
|
|
238
|
+
}, mockServerPath, method, urlPathRegex, responseData, responseMessages, responseLocation, returnCode, isText);
|
|
239
|
+
return await ui5.mockserver.waitForUi5ApplicationLoad();
|
|
259
240
|
}
|
|
260
241
|
;
|
|
261
242
|
/**
|
|
@@ -267,33 +248,31 @@ class Mockserver {
|
|
|
267
248
|
* @param {String} urlPathRegex - The url path regex to filter the requests
|
|
268
249
|
* @example await ui5.mockserver.removeRequest("GET","path/to/project/localService/main/mockserver", "*.Headers.*");
|
|
269
250
|
*/
|
|
270
|
-
removeRequest(method, mockServerPath, urlPathRegex) {
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
elemDeleted = true;
|
|
289
|
-
}
|
|
251
|
+
async removeRequest(method, mockServerPath, urlPathRegex) {
|
|
252
|
+
await this.lib.mockServerActionInBrowser(function (mockserver, method, urlPathRegex, done) {
|
|
253
|
+
var mockServerInst = mockserver.getMockServer();
|
|
254
|
+
if (!mockServerInst) {
|
|
255
|
+
console.error("Mockserver not yet initialized or method getMockServer is missing");
|
|
256
|
+
done();
|
|
257
|
+
}
|
|
258
|
+
var aExistingRequests = mockServerInst.getRequests();
|
|
259
|
+
var aRequests = [].concat(aExistingRequests);
|
|
260
|
+
var elemDeleted = false;
|
|
261
|
+
if (urlPathRegex && method && aExistingRequests) {
|
|
262
|
+
//var urlRegEsc = RegExp(urlPathRegex).source.replace(/\\/g, "");
|
|
263
|
+
for (let index = 0; index < aExistingRequests.length; index++) {
|
|
264
|
+
const mockRequest = aExistingRequests[index];
|
|
265
|
+
var regExpPath = mockRequest.path.toString();
|
|
266
|
+
if (mockRequest.method === method && urlPathRegex === regExpPath) {
|
|
267
|
+
aRequests.splice(index, 1);
|
|
268
|
+
elemDeleted = true;
|
|
290
269
|
}
|
|
291
270
|
}
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
271
|
+
}
|
|
272
|
+
mockServerInst.setRequests(aRequests);
|
|
273
|
+
done(elemDeleted);
|
|
274
|
+
}, mockServerPath, method, urlPathRegex);
|
|
275
|
+
return await ui5.mockserver.waitForUi5ApplicationLoad();
|
|
297
276
|
}
|
|
298
277
|
;
|
|
299
278
|
/**
|
|
@@ -310,136 +289,134 @@ class Mockserver {
|
|
|
310
289
|
* @param {String} responseLocation - Mocks the location response messages header
|
|
311
290
|
* @example await ui5.mockserver.addOrOverrideRequest("GET","path/to/project/localService/main/mockserver", "*.Headers.*", "path/to/project/localService/main/mockdata/test.json", 200, true, JSON.stringify(msg));
|
|
312
291
|
*/
|
|
313
|
-
addOrOverrideRequest(method, mockServerPath, urlPathRegex, responseJsonPath, returnCode, isText, responseMessages, responseLocation) {
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
responseData = JSON.stringify(responseJsonPath);
|
|
319
|
-
}
|
|
320
|
-
}
|
|
321
|
-
catch (error) {
|
|
322
|
-
throw new Error("Something went wrong with the conversion" + error);
|
|
323
|
-
}
|
|
324
|
-
// If undefined dont add any messages
|
|
325
|
-
if (!responseMessages) {
|
|
326
|
-
responseMessages = false;
|
|
292
|
+
async addOrOverrideRequest(method, mockServerPath, urlPathRegex, responseJsonPath, returnCode, isText, responseMessages, responseLocation) {
|
|
293
|
+
var responseData = responseJsonPath;
|
|
294
|
+
try {
|
|
295
|
+
if (typeof responseJsonPath !== "string" && typeof responseJsonPath === "object") {
|
|
296
|
+
responseData = JSON.stringify(responseJsonPath);
|
|
327
297
|
}
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
298
|
+
}
|
|
299
|
+
catch (error) {
|
|
300
|
+
throw new Error("Something went wrong with the conversion" + error);
|
|
301
|
+
}
|
|
302
|
+
// If undefined dont add any messages
|
|
303
|
+
if (!responseMessages) {
|
|
304
|
+
responseMessages = false;
|
|
305
|
+
}
|
|
306
|
+
// If undefined dont add any location
|
|
307
|
+
if (!responseLocation) {
|
|
308
|
+
responseLocation = false;
|
|
309
|
+
}
|
|
310
|
+
await this.lib.mockServerActionInBrowser(function (mockserver, method, urlPathRegex, responseJsonPath, responseMessages, responseLocation, returnCode, isText, done) {
|
|
311
|
+
var mockServerInst = mockserver.getMockServer();
|
|
312
|
+
if (!mockServerInst)
|
|
313
|
+
throw new Error("Mockserver not yet initialized or method getMockServer is missing");
|
|
314
|
+
var fnResponse = function (oXhr) {
|
|
315
|
+
// If connection close dont redo response
|
|
316
|
+
if (oXhr.readyState && oXhr.readyState === 4)
|
|
317
|
+
return true;
|
|
318
|
+
var oData = null;
|
|
319
|
+
try {
|
|
320
|
+
if (isText && isText !== "false") {
|
|
321
|
+
oData = responseJsonPath;
|
|
322
|
+
}
|
|
323
|
+
else {
|
|
324
|
+
oData = JSON.parse(responseJsonPath);
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
catch (e) {
|
|
328
|
+
if (typeof responseJsonPath === "string" && !RegExp(".?([^\/\s]+\/)(.*)").test(responseJsonPath)) {
|
|
329
|
+
oData = responseJsonPath;
|
|
330
|
+
}
|
|
331
|
+
else {
|
|
342
332
|
if (isText && isText !== "false") {
|
|
343
|
-
|
|
333
|
+
// @ts-ignore
|
|
334
|
+
var oResponse = jQuery.sap.sjax({
|
|
335
|
+
url: responseJsonPath,
|
|
336
|
+
dataType: "text"
|
|
337
|
+
});
|
|
344
338
|
}
|
|
345
339
|
else {
|
|
346
|
-
|
|
340
|
+
// @ts-ignore
|
|
341
|
+
oResponse = jQuery.sap.sjax({
|
|
342
|
+
url: responseJsonPath,
|
|
343
|
+
dataType: "json"
|
|
344
|
+
});
|
|
347
345
|
}
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
oData = responseJsonPath;
|
|
352
|
-
}
|
|
353
|
-
else {
|
|
354
|
-
if (isText && isText !== "false") {
|
|
355
|
-
// @ts-ignore
|
|
356
|
-
var oResponse = jQuery.sap.sjax({
|
|
357
|
-
url: responseJsonPath,
|
|
358
|
-
dataType: "text"
|
|
359
|
-
});
|
|
360
|
-
}
|
|
361
|
-
else {
|
|
362
|
-
// @ts-ignore
|
|
363
|
-
oResponse = jQuery.sap.sjax({
|
|
364
|
-
url: responseJsonPath,
|
|
365
|
-
dataType: "json"
|
|
366
|
-
});
|
|
346
|
+
if (oResponse.success) {
|
|
347
|
+
if (isText && isText !== "false" && oResponse.data) {
|
|
348
|
+
oData = oResponse.data;
|
|
367
349
|
}
|
|
368
|
-
if (oResponse.
|
|
369
|
-
if (
|
|
350
|
+
else if (oResponse.data.d) {
|
|
351
|
+
if (oResponse.data.d.results) {
|
|
370
352
|
oData = oResponse.data;
|
|
371
353
|
}
|
|
372
354
|
else if (oResponse.data.d) {
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
355
|
+
// Function Import or single data
|
|
356
|
+
oData = oResponse.data;
|
|
357
|
+
}
|
|
358
|
+
else {
|
|
359
|
+
console.error("The mock data are invalid");
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
else {
|
|
363
|
+
if (Array.isArray(oResponse.data)) {
|
|
364
|
+
oData = oResponse.data;
|
|
383
365
|
}
|
|
384
366
|
else {
|
|
385
|
-
|
|
386
|
-
oData = oResponse.data;
|
|
387
|
-
}
|
|
388
|
-
else {
|
|
389
|
-
console.error("The mock data could not be loaded due to wrong format!");
|
|
390
|
-
}
|
|
367
|
+
console.error("The mock data could not be loaded due to wrong format!");
|
|
391
368
|
}
|
|
392
369
|
}
|
|
393
370
|
}
|
|
394
371
|
}
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
372
|
+
}
|
|
373
|
+
var resHeader = {};
|
|
374
|
+
resHeader["content-encoding"] = "identity";
|
|
375
|
+
let parsedReturnCode = parseInt(returnCode);
|
|
376
|
+
if (isNaN(parsedReturnCode)) {
|
|
377
|
+
parsedReturnCode = 200;
|
|
378
|
+
}
|
|
379
|
+
if (isText && isText !== "false") {
|
|
380
|
+
if (responseMessages && responseMessages !== "false") {
|
|
381
|
+
resHeader["sap-message"] = responseMessages;
|
|
400
382
|
}
|
|
401
|
-
if (
|
|
402
|
-
|
|
403
|
-
resHeader["sap-message"] = responseMessages;
|
|
404
|
-
}
|
|
405
|
-
if (responseLocation && responseLocation !== "false") {
|
|
406
|
-
resHeader["location"] = responseLocation;
|
|
407
|
-
}
|
|
408
|
-
resHeader["Content-Type"] = "text/plain;charset=utf-8";
|
|
409
|
-
oXhr.respond(parsedReturnCode, resHeader, oData);
|
|
383
|
+
if (responseLocation && responseLocation !== "false") {
|
|
384
|
+
resHeader["location"] = responseLocation;
|
|
410
385
|
}
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
}
|
|
418
|
-
resHeader["Content-Type"] = "application/json;charset=utf-8";
|
|
419
|
-
oXhr.respond(parsedReturnCode, resHeader, JSON.stringify(oData));
|
|
386
|
+
resHeader["Content-Type"] = "text/plain;charset=utf-8";
|
|
387
|
+
oXhr.respond(parsedReturnCode, resHeader, oData);
|
|
388
|
+
}
|
|
389
|
+
else {
|
|
390
|
+
if (responseMessages && responseMessages !== "false") {
|
|
391
|
+
resHeader["sap-message"] = responseMessages;
|
|
420
392
|
}
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
var aRequests = mockServerInst.getRequests();
|
|
424
|
-
const isOverride = false;
|
|
425
|
-
if (!isOverride) {
|
|
426
|
-
if (!urlPathRegex) {
|
|
427
|
-
console.error("path regex wasnt provided");
|
|
428
|
-
done();
|
|
393
|
+
if (responseLocation && responseLocation !== "false") {
|
|
394
|
+
resHeader["location"] = responseLocation;
|
|
429
395
|
}
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
aRequests.push({
|
|
433
|
-
method: method,
|
|
434
|
-
path: new RegExp(urlPathEscRegex),
|
|
435
|
-
response: fnResponse
|
|
436
|
-
});
|
|
437
|
-
mockServerInst.setRequests(aRequests);
|
|
396
|
+
resHeader["Content-Type"] = "application/json;charset=utf-8";
|
|
397
|
+
oXhr.respond(parsedReturnCode, resHeader, JSON.stringify(oData));
|
|
438
398
|
}
|
|
439
|
-
|
|
440
|
-
}
|
|
441
|
-
|
|
442
|
-
|
|
399
|
+
return true;
|
|
400
|
+
};
|
|
401
|
+
var aRequests = mockServerInst.getRequests();
|
|
402
|
+
const isOverride = false;
|
|
403
|
+
if (!isOverride) {
|
|
404
|
+
if (!urlPathRegex) {
|
|
405
|
+
console.error("path regex wasnt provided");
|
|
406
|
+
done();
|
|
407
|
+
}
|
|
408
|
+
//Remove regexp slashes so we read them if needed
|
|
409
|
+
var urlPathEscRegex = urlPathRegex.substring(1, urlPathRegex.length - 1);
|
|
410
|
+
aRequests.push({
|
|
411
|
+
method: method,
|
|
412
|
+
path: new RegExp(urlPathEscRegex),
|
|
413
|
+
response: fnResponse
|
|
414
|
+
});
|
|
415
|
+
mockServerInst.setRequests(aRequests);
|
|
416
|
+
}
|
|
417
|
+
done();
|
|
418
|
+
}, mockServerPath, method, urlPathRegex, responseData, responseMessages, responseLocation, returnCode, isText);
|
|
419
|
+
return await ui5.mockserver.waitForUi5ApplicationLoad();
|
|
443
420
|
}
|
|
444
421
|
;
|
|
445
422
|
/**
|
|
@@ -449,19 +426,17 @@ class Mockserver {
|
|
|
449
426
|
* @param {String} mockServerPath - The full path to your mockserver file [make sure you implemented getMockServer method in this file to return the mockserver instance].
|
|
450
427
|
* @example await ui5.mockserver.startMockServer("path/to/project/localService/main/mockserver");
|
|
451
428
|
*/
|
|
452
|
-
startMockServer(mockServerPath) {
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
console.error("Mockserver not yet initialized or method getMockServer is missing");
|
|
458
|
-
done();
|
|
459
|
-
}
|
|
460
|
-
mockServerInst.start();
|
|
429
|
+
async startMockServer(mockServerPath) {
|
|
430
|
+
await this.lib.mockServerActionInBrowser(function (mockserver, done) {
|
|
431
|
+
var mockServerInst = mockserver.getMockServer();
|
|
432
|
+
if (!mockServerInst) {
|
|
433
|
+
console.error("Mockserver not yet initialized or method getMockServer is missing");
|
|
461
434
|
done();
|
|
462
|
-
}
|
|
463
|
-
|
|
464
|
-
|
|
435
|
+
}
|
|
436
|
+
mockServerInst.start();
|
|
437
|
+
done();
|
|
438
|
+
}, mockServerPath);
|
|
439
|
+
return await ui5.mockserver.waitForUi5ApplicationLoad();
|
|
465
440
|
}
|
|
466
441
|
;
|
|
467
442
|
/**
|
|
@@ -472,28 +447,26 @@ class Mockserver {
|
|
|
472
447
|
* @param {String} mockServerOptions - The mock server options
|
|
473
448
|
* @example await ui5.mockserver.initMockServer("path/to/project/localService/main/mockserver", mockServerOptions);
|
|
474
449
|
*/
|
|
475
|
-
initMockServer(mockServerPath, mockServerOptions) {
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
MessageBox.error(oError.message);
|
|
488
|
-
});
|
|
489
|
-
}).finally(function () {
|
|
490
|
-
// initialize the embedded component on the HTML page
|
|
491
|
-
// eslint-disable-next-line no-undef
|
|
492
|
-
sap.ui.require(["sap/ui/core/ComponentSupport"]);
|
|
493
|
-
done();
|
|
450
|
+
async initMockServer(mockServerPath, mockServerOptions) {
|
|
451
|
+
var mockServerOpts = JSON.stringify(mockServerOptions);
|
|
452
|
+
return await this.lib.mockServerActionInBrowser(function (mockserver, mockServerOpts, done) {
|
|
453
|
+
if (!mockserver) {
|
|
454
|
+
console.error("Mockserver file not yet loaded or is missing");
|
|
455
|
+
done();
|
|
456
|
+
}
|
|
457
|
+
mockserver.init(JSON.parse(mockServerOpts)).catch(function (oError) {
|
|
458
|
+
// load MessageBox only when needed as it otherwise bypasses the preload of sap.m
|
|
459
|
+
// eslint-disable-next-line no-undef
|
|
460
|
+
sap.ui.require(["sap/m/MessageBox"], function (MessageBox) {
|
|
461
|
+
MessageBox.error(oError.message);
|
|
494
462
|
});
|
|
495
|
-
}
|
|
496
|
-
|
|
463
|
+
}).finally(function () {
|
|
464
|
+
// initialize the embedded component on the HTML page
|
|
465
|
+
// eslint-disable-next-line no-undef
|
|
466
|
+
sap.ui.require(["sap/ui/core/ComponentSupport"]);
|
|
467
|
+
done();
|
|
468
|
+
});
|
|
469
|
+
}, mockServerPath, mockServerOpts);
|
|
497
470
|
}
|
|
498
471
|
;
|
|
499
472
|
/**
|
|
@@ -503,19 +476,17 @@ class Mockserver {
|
|
|
503
476
|
* @param {String} mockServerPath - The full path to your mockserver file [make sure you implemented getMockServer method in this file to return the mockserver instance].
|
|
504
477
|
* @example await ui5.mockserver.initApplication("path/to/project/localService/main/mockserver");
|
|
505
478
|
*/
|
|
506
|
-
initApplication(mockServerPath) {
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
console.error("Mockserver file not yet loaded or is missing");
|
|
511
|
-
done();
|
|
512
|
-
}
|
|
513
|
-
// eslint-disable-next-line no-undef
|
|
514
|
-
sap.ushell.Container.createRenderer().placeAt("content");
|
|
479
|
+
async initApplication(mockServerPath) {
|
|
480
|
+
await this.lib.mockServerActionInBrowser(function (mockserver, done) {
|
|
481
|
+
if (!mockserver) {
|
|
482
|
+
console.error("Mockserver file not yet loaded or is missing");
|
|
515
483
|
done();
|
|
516
|
-
}
|
|
517
|
-
|
|
518
|
-
|
|
484
|
+
}
|
|
485
|
+
// eslint-disable-next-line no-undef
|
|
486
|
+
sap.ushell.Container.createRenderer().placeAt("content");
|
|
487
|
+
done();
|
|
488
|
+
}, mockServerPath);
|
|
489
|
+
return await ui5.mockserver.waitForUi5ApplicationLoad();
|
|
519
490
|
}
|
|
520
491
|
;
|
|
521
492
|
/**
|
|
@@ -525,18 +496,16 @@ class Mockserver {
|
|
|
525
496
|
* @param {String} mockServerPath - The full path to your mockserver file [make sure you implemented getMockServer method in this file to return the mockserver instance].
|
|
526
497
|
* @example await ui5.mockserver.stopMockServer("path/to/project/localService/main/mockserver");
|
|
527
498
|
*/
|
|
528
|
-
stopMockServer(mockServerPath) {
|
|
529
|
-
return
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
console.error("Mockserver not yet initialized or method getMockServer is missing");
|
|
534
|
-
done();
|
|
535
|
-
}
|
|
536
|
-
mockServerInst.stop();
|
|
499
|
+
async stopMockServer(mockServerPath) {
|
|
500
|
+
return await this.lib.mockServerActionInBrowser(function (mockserver, done) {
|
|
501
|
+
var mockServerInst = mockserver.getMockServer();
|
|
502
|
+
if (!mockServerInst) {
|
|
503
|
+
console.error("Mockserver not yet initialized or method getMockServer is missing");
|
|
537
504
|
done();
|
|
538
|
-
}
|
|
539
|
-
|
|
505
|
+
}
|
|
506
|
+
mockServerInst.stop();
|
|
507
|
+
done();
|
|
508
|
+
}, mockServerPath);
|
|
540
509
|
}
|
|
541
510
|
;
|
|
542
511
|
/**
|
|
@@ -548,10 +517,8 @@ class Mockserver {
|
|
|
548
517
|
* @returns {String} The json object
|
|
549
518
|
* @example await ui5.mockserver.loadMockDataFile("path/to/project/mockData/myData.json", true);
|
|
550
519
|
*/
|
|
551
|
-
loadMockDataFile(filePath, isText) {
|
|
552
|
-
return
|
|
553
|
-
return yield this.lib.loadMockData(filePath, isText);
|
|
554
|
-
});
|
|
520
|
+
async loadMockDataFile(filePath, isText) {
|
|
521
|
+
return await this.lib.loadMockData(filePath, isText);
|
|
555
522
|
}
|
|
556
523
|
;
|
|
557
524
|
/**
|
|
@@ -563,18 +530,16 @@ class Mockserver {
|
|
|
563
530
|
* @returns {Array} An array of json objects
|
|
564
531
|
* @example await ui5.mockserver.getEntitySetData("path/to/project/localService/main/mockserver", "Headers");
|
|
565
532
|
*/
|
|
566
|
-
getEntitySetData(mockServerPath, entitySetName) {
|
|
567
|
-
return
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
}, mockServerPath, entitySetName);
|
|
577
|
-
});
|
|
533
|
+
async getEntitySetData(mockServerPath, entitySetName) {
|
|
534
|
+
return await this.lib.mockServerActionInBrowser(function (mockserver, entitySetName, done) {
|
|
535
|
+
var mockServerInst = mockserver.getMockServer();
|
|
536
|
+
if (!mockServerInst) {
|
|
537
|
+
console.error("Mockserver not yet initialized or method getMockServer is missing");
|
|
538
|
+
done();
|
|
539
|
+
}
|
|
540
|
+
const oData = mockServerInst.getEntitySetData(entitySetName);
|
|
541
|
+
done(oData);
|
|
542
|
+
}, mockServerPath, entitySetName);
|
|
578
543
|
}
|
|
579
544
|
;
|
|
580
545
|
/**
|
|
@@ -586,76 +551,74 @@ class Mockserver {
|
|
|
586
551
|
* @param {String} entries - The json object to be used as data to be inserted [use relative path from the html page started].
|
|
587
552
|
* @example await ui5.mockserver.setEntitySetData("path/to/project/localService/main/mockserver", "Headers", entries);
|
|
588
553
|
*/
|
|
589
|
-
setEntitySetData(mockServerPath, entitySetName, entries) {
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
responseData = JSON.stringify(entries);
|
|
595
|
-
}
|
|
554
|
+
async setEntitySetData(mockServerPath, entitySetName, entries) {
|
|
555
|
+
var responseData = entries;
|
|
556
|
+
try {
|
|
557
|
+
if (typeof entries !== "string" && typeof entries === "object") {
|
|
558
|
+
responseData = JSON.stringify(entries);
|
|
596
559
|
}
|
|
597
|
-
|
|
598
|
-
|
|
560
|
+
}
|
|
561
|
+
catch (error) {
|
|
562
|
+
throw new Error("Something went wrong with the conversion" + error);
|
|
563
|
+
}
|
|
564
|
+
return await this.lib.mockServerActionInBrowser(function (mockserver, entitySetName, entries, done) {
|
|
565
|
+
var mockServerInst = mockserver.getMockServer();
|
|
566
|
+
if (!mockServerInst) {
|
|
567
|
+
console.error("Mockserver not yet initialized or method getMockServer is missing");
|
|
568
|
+
done();
|
|
599
569
|
}
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
if (!Array.isArray(tempOData)) {
|
|
610
|
-
if (tempOData.d.results)
|
|
611
|
-
oData = [].concat(tempOData.d.results);
|
|
612
|
-
else if (tempOData.d)
|
|
613
|
-
oData = [].concat(tempOData.d);
|
|
614
|
-
else
|
|
615
|
-
oData = [].concat(tempOData);
|
|
616
|
-
}
|
|
617
|
-
else {
|
|
618
|
-
// @ts-ignore
|
|
570
|
+
var oData = [];
|
|
571
|
+
try {
|
|
572
|
+
var tempOData = JSON.parse(entries);
|
|
573
|
+
if (!Array.isArray(tempOData)) {
|
|
574
|
+
if (tempOData.d.results)
|
|
575
|
+
oData = [].concat(tempOData.d.results);
|
|
576
|
+
else if (tempOData.d)
|
|
577
|
+
oData = [].concat(tempOData.d);
|
|
578
|
+
else
|
|
619
579
|
oData = [].concat(tempOData);
|
|
620
|
-
}
|
|
621
580
|
}
|
|
622
|
-
|
|
581
|
+
else {
|
|
623
582
|
// @ts-ignore
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
583
|
+
oData = [].concat(tempOData);
|
|
584
|
+
}
|
|
585
|
+
}
|
|
586
|
+
catch (e) {
|
|
587
|
+
// @ts-ignore
|
|
588
|
+
var oResponse = jQuery.sap.sjax({
|
|
589
|
+
url: entries,
|
|
590
|
+
dataType: "json"
|
|
591
|
+
});
|
|
592
|
+
if (oResponse.success) {
|
|
593
|
+
if (oResponse.data.d) {
|
|
594
|
+
if (oResponse.data.d.results) {
|
|
595
|
+
oData = oResponse.data.d.results;
|
|
596
|
+
}
|
|
597
|
+
else if (oResponse.data.d) {
|
|
598
|
+
// Single data
|
|
599
|
+
oData.push(oResponse.data.d);
|
|
600
|
+
}
|
|
601
|
+
else if (oResponse.data) {
|
|
602
|
+
// Fallback Single data
|
|
603
|
+
oData.push(oResponse.data);
|
|
644
604
|
}
|
|
645
605
|
else {
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
606
|
+
console.error("The mock data are invalid");
|
|
607
|
+
}
|
|
608
|
+
}
|
|
609
|
+
else {
|
|
610
|
+
if (Array.isArray(oResponse.data)) {
|
|
611
|
+
oData = [].concat(oResponse.data);
|
|
612
|
+
}
|
|
613
|
+
else {
|
|
614
|
+
console.error("The mock data could not be loaded due to wrong format!");
|
|
652
615
|
}
|
|
653
616
|
}
|
|
654
617
|
}
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
});
|
|
618
|
+
}
|
|
619
|
+
mockServerInst.setEntitySetData(entitySetName, oData);
|
|
620
|
+
done(oData);
|
|
621
|
+
}, mockServerPath, entitySetName, responseData);
|
|
659
622
|
}
|
|
660
623
|
;
|
|
661
624
|
}
|