From 4051832dc0473f411e73bc48b4e6a05ab02dbdd2 Mon Sep 17 00:00:00 2001 From: Webber Date: Mon, 27 Jan 2020 23:03:29 +0100 Subject: [PATCH] =?UTF-8?q?Add=20some=20more=20basic=20tests=20?= =?UTF-8?q?=F0=9F=A4=B7=E2=80=8D=E2=99=82=EF=B8=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/model/build-parameters.test.js | 85 ++++++++++++++++++++++++++++++ src/model/index.test.js | 10 ++++ src/model/input.js | 6 ++- src/model/input.test.js | 4 ++ src/model/platform.test.js | 37 +++++++++++++ src/model/project.js | 23 ++++++++ src/model/project.test.js | 33 ++++++++++++ src/model/unity.js | 7 +++ src/model/unity.test.js | 13 +++++ 9 files changed, 217 insertions(+), 1 deletion(-) create mode 100644 src/model/build-parameters.test.js create mode 100644 src/model/index.test.js create mode 100644 src/model/platform.test.js create mode 100644 src/model/project.js create mode 100644 src/model/project.test.js create mode 100644 src/model/unity.js create mode 100644 src/model/unity.test.js diff --git a/src/model/build-parameters.test.js b/src/model/build-parameters.test.js new file mode 100644 index 00000000..0e480c88 --- /dev/null +++ b/src/model/build-parameters.test.js @@ -0,0 +1,85 @@ +import BuildParameters from './build-parameters'; +import Platform from './platform'; + +describe('BuildParameters', () => { + describe('create', () => { + const someParameters = { + unityVersion: 'someVersion', + targetPlatform: 'somePlatform', + projectPath: 'path/to/project', + buildName: 'someBuildName', + buildsPath: 'someBuildsPath', + buildMethod: 'Namespace.Class.Method', + customParameters: '-someParam someValue', + }; + + it('does not throw', () => { + expect(() => BuildParameters.create(someParameters)).not.toThrow(); + }); + + it('returns the version', () => { + expect(BuildParameters.create(someParameters).version).toStrictEqual( + someParameters.unityVersion, + ); + }); + + it('returns the platform', () => { + expect(BuildParameters.create(someParameters).platform).toStrictEqual( + someParameters.targetPlatform, + ); + }); + + it('returns the project path', () => { + expect(BuildParameters.create(someParameters).projectPath).toStrictEqual( + someParameters.projectPath, + ); + }); + + it('returns the build name', () => { + expect(BuildParameters.create(someParameters).buildName).toStrictEqual( + someParameters.buildName, + ); + }); + + it('returns the build path', () => { + expect(BuildParameters.create(someParameters).buildPath).toStrictEqual( + `${someParameters.buildsPath}/${someParameters.targetPlatform}`, + ); + }); + + describe('build file', () => { + it('returns the build file', () => { + expect(BuildParameters.create(someParameters).buildFile).toStrictEqual( + someParameters.buildName, + ); + }); + + test.each([Platform.types.StandaloneWindows, Platform.types.StandaloneWindows64])( + 'appends exe for %s', + targetPlatform => { + expect( + BuildParameters.create({ ...someParameters, targetPlatform }).buildFile, + ).toStrictEqual(`${someParameters.buildName}.exe`); + }, + ); + + test.each([Platform.types.Android])('appends apk for %s', targetPlatform => { + expect( + BuildParameters.create({ ...someParameters, targetPlatform }).buildFile, + ).toStrictEqual(`${someParameters.buildName}.apk`); + }); + }); + + it('returns the build method', () => { + expect(BuildParameters.create(someParameters).buildMethod).toStrictEqual( + someParameters.buildMethod, + ); + }); + + it('returns the custom parameters', () => { + expect(BuildParameters.create(someParameters).customParameters).toStrictEqual( + someParameters.customParameters, + ); + }); + }); +}); diff --git a/src/model/index.test.js b/src/model/index.test.js new file mode 100644 index 00000000..e3337235 --- /dev/null +++ b/src/model/index.test.js @@ -0,0 +1,10 @@ +import * as Index from '.'; + +describe('Index', () => { + test.each(['Action', 'BuildParameters', 'Cache', 'Docker', 'Input', 'ImageTag', 'Platform'])( + 'exports %s', + exportedModule => { + expect(typeof Index[exportedModule]).toStrictEqual('function'); + }, + ); +}); diff --git a/src/model/input.js b/src/model/input.js index 117a4a36..e9034ba3 100644 --- a/src/model/input.js +++ b/src/model/input.js @@ -7,12 +7,16 @@ class Input { // Input variables specified in workflows using "with" prop. const unityVersion = core.getInput('unityVersion'); const targetPlatform = core.getInput('targetPlatform') || Platform.default; - const projectPath = core.getInput('projectPath') || '.'; + const rawProjectPath = core.getInput('projectPath') || '.'; const buildName = core.getInput('buildName') || targetPlatform; const buildsPath = core.getInput('buildsPath') || 'build'; const buildMethod = core.getInput('buildMethod'); // processed in docker file const customParameters = core.getInput('customParameters') || ''; + // Sanitise input + const projectPath = rawProjectPath.replace(/\/$/, ''); + + // Return sanitised input return { unityVersion, targetPlatform, diff --git a/src/model/input.test.js b/src/model/input.test.js index ea71d58a..36e56517 100644 --- a/src/model/input.test.js +++ b/src/model/input.test.js @@ -5,5 +5,9 @@ describe('Input', () => { it('does not throw', () => { expect(() => Input.getFromUser()).not.toThrow(); }); + + it('returns an object', () => { + expect(typeof Input.getFromUser()).toStrictEqual('object'); + }); }); }); diff --git a/src/model/platform.test.js b/src/model/platform.test.js new file mode 100644 index 00000000..7fb820b6 --- /dev/null +++ b/src/model/platform.test.js @@ -0,0 +1,37 @@ +import Platform from './platform'; + +describe('Platform', () => { + describe('default', () => { + it('does not throw', () => { + expect(() => Platform.default).not.toThrow(); + }); + + it('returns a string', () => { + expect(typeof Platform.default).toStrictEqual('string'); + }); + + it('returns a platform', () => { + expect(Object.values(Platform.types)).toContain(Platform.default); + }); + }); + + describe('isWindows', () => { + it('returns true for windows', () => { + expect(Platform.isWindows(Platform.types.StandaloneWindows64)).toStrictEqual(true); + }); + + it('returns false for MacOS', () => { + expect(Platform.isWindows(Platform.types.StandaloneOSX)).toStrictEqual(false); + }); + }); + + describe('isAndroid', () => { + it('returns true for Android', () => { + expect(Platform.isAndroid(Platform.types.Android)).toStrictEqual(true); + }); + + it('returns false for Windows', () => { + expect(Platform.isAndroid(Platform.types.StandaloneWindows64)).toStrictEqual(false); + }); + }); +}); diff --git a/src/model/project.js b/src/model/project.js new file mode 100644 index 00000000..c487e6a1 --- /dev/null +++ b/src/model/project.js @@ -0,0 +1,23 @@ +import Unity from './unity'; +import Input from './input'; +import Action from './action'; + +class Project { + static get relativePath() { + const { projectPath } = Input.getFromUser(); + + return `${projectPath}`; + } + + static get absolutePath() { + const { workspace } = Action; + + return `${workspace}/${this.relativePath}`; + } + + static get libraryFolder() { + return `${this.relativePath}/${Unity.libraryFolder}`; + } +} + +export default Project; diff --git a/src/model/project.test.js b/src/model/project.test.js new file mode 100644 index 00000000..8dadfaeb --- /dev/null +++ b/src/model/project.test.js @@ -0,0 +1,33 @@ +import Project from './project'; + +describe('Platform', () => { + describe('relativePath', () => { + it('does not throw', () => { + expect(() => Project.relativePath).not.toThrow(); + }); + + it('returns a string', () => { + expect(typeof Project.relativePath).toStrictEqual('string'); + }); + }); + + describe('absolutePath', () => { + it('does not throw', () => { + expect(() => Project.absolutePath).not.toThrow(); + }); + + it('returns a string', () => { + expect(typeof Project.absolutePath).toStrictEqual('string'); + }); + }); + + describe('libraryFolder', () => { + it('does not throw', () => { + expect(() => Project.libraryFolder).not.toThrow(); + }); + + it('returns a string', () => { + expect(typeof Project.libraryFolder).toStrictEqual('string'); + }); + }); +}); diff --git a/src/model/unity.js b/src/model/unity.js new file mode 100644 index 00000000..72f8e1ed --- /dev/null +++ b/src/model/unity.js @@ -0,0 +1,7 @@ +class Unity { + static get libraryFolder() { + return 'Library'; + } +} + +export default Unity; diff --git a/src/model/unity.test.js b/src/model/unity.test.js new file mode 100644 index 00000000..05cd7d02 --- /dev/null +++ b/src/model/unity.test.js @@ -0,0 +1,13 @@ +import Unity from './unity'; + +describe('Unity', () => { + describe('libraryFolder', () => { + it('does not throw', () => { + expect(() => Unity.libraryFolder).not.toThrow(); + }); + + it('returns a string', () => { + expect(typeof Unity.libraryFolder).toStrictEqual('string'); + }); + }); +});