Skip to content

Commit

Permalink
[INTERNAL] Specifications: Add more tests (#563)
Browse files Browse the repository at this point in the history
Co-authored-by: Yavor Ivanov <d3xter666@users.noreply.github.com>
Co-authored-by: Florian Vogt <florian.vogt@sap.com>
  • Loading branch information
3 people committed Feb 1, 2023
1 parent f90d17a commit a0e1e96
Show file tree
Hide file tree
Showing 5 changed files with 96 additions and 0 deletions.
57 changes: 57 additions & 0 deletions test/lib/specifications/Project.js
Expand Up @@ -92,6 +92,63 @@ test("getCustomTasks/getCustomMiddleware defaults", async (t) => {
"Returned correct default value for custom middleware configuration");
});

test("getFramework*: Defaults", async (t) => {
const customProjectInput = clone(basicProjectInput);
const project = await Specification.create(customProjectInput);
t.is(project.getFrameworkName(), undefined, "Returned correct framework name");
t.is(project.getFrameworkVersion(), undefined, "Returned correct framework version");
t.deepEqual(project.getFrameworkDependencies(), [], "Returned correct framework dependencies");
t.false(project.isFrameworkProject(), "Is not a framework project");
});

test("getFramework* configurations", async (t) => {
const customProjectInput = clone(basicProjectInput);
customProjectInput.configuration.framework = {
name: "OpenUI5",
version: "1.111.1",
libraries: [
{name: "lib-1"},
{name: "lib-2"},
]
};
customProjectInput.id = "@openui5/" + customProjectInput.id;
const project = await Specification.create(customProjectInput);
t.is(project.getFrameworkName(), "OpenUI5", "Returned correct framework name");
t.is(project.getFrameworkVersion(), "1.111.1", "Returned correct framework version");
t.deepEqual(project.getFrameworkDependencies(), [
{name: "lib-1"},
{name: "lib-2"}
], "Returned correct framework dependencies");
t.true(project.isFrameworkProject(), "Is a framework project");
});

test("isFrameworkProject: sapui5", async (t) => {
const customProjectInput = clone(basicProjectInput);
customProjectInput.id = "@sapui5/" + customProjectInput.id;
const project = await Specification.create(customProjectInput);
t.true(project.isFrameworkProject(), "Is a framework project");
});

test("isDeprecated/isSapInternal: Defaults", async (t) => {
const customProjectInput = clone(basicProjectInput);

const project = await Specification.create(customProjectInput);
t.false(project.isDeprecated(), "Is not deprecated");
t.false(project.isSapInternal(), "Is not SAP-internal");
t.false(project.getAllowSapInternal(), "Does not allow SAP-internal");
});

test("isDeprecated/isSapInternal: True", async (t) => {
const customProjectInput = clone(basicProjectInput);
customProjectInput.configuration.metadata.deprecated = true;
customProjectInput.configuration.metadata.sapInternal = true;
customProjectInput.configuration.metadata.allowSapInternal = true;
const project = await Specification.create(customProjectInput);
t.true(project.isDeprecated(), "Is deprecated");
t.true(project.isSapInternal(), "Is SAP-internal");
t.true(project.getAllowSapInternal(), "Does allow SAP-internal");
});

test("getServerSettings", async (t) => {
const customProjectInput = clone(basicProjectInput);
customProjectInput.configuration.server = {
Expand Down
12 changes: 12 additions & 0 deletions test/lib/specifications/types/Application.js
Expand Up @@ -34,6 +34,18 @@ test("Correct class", async (t) => {
t.true(project instanceof Application, `Is an instance of the Application class`);
});

test("getNamespace", async (t) => {
const project = await Specification.create(basicProjectInput);
t.is(project.getNamespace(), "id1",
"Returned correct namespace");
});

test("getSourcePath", async (t) => {
const project = await Specification.create(basicProjectInput);
t.is(project.getSourcePath(), path.join(applicationAPath, "webapp"),
"Returned correct source path");
});

test("getCachebusterSignatureType: Default", async (t) => {
const project = await Specification.create(basicProjectInput);
t.is(project.getCachebusterSignatureType(), "time",
Expand Down
6 changes: 6 additions & 0 deletions test/lib/specifications/types/Library.js
Expand Up @@ -62,6 +62,12 @@ test("getNamespace", async (t) => {
"Returned correct namespace");
});

test("getSourcePath", async (t) => {
const project = await (new Library().init(basicProjectInput));
t.is(project.getSourcePath(), path.join(libraryDPath, "main", "src"),
"Returned correct source path");
});

test("getPropertiesFileSourceEncoding: Default", async (t) => {
const project = await (new Library().init(basicProjectInput));
t.is(project.getPropertiesFileSourceEncoding(), "UTF-8",
Expand Down
15 changes: 15 additions & 0 deletions test/lib/specifications/types/Module.js
Expand Up @@ -45,6 +45,21 @@ test("Correct class", async (t) => {
});

test("getSourcePath: Throws", async (t) => {
const project = await Specification.create(basicProjectInput);
const err = t.throws(() => {
project.getSourcePath();
});
t.is(err.message, "Projects of type module have more than one source path",
"Threw with expected error message");
});

test("getNamespace", async (t) => {
const project = await Specification.create(basicProjectInput);
t.is(project.getNamespace(), null,
"Returned no namespace");
});

test("Access project resources via reader", async (t) => {
const project = await Specification.create(basicProjectInput);
t.throws(() => {
project.getSourcePath();
Expand Down
6 changes: 6 additions & 0 deletions test/lib/specifications/types/ThemeLibrary.js
Expand Up @@ -47,6 +47,12 @@ test("getSourcePath", async (t) => {
t.is(project.getSourcePath(), path.join(themeLibraryEPath, "src"), "Correct source path");
});

test("getNamespace", async (t) => {
const project = await Specification.create(basicProjectInput);
t.is(project.getNamespace(), null,
"Returned no namespace");
});

test("Access project resources via reader", async (t) => {
const project = await Specification.create(basicProjectInput);
const reader = project.getReader();
Expand Down

0 comments on commit a0e1e96

Please sign in to comment.