Skip to content

Commit

Permalink
fixed script errors & added tests
Browse files Browse the repository at this point in the history
  • Loading branch information
undergroundwires committed Jul 15, 2020
1 parent 646a8e0 commit 9e722dd
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 18 deletions.
12 changes: 6 additions & 6 deletions src/application/Parser/ApplicationParser.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
import { Category } from '../../domain/Category';
import { Application } from '../../domain/Application';
import applicationFile from 'js-yaml-loader!./../application.yaml';
import { ApplicationYaml } from 'js-yaml-loader!./../application.yaml';
import { parseCategory } from './CategoryParser';

export function parseApplication(): Application {
export function parseApplication(content: ApplicationYaml): Application {
const categories = new Array<Category>();
if (!applicationFile.actions || applicationFile.actions.length <= 0) {
if (!content.actions || content.actions.length <= 0) {
throw new Error('Application does not define any action');
}
for (const action of applicationFile.actions) {
for (const action of content.actions) {
const category = parseCategory(action);
categories.push(category);
}
const app = new Application(
applicationFile.name,
applicationFile.repositoryUrl,
content.name,
content.repositoryUrl,
process.env.VUE_APP_VERSION,
categories);
return app;
Expand Down
11 changes: 6 additions & 5 deletions src/application/State/ApplicationState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@ import { IUserFilter } from './Filter/IUserFilter';
import { ApplicationCode } from './Code/ApplicationCode';
import { UserSelection } from './Selection/UserSelection';
import { IUserSelection } from './Selection/IUserSelection';
import { AsyncLazy } from '../../infrastructure/Threading/AsyncLazy';
import { Signal } from '../../infrastructure/Events/Signal';
import { AsyncLazy } from '@/infrastructure/Threading/AsyncLazy';
import { Signal } from '@/infrastructure/Events/Signal';
import { parseApplication } from '../Parser/ApplicationParser';
import { IApplicationState } from './IApplicationState';
import { Script } from '../../domain/Script';
import { Application } from '../../domain/Application';
import { Script } from '@/domain/Script';
import { Application } from '@/domain/Application';
import { IApplicationCode } from './Code/IApplicationCode';
import applicationFile from 'js-yaml-loader!@/application/application.yaml';

/** Mutatable singleton application state that's the single source of truth throughout the application */
export class ApplicationState implements IApplicationState {
Expand All @@ -20,7 +21,7 @@ export class ApplicationState implements IApplicationState {

/** Application instance with all scripts. */
private static instance = new AsyncLazy<IApplicationState>(() => {
const application = parseApplication();
const application = parseApplication(applicationFile);
const selectedScripts = new Array<Script>();
const state = new ApplicationState(application, selectedScripts);
return Promise.resolve(state);
Expand Down
7 changes: 1 addition & 6 deletions src/application/application.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -304,14 +304,9 @@ actions:
SET /A dps_service_running=1
net stop DPS
)
REM del /F /S /Q /A "%windir%\System32\sru*"
IF !dps_service_running! == 1 (
echo "Was running"
net start DPS
) ELSE (
echo "Was not running"
)
endlocal
Expand Down Expand Up @@ -1146,7 +1141,7 @@ actions:
-
name: Disable Windows Defender
recommend: false
code: |
code: |-
netsh advfirewall set allprofiles state off
reg add "HKLM\SOFTWARE\Policies\Microsoft\Windows Defender" /v DisableAntiSpyware /t REG_DWORD /d 1 /f
reg add "HKLM\SYSTEM\CurrentControlSet\Services\MpsSvc" /v "Start" /t REG_DWORD /d 4 /f
Expand Down
2 changes: 1 addition & 1 deletion src/application/application.yaml.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ declare module 'js-yaml-loader!*' {
category: string;
}

interface ApplicationYaml {
export interface ApplicationYaml {
name: string;
repositoryUrl: string;
actions: ReadonlyArray<YamlCategory>;
Expand Down
12 changes: 12 additions & 0 deletions tests/unit/application/Parser/ApplicationParser.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import applicationFile from 'js-yaml-loader!@/application/application.yaml';
import { parseApplication } from '@/application/Parser/ApplicationParser';
import 'mocha';
import { expect } from 'chai';

describe('ApplicationParser', () => {
describe('parseApplication', () => {
it('can parse current application file', () => {
expect(() => parseApplication(applicationFile)).to.not.throw();
});
});
});

0 comments on commit 9e722dd

Please sign in to comment.