refactor application.yaml to become an os definition #40
This commit is contained in:
@@ -1,7 +1,14 @@
|
||||
import { ScriptingDefinitionStub } from './ScriptingDefinitionStub';
|
||||
import { IApplication, ICategory, IScript } from '@/domain/IApplication';
|
||||
import { ProjectInformation } from '@/domain/ProjectInformation';
|
||||
import { OperatingSystem } from '@/domain/OperatingSystem';
|
||||
import { ScriptStub } from './ScriptStub';
|
||||
import { IScriptingDefinition } from '@/domain/IScriptingDefinition';
|
||||
|
||||
export class ApplicationStub implements IApplication {
|
||||
public scripting: IScriptingDefinition = new ScriptingDefinitionStub();
|
||||
public os = OperatingSystem.Linux;
|
||||
public initialScript: IScript = new ScriptStub('55');
|
||||
public totalScripts = 0;
|
||||
public totalCategories = 0;
|
||||
public readonly info = new ProjectInformation('StubApplication', '0.1.0', 'https://github.com/undergroundwires/privacy.sexy', 'https://privacy.sexy');
|
||||
@@ -11,6 +18,18 @@ export class ApplicationStub implements IApplication {
|
||||
this.actions.push(category);
|
||||
return this;
|
||||
}
|
||||
public withOs(os: OperatingSystem): ApplicationStub {
|
||||
this.os = os;
|
||||
return this;
|
||||
}
|
||||
public withScripting(scripting: IScriptingDefinition): ApplicationStub {
|
||||
this.scripting = scripting;
|
||||
return this;
|
||||
}
|
||||
public withInitialScript(script: IScript): ApplicationStub {
|
||||
this.initialScript = script;
|
||||
return this;
|
||||
}
|
||||
public findCategory(categoryId: number): ICategory {
|
||||
return this.getAllCategories().find(
|
||||
(category) => category.id === categoryId);
|
||||
|
||||
15
tests/unit/stubs/EnumParserStub.ts
Normal file
15
tests/unit/stubs/EnumParserStub.ts
Normal file
@@ -0,0 +1,15 @@
|
||||
import { IEnumParser } from '@/application/Common/Enum';
|
||||
|
||||
export function mockEnumParser<T>(inputName: string, inputValue: string, outputValue: T): IEnumParser<T> {
|
||||
return {
|
||||
parseEnum: (value, name) => {
|
||||
if (name !== inputName) {
|
||||
throw new Error(`Unexpected name: "${name}"`);
|
||||
}
|
||||
if (value !== inputValue) {
|
||||
throw new Error(`Unexpected value: "${value}"`);
|
||||
}
|
||||
return outputValue;
|
||||
},
|
||||
};
|
||||
}
|
||||
43
tests/unit/stubs/ProjectInformationStub.ts
Normal file
43
tests/unit/stubs/ProjectInformationStub.ts
Normal file
@@ -0,0 +1,43 @@
|
||||
import { IProjectInformation } from '@/domain/IProjectInformation';
|
||||
import { OperatingSystem } from '@/domain/OperatingSystem';
|
||||
|
||||
export class ProjectInformationStub implements IProjectInformation {
|
||||
public name: string;
|
||||
public version: string;
|
||||
public repositoryUrl: string;
|
||||
public homepage: string;
|
||||
public feedbackUrl: string;
|
||||
public releaseUrl: string;
|
||||
public repositoryWebUrl: string;
|
||||
public withName(name: string): ProjectInformationStub {
|
||||
this.name = name;
|
||||
return this;
|
||||
}
|
||||
public withVersion(version: string): ProjectInformationStub {
|
||||
this.version = version;
|
||||
return this;
|
||||
}
|
||||
public withRepositoryUrl(repositoryUrl: string): ProjectInformationStub {
|
||||
this.repositoryUrl = repositoryUrl;
|
||||
return this;
|
||||
}
|
||||
public withHomepageUrl(homepageUrl: string): ProjectInformationStub {
|
||||
this.homepage = homepageUrl;
|
||||
return this;
|
||||
}
|
||||
public withFeedbackUrl(feedbackUrl: string): ProjectInformationStub {
|
||||
this.feedbackUrl = feedbackUrl;
|
||||
return this;
|
||||
}
|
||||
public withReleaseUrl(releaseUrl: string): ProjectInformationStub {
|
||||
this.releaseUrl = releaseUrl;
|
||||
return this;
|
||||
}
|
||||
public withRepositoryWebUrl(repositoryWebUrl: string): ProjectInformationStub {
|
||||
this.repositoryWebUrl = repositoryWebUrl;
|
||||
return this;
|
||||
}
|
||||
public getDownloadUrl(os: OperatingSystem): string {
|
||||
throw new Error('Method not implemented.');
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
import { BaseEntity } from '@/infrastructure/Entity/BaseEntity';
|
||||
import { IScript } from '@/domain/IScript';
|
||||
import { RecommendationLevel } from '@/domain/RecommendationLevel';
|
||||
import { SelectedScript } from '@/application/State/Selection/SelectedScript';
|
||||
|
||||
export class ScriptStub extends BaseEntity<string> implements IScript {
|
||||
public name = `name${this.id}`;
|
||||
@@ -38,4 +39,8 @@ export class ScriptStub extends BaseEntity<string> implements IScript {
|
||||
this.code.revert = revertCode;
|
||||
return this;
|
||||
}
|
||||
|
||||
public toSelectedScript(isReverted = false): SelectedScript {
|
||||
return new SelectedScript(this, isReverted);
|
||||
}
|
||||
}
|
||||
|
||||
18
tests/unit/stubs/ScriptingDefinitionStub.ts
Normal file
18
tests/unit/stubs/ScriptingDefinitionStub.ts
Normal file
@@ -0,0 +1,18 @@
|
||||
import { IScriptingDefinition } from '@/domain/IScriptingDefinition';
|
||||
import { ScriptingLanguage } from '@/domain/ScriptingLanguage';
|
||||
|
||||
export class ScriptingDefinitionStub implements IScriptingDefinition {
|
||||
public fileExtension: string = '.bat';
|
||||
public language = ScriptingLanguage.batchfile;
|
||||
public startCode = 'REM start code';
|
||||
public endCode = 'REM end code';
|
||||
|
||||
public withStartCode(startCode: string): ScriptingDefinitionStub {
|
||||
this.startCode = startCode;
|
||||
return this;
|
||||
}
|
||||
public withEndCode(endCode: string): ScriptingDefinitionStub {
|
||||
this.endCode = endCode;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
@@ -58,4 +58,10 @@ export class YamlScriptStub implements YamlScript {
|
||||
this.call = call;
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
public withRecommend(recommend: string): YamlScriptStub {
|
||||
this.recommend = recommend;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user