Skip to content

Commit e536e1d

Browse files
cotchereGerrit Code Review
authored andcommitted
Merge "[INTERNAL] sap.ui.fl: new change merger appdescr_platform_cf_setUI5VersionNumber"
2 parents 6e06b0c + caea465 commit e536e1d

File tree

5 files changed

+217
-1
lines changed

5 files changed

+217
-1
lines changed

src/sap.ui.fl/src/sap/ui/fl/apply/_internal/appVariant/DescriptorChangeTypes.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,8 @@ sap.ui.define([
6060
"appdescr_ui5_changeModel",
6161
"appdescr_ui_generic_app_addNewObjectPage",
6262
"appdescr_ui_generic_app_changePageConfiguration",
63-
"appdescr_fe_addNewPage"
63+
"appdescr_fe_addNewPage",
64+
"appdescr_platform_cf_setUI5VersionNumber"
6465
];
6566
},
6667
getCondensableChangeTypes() {

src/sap.ui.fl/src/sap/ui/fl/apply/_internal/changes/descriptor/RegistrationBuild.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ sap.ui.define([
2828
appdescr_ui5_addComponentUsages: requireAsync.bind(this, "sap/ui/fl/apply/_internal/changes/descriptor/ui5/AddComponentUsages"),
2929
appdescr_ui5_changeModel: requireAsync.bind(this, "sap/ui/fl/apply/_internal/changes/descriptor/ui5/ChangeModel"),
3030
appdescr_ui5_setMinUI5Version: requireAsync.bind(this, "sap/ui/fl/apply/_internal/changes/descriptor/ui5/SetMinUI5Version"),
31+
appdescr_platform_cf_setUI5VersionNumber: requireAsync.bind(this, "sap/ui/fl/apply/_internal/changes/descriptor/platform/SetUI5VersionNumber"),
3132
appdescr_fiori_setRegistrationIds: requireAsync.bind(this, "sap/ui/fl/apply/_internal/changes/descriptor/fiori/SetRegistrationIds"),
3233
appdescr_ui5_setFlexExtensionPointEnabled: requireAsync.bind(this, "sap/ui/fl/apply/_internal/changes/descriptor/ui5/SetFlexExtensionPointEnabled"),
3334
appdescr_ui5_addNewModel: requireAsync.bind(this, "sap/ui/fl/apply/_internal/changes/descriptor/ui5/AddNewModel"),
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
2+
/*!
3+
* ${copyright}
4+
*/
5+
sap.ui.define([
6+
"sap/base/util/ObjectPath",
7+
"sap/base/util/Version"
8+
], function(
9+
ObjectPath,
10+
Version
11+
) {
12+
"use strict";
13+
const rSemver = /^(0|[1-9]\d*)\.(0|[1-9]\d*)(?:\.(0|[1-9]\d*))?(?:-[0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*)?(?:\+[0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*)?$/;
14+
/**
15+
* Descriptor change merger for change type <code>appdescr_platform_cf_setUI5VersionNumber</code>.
16+
* Upserts string value at <code>sap.platform.cf/ui5VersionNumber</code>.
17+
*
18+
* Only available during build time {@link sap.ui.fl.apply._internal.changes.descriptor.RegistrationBuild}.
19+
*
20+
* @namespace
21+
* @alias sap.ui.fl.apply._internal.changes.descriptor.platform.SetUI5VersionNumber
22+
* @since 1.120
23+
* @version ${version}
24+
* @private
25+
* @ui5-restricted sap.ui.fl.apply._internal
26+
*/
27+
const SetUI5VersionNumber = /** @lends sap.ui.fl.apply._internal.changes.descriptor.platform.SetUI5VersionNumber */ {
28+
/**
29+
* Applies <code>appdescr_platform_cf_setUI5VersionNumber</code> change to the manifest.
30+
* @param {object} oManifest - Original manifest
31+
* @param {sap.ui.fl.apply._internal.flexObjects.AppDescriptorChange} oChange - Change with type <code>appdescr_platform_cf_setUI5VersionNumber</code>
32+
* @param {object} oChange.content - Details of the change
33+
* @param {string} oChange.content.ui5VersionNumber - String UI5 version number to set
34+
* @returns {object} Updated manifest with changed <code>sap.platform.cf/ui5VersionNumber</code>
35+
*
36+
* @private
37+
* @ui5-restricted sap.ui.fl.apply._internal
38+
*/
39+
applyChange(oManifest, oChange) {
40+
if (!oChange.getContent().hasOwnProperty("ui5VersionNumber")) {
41+
throw new Error("No ui5VersionNumber in change content provided");
42+
}
43+
const sUI5VersionNumber = oChange.getContent().ui5VersionNumber;
44+
if (typeof sUI5VersionNumber !== "string") {
45+
throw new Error(`The current change value type of property ui5VersionNumber is '${typeof sUI5VersionNumber}'. Only allowed type for property ui5VersionNumber is string`);
46+
}
47+
const aSemverMatch = rSemver.exec(sUI5VersionNumber);
48+
if (!aSemverMatch) {
49+
throw new Error(`The value of property ui5VersionNumber ('${sUI5VersionNumber}') is not a valid semantic version (MAJOR.MINOR or MAJOR.MINOR.PATCH)`);
50+
}
51+
const aPropertyPath = ["sap.platform.cf", "ui5VersionNumber"];
52+
const oNewVersion = new Version(sUI5VersionNumber);
53+
const oCurrVersionString = ObjectPath.get(aPropertyPath, oManifest);
54+
const oCurrVersion = oCurrVersionString ? new Version(oCurrVersionString) : null;
55+
if (!oCurrVersion || oCurrVersion.compareTo(oNewVersion) < 0) {
56+
ObjectPath.set(aPropertyPath, sUI5VersionNumber, oManifest);
57+
}
58+
return oManifest;
59+
}
60+
};
61+
return SetUI5VersionNumber;
62+
});
Lines changed: 146 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
1+
2+
/* global QUnit */
3+
sap.ui.define([
4+
"sap/ui/fl/apply/_internal/changes/descriptor/platform/SetUI5VersionNumber",
5+
"sap/ui/fl/apply/_internal/flexObjects/AppDescriptorChange",
6+
"sap/ui/thirdparty/sinon-4"
7+
], function(
8+
SetUI5VersionNumber,
9+
AppDescriptorChange,
10+
sinon
11+
) {
12+
"use strict";
13+
const sandbox = sinon.createSandbox();
14+
function assertInvalidVersionChange(assert, oManifest, oChange) {
15+
assert.throws(function() {
16+
SetUI5VersionNumber.applyChange(oManifest, oChange);
17+
}, /not a valid semantic version/, "throws error for invalid semantic version");
18+
}
19+
QUnit.module("applyChange", {
20+
beforeEach() {
21+
this.oChange = new AppDescriptorChange({
22+
flexObjectMetadata: {
23+
changeType: "appdescr_platform_cf_setUI5VersionNumber"
24+
},
25+
content: {
26+
ui5VersionNumber: "1.120.0"
27+
}
28+
});
29+
},
30+
afterEach() {
31+
sandbox.restore();
32+
}
33+
}, function() {
34+
QUnit.test("when applying change to manifest with existing sap.platform.cf", function(assert) {
35+
const oManifest = {
36+
"sap.platform.cf": {
37+
ui5VersionNumber: "1.86"
38+
}
39+
};
40+
const oNewManifest = SetUI5VersionNumber.applyChange(oManifest, this.oChange);
41+
assert.strictEqual(oNewManifest["sap.platform.cf"].ui5VersionNumber, "1.120.0",
42+
"ui5VersionNumber is stored with patch when provided");
43+
});
44+
QUnit.test("when applying change with lower ui5VersionNumber than existing, manifest is not updated (downgrade check)", function(assert) {
45+
const oManifest = {
46+
"sap.platform.cf": {
47+
ui5VersionNumber: "1.120"
48+
}
49+
};
50+
const oChange = new AppDescriptorChange({
51+
flexObjectMetadata: {
52+
changeType: "appdescr_platform_cf_setUI5VersionNumber"
53+
},
54+
content: {
55+
ui5VersionNumber: "1.86.0"
56+
}
57+
});
58+
const oNewManifest = SetUI5VersionNumber.applyChange(oManifest, oChange);
59+
assert.strictEqual(oNewManifest["sap.platform.cf"].ui5VersionNumber, "1.120",
60+
"ui5VersionNumber is not updated to major.minor if lower");
61+
});
62+
QUnit.test("when applying change to manifest without sap.platform.cf node", function(assert) {
63+
const oManifest = {
64+
"sap.app": {
65+
id: "my.sample"
66+
}
67+
};
68+
const oNewManifest = SetUI5VersionNumber.applyChange(oManifest, this.oChange);
69+
assert.strictEqual(oNewManifest["sap.platform.cf"].ui5VersionNumber, "1.120.0",
70+
"ui5VersionNumber is created and set with patch when provided");
71+
});
72+
QUnit.test("when applying change with major.minor version, it is accepted", function(assert) {
73+
const oChange = new AppDescriptorChange({
74+
flexObjectMetadata: {
75+
changeType: "appdescr_platform_cf_setUI5VersionNumber"
76+
},
77+
content: {
78+
ui5VersionNumber: "1.120"
79+
}
80+
});
81+
const oManifest = {};
82+
const oNewManifest = SetUI5VersionNumber.applyChange(oManifest, oChange);
83+
assert.strictEqual(oNewManifest["sap.platform.cf"].ui5VersionNumber, "1.120",
84+
"ui5VersionNumber is stored as major.minor");
85+
});
86+
QUnit.test("when applying change with major.minor.patch version, it is accepted", function(assert) {
87+
const oChange = new AppDescriptorChange({
88+
flexObjectMetadata: {
89+
changeType: "appdescr_platform_cf_setUI5VersionNumber"
90+
},
91+
content: {
92+
ui5VersionNumber: "1.120.1"
93+
}
94+
});
95+
const oManifest = {};
96+
const oNewManifest = SetUI5VersionNumber.applyChange(oManifest, oChange);
97+
assert.strictEqual(oNewManifest["sap.platform.cf"].ui5VersionNumber, "1.120.1",
98+
"ui5VersionNumber is stored with patch when provided");
99+
});
100+
QUnit.test("when applying change with missing ui5VersionNumber", function(assert) {
101+
const oChange = new AppDescriptorChange({
102+
flexObjectMetadata: {
103+
changeType: "appdescr_platform_cf_setUI5VersionNumber"
104+
},
105+
content: {}
106+
});
107+
const oManifest = {};
108+
assert.throws(function() {
109+
SetUI5VersionNumber.applyChange(oManifest, oChange);
110+
}, Error("No ui5VersionNumber in change content provided"), "throws error for missing property");
111+
});
112+
QUnit.test("when applying change with non-string ui5VersionNumber", function(assert) {
113+
const oChange = new AppDescriptorChange({
114+
flexObjectMetadata: {
115+
changeType: "appdescr_platform_cf_setUI5VersionNumber"
116+
},
117+
content: {
118+
ui5VersionNumber: 120
119+
}
120+
});
121+
const oManifest = {};
122+
assert.throws(function() {
123+
SetUI5VersionNumber.applyChange(oManifest, oChange);
124+
}, /Only allowed type for property ui5VersionNumber is string/, "throws error for wrong type");
125+
});
126+
QUnit.test("when applying change with invalid semantic versions", function(assert) {
127+
const oManifest = {};
128+
const aInvalidVersions = ["invalidversion", "1,0,0", ""];
129+
for (let i = 0; i < aInvalidVersions.length; i++) {
130+
const sInvalidVersion = aInvalidVersions[i];
131+
const oChange = new AppDescriptorChange({
132+
flexObjectMetadata: {
133+
changeType: "appdescr_platform_cf_setUI5VersionNumber"
134+
},
135+
content: {
136+
ui5VersionNumber: sInvalidVersion
137+
}
138+
});
139+
assertInvalidVersionChange(assert, oManifest, oChange);
140+
}
141+
});
142+
});
143+
QUnit.done(function() {
144+
document.getElementById("qunit-fixture").style.display = "none";
145+
});
146+
});

src/sap.ui.fl/test/sap/ui/fl/qunit/testsuite.qunit.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1517,6 +1517,12 @@ sap.ui.define([
15171517
only: ["sap/ui/fl/apply/_internal/changes/descriptor/ovp/DeleteCard"]
15181518
}
15191519
},
1520+
"apply/_internal/changes/descriptor/platform/SetUI5VersionNumber": {
1521+
group: "Apply Internal - Descriptor Change Merger",
1522+
coverage: {
1523+
only: ["sap/ui/fl/apply/_internal/changes/descriptor/platform/SetUI5VersionNumber"]
1524+
}
1525+
},
15201526
"Generic Testsuite": {
15211527
page: "test-resources/sap/ui/fl/qunit/testsuite.generic.qunit.html"
15221528
}

0 commit comments

Comments
 (0)