Skip to content

Commit

Permalink
Removed "Utils" from helper file names
Browse files Browse the repository at this point in the history
renamed variable "version" to "specVersion" in tests

Restructure "additionalProperty tests"
  • Loading branch information
tobiasso85 committed Apr 27, 2020
1 parent fd1d30d commit ca974da
Show file tree
Hide file tree
Showing 13 changed files with 201 additions and 225 deletions.
73 changes: 7 additions & 66 deletions test/lib/validation/schema/__helper__/customConfiguration.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,21 @@ module.exports = {
* @param {Function} assertValidation assertion function
* @param {string} type one of "project-shim", "server-middleware" "task",
* "application", "library", "theme-library" and "module"
* @param {Object} oMandatoryProperty mandatory configuration content
* @param {Object} additionalConfiguration additional configuration content
*/
runTests: function(test, assertValidation, type, oMandatoryProperty) {
oMandatoryProperty = oMandatoryProperty || {};
defineTests: function(test, assertValidation, type, additionalConfiguration) {
additionalConfiguration = additionalConfiguration || {};

// version specific tests for customConfiguration
test(type + ": Invalid customConfiguration (specVersion 2.0)", async (t) => {
test(`${type}: Invalid customConfiguration (specVersion 2.0)`, async (t) => {
await assertValidation(t, Object.assign({
"specVersion": "2.0",
"type": type,
"metadata": {
"name": "my-" + type
},
"customConfiguration": {}
}, oMandatoryProperty), [
}, additionalConfiguration), [
{
dataPath: "",
keyword: "additionalProperties",
Expand All @@ -36,45 +36,7 @@ module.exports = {
]);
});

test(type + " (specVersion 2.0): Additional property", async (t) => {
await assertValidation(t, Object.assign( {
"specVersion": "2.0",
"type": type,
"metadata": {
"name": "my-" + type
},
"notAllowed": true
}, oMandatoryProperty), [{
dataPath: "",
keyword: "additionalProperties",
message: "should NOT have additional properties",
params: {
additionalProperty: "notAllowed",
},
schemaPath: "#/else/additionalProperties",
}]);
});

test(type + " (specVersion 2.1): Additional property", async (t) => {
await assertValidation(t, Object.assign( {
"specVersion": "2.1",
"type": type,
"metadata": {
"name": "my-" + type
},
"notAllowed": true
}, oMandatoryProperty), [{
dataPath: "",
keyword: "additionalProperties",
message: "should NOT have additional properties",
params: {
additionalProperty: "notAllowed",
},
schemaPath: "#/then/additionalProperties",
}]);
});

test(type + ": Valid customConfiguration (specVersion 2.1)", async (t) => {
test(`${type}: Valid customConfiguration (specVersion 2.1)`, async (t) => {
await assertValidation(t, Object.assign( {
"specVersion": "2.1",
"type": type,
Expand All @@ -84,28 +46,7 @@ module.exports = {
"customConfiguration": {
"foo": "bar"
}
}, oMandatoryProperty));
});

test(type + ": Additional property (specVersion 2.1)", async (t) => {
await assertValidation(t, Object.assign( {
"specVersion": "2.1",
"type": type,
"metadata": {
"name": "my-" + type
},
"foo": {
"bar": true
}
}, oMandatoryProperty), [{
dataPath: "",
keyword: "additionalProperties",
message: "should NOT have additional properties",
params: {
additionalProperty: "foo",
},
schemaPath: "#/then/additionalProperties",
}]);
}, additionalConfiguration));
});
}
};
73 changes: 73 additions & 0 deletions test/lib/validation/schema/__helper__/extension.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
const customConfiguration = require("./customConfiguration");

/**
* Common test functionality to be able to run the same tests for different types of kind "extension"
*/
module.exports = {
/**
* Executes the tests for different types of kind extension, e.g. "project-shim", "server-middleware" and "task"
*
* @param {Function} test ava test
* @param {Function} assertValidation assertion function
* @param {string} type one of "project-shim", "server-middleware" and "task"
* @param {Object} additionalConfiguration additional configuration content
*/
defineTests: function(test, assertValidation, type, additionalConfiguration) {
additionalConfiguration = additionalConfiguration || {};
additionalConfiguration = Object.assign({"kind": "extension"}, additionalConfiguration);

customConfiguration.defineTests(test, assertValidation, type, additionalConfiguration);

["2.0", "2.1"].forEach((specVersion) => {
test(`kind: extension / type: ${type} basic (${specVersion})`, async (t) => {
await assertValidation(t, Object.assign({
"specVersion": specVersion,
"kind": "extension",
"type": type,
"metadata": {
"name": "my-" + type
}
}, additionalConfiguration));
});

test(`kind: extension / type: ${type} additionalProperties (${specVersion})`, async (t) => {
await assertValidation(t, Object.assign({
"specVersion": specVersion,
"kind": "extension",
"type": type,
"metadata": {
"name": "my-" + type
},
"resources": {}
}, additionalConfiguration), [{
dataPath: "",
keyword: "additionalProperties",
message: "should NOT have additional properties",
params: {
"additionalProperty": "resources"
},
schemaPath: specVersion === "2.1" ? "#/then/additionalProperties" : "#/else/additionalProperties"
}]);
});

test(`${type} Invalid configuration: Additional property (${specVersion})`, async (t) => {
await assertValidation(t, Object.assign( {
"specVersion": specVersion,
"type": type,
"metadata": {
"name": "my-" + type
},
"notAllowed": true
}, additionalConfiguration), [{
dataPath: "",
keyword: "additionalProperties",
message: "should NOT have additional properties",
params: {
additionalProperty: "notAllowed",
},
schemaPath: specVersion === "2.1" ? "#/then/additionalProperties" : "#/else/additionalProperties"
}]);
});
});
}
};
56 changes: 0 additions & 56 deletions test/lib/validation/schema/__helper__/extensionUtils.js

This file was deleted.

24 changes: 12 additions & 12 deletions test/lib/validation/schema/__helper__/framework.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ module.exports = {
* @param {Function} assertValidation assertion function
* @param {string} type one of "application", "library" and "theme-library"
*/
runTests: function(test, assertValidation, type) {
["2.0", "2.1"].forEach((version) => {
test(type + " (specVersion " + version + "): framework configuration: OpenUI5", async (t) => {
defineTests: function(test, assertValidation, type) {
["2.0", "2.1"].forEach((specVersion) => {
test(`${type} (specVersion ${specVersion}): framework configuration: OpenUI5`, async (t) => {
const config = {
"specVersion": version,
"specVersion": specVersion,
"type": type,
"metadata": {
"name": "my-" + type
Expand All @@ -32,9 +32,9 @@ module.exports = {
await assertValidation(t, config);
});

test(type + " (specVersion " + version + "): framework configuration: SAPUI5", async (t) => {
test(`${type} (specVersion ${specVersion}): framework configuration: SAPUI5`, async (t) => {
const config = {
"specVersion": version,
"specVersion": specVersion,
"type": type,
"metadata": {
"name": "my-" + type
Expand All @@ -60,9 +60,9 @@ module.exports = {
await assertValidation(t, config);
});

test(type + " (specVersion " + version + "): framework configuration: Invalid", async (t) => {
test(`${type} (specVersion ${specVersion}): framework configuration: Invalid`, async (t) => {
const config = {
"specVersion": version,
"specVersion": specVersion,
"type": type,
"metadata": {
"name": "my-" + type
Expand Down Expand Up @@ -164,9 +164,9 @@ module.exports = {
]);
});

test(type + " (specVersion " + version + "): framework configuration: Missing 'name'", async (t) => {
test(`${type} (specVersion ${specVersion}): framework configuration: Missing 'name'`, async (t) => {
await assertValidation(t, {
"specVersion": version,
"specVersion": specVersion,
"type": type,
"metadata": {
"name": "my-" + type
Expand All @@ -185,9 +185,9 @@ module.exports = {
]);
});

test(type + " (specVersion " + version + "): framework configuration: library with optional and development", async (t) => {
test(`${type} (specVersion ${specVersion}): framework configuration: library with optional and development`, async (t) => {
await assertValidation(t, {
"specVersion": version,
"specVersion": specVersion,
"type": type,
"metadata": {
"name": "my-" + type
Expand Down
Loading

0 comments on commit ca974da

Please sign in to comment.