|
| 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 | +}); |
0 commit comments