added ability to revert (#21)
This commit is contained in:
@@ -1,12 +1,115 @@
|
||||
import applicationFile from 'js-yaml-loader!@/application/application.yaml';
|
||||
import { IEntity } from '@/infrastructure/Entity/IEntity';
|
||||
import applicationFile, { YamlCategory, YamlScript, ApplicationYaml } from 'js-yaml-loader!@/application/application.yaml';
|
||||
import { parseApplication } from '@/application/Parser/ApplicationParser';
|
||||
import 'mocha';
|
||||
import { expect } from 'chai';
|
||||
import { parseCategory } from '@/application/Parser/CategoryParser';
|
||||
|
||||
declare var process;
|
||||
|
||||
describe('ApplicationParser', () => {
|
||||
describe('parseApplication', () => {
|
||||
it('can parse current application file', () => {
|
||||
expect(() => parseApplication(applicationFile)).to.not.throw();
|
||||
});
|
||||
it('throws when undefined', () => {
|
||||
expect(() => parseApplication(undefined)).to.throw('application is null or undefined');
|
||||
});
|
||||
it('throws when undefined actions', () => {
|
||||
const sut: ApplicationYaml = {
|
||||
name: 'test',
|
||||
repositoryUrl: 'https://privacy.sexy',
|
||||
actions: undefined,
|
||||
};
|
||||
expect(() => parseApplication(sut)).to.throw('application does not define any action');
|
||||
});
|
||||
it('throws when has no actions', () => {
|
||||
const sut: ApplicationYaml = {
|
||||
name: 'test',
|
||||
repositoryUrl: 'https://privacy.sexy',
|
||||
actions: [],
|
||||
};
|
||||
expect(() => parseApplication(sut)).to.throw('application does not define any action');
|
||||
});
|
||||
it('returns expected name', () => {
|
||||
// arrange
|
||||
const expected = 'test-app-name';
|
||||
const sut: ApplicationYaml = {
|
||||
name: expected,
|
||||
repositoryUrl: 'https://privacy.sexy',
|
||||
actions: [ getTestCategory() ],
|
||||
};
|
||||
// act
|
||||
const actual = parseApplication(sut).name;
|
||||
// assert
|
||||
expect(actual).to.be.equal(actual);
|
||||
});
|
||||
it('returns expected repository url', () => {
|
||||
// arrange
|
||||
const expected = 'https://privacy.sexy';
|
||||
const sut: ApplicationYaml = {
|
||||
name: 'name',
|
||||
repositoryUrl: expected,
|
||||
actions: [ getTestCategory() ],
|
||||
};
|
||||
// act
|
||||
const actual = parseApplication(sut).repositoryUrl;
|
||||
// assert
|
||||
expect(actual).to.be.equal(actual);
|
||||
});
|
||||
it('returns expected repository version', () => {
|
||||
// arrange
|
||||
const expected = '1.0.0';
|
||||
process = {
|
||||
env: {
|
||||
VUE_APP_VERSION: expected,
|
||||
},
|
||||
};
|
||||
const sut: ApplicationYaml = {
|
||||
name: 'name',
|
||||
repositoryUrl: 'https://privacy.sexy',
|
||||
actions: [ getTestCategory() ],
|
||||
};
|
||||
// act
|
||||
const actual = parseApplication(sut).version;
|
||||
// assert
|
||||
expect(actual).to.be.equal(actual);
|
||||
});
|
||||
it('parses actions', () => {
|
||||
// arrange
|
||||
const actions = [ getTestCategory('test1'), getTestCategory('test2') ];
|
||||
const expected = [ parseCategory(actions[0]), parseCategory(actions[1]) ];
|
||||
const sut: ApplicationYaml = {
|
||||
name: 'name',
|
||||
repositoryUrl: 'https://privacy.sexy',
|
||||
actions,
|
||||
};
|
||||
// act
|
||||
const actual = parseApplication(sut).actions;
|
||||
// assert
|
||||
expect(excludingId(actual)).to.be.deep.equal(excludingId(expected));
|
||||
function excludingId<TId>(array: ReadonlyArray<IEntity<TId>>) {
|
||||
return array.map((obj) => {
|
||||
const { ['id']: omitted, ...rest } = obj;
|
||||
return rest;
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
function getTestCategory(scriptName = 'testScript'): YamlCategory {
|
||||
return {
|
||||
category: 'category name',
|
||||
children: [ getTestScript(scriptName) ],
|
||||
};
|
||||
}
|
||||
|
||||
function getTestScript(scriptName: string): YamlScript {
|
||||
return {
|
||||
name: scriptName,
|
||||
code: 'script code',
|
||||
revertCode: 'revert code',
|
||||
recommend: true,
|
||||
};
|
||||
}
|
||||
|
||||
109
tests/unit/application/Parser/CategoryParser.spec.ts
Normal file
109
tests/unit/application/Parser/CategoryParser.spec.ts
Normal file
@@ -0,0 +1,109 @@
|
||||
import 'mocha';
|
||||
import { expect } from 'chai';
|
||||
import { parseCategory } from '@/application/Parser/CategoryParser';
|
||||
import { YamlCategory, CategoryOrScript, YamlScript } from 'js-yaml-loader!./application.yaml';
|
||||
import { parseScript } from '@/application/Parser/ScriptParser';
|
||||
import { parseDocUrls } from '@/application/Parser/DocumentationParser';
|
||||
|
||||
describe('CategoryParser', () => {
|
||||
describe('parseCategory', () => {
|
||||
|
||||
it('throws when undefined', () => {
|
||||
expect(() => parseCategory(undefined)).to.throw('category is null or undefined');
|
||||
});
|
||||
|
||||
it('throws when children is empty', () => {
|
||||
const category: YamlCategory = {
|
||||
category: 'test',
|
||||
children: [],
|
||||
};
|
||||
expect(() => parseCategory(category)).to.throw('category has no children');
|
||||
});
|
||||
|
||||
it('throws when children is undefined', () => {
|
||||
const category: YamlCategory = {
|
||||
category: 'test',
|
||||
children: undefined,
|
||||
};
|
||||
expect(() => parseCategory(category)).to.throw('category has no children');
|
||||
});
|
||||
|
||||
it('throws when name is empty', () => {
|
||||
const category: YamlCategory = {
|
||||
category: '',
|
||||
children: getTestChildren(),
|
||||
};
|
||||
expect(() => parseCategory(category)).to.throw('category has no name');
|
||||
});
|
||||
|
||||
it('throws when name is undefined', () => {
|
||||
const category: YamlCategory = {
|
||||
category: undefined,
|
||||
children: getTestChildren(),
|
||||
};
|
||||
expect(() => parseCategory(category)).to.throw('category has no name');
|
||||
});
|
||||
|
||||
it('returns expected docs', () => {
|
||||
// arrange
|
||||
const url = 'https://privacy.sexy';
|
||||
const expected = parseDocUrls({ docs: url });
|
||||
const category: YamlCategory = {
|
||||
category: 'category name',
|
||||
children: getTestChildren(),
|
||||
docs: url,
|
||||
};
|
||||
// act
|
||||
const actual = parseCategory(category).documentationUrls;
|
||||
// assert
|
||||
expect(actual).to.deep.equal(expected);
|
||||
});
|
||||
|
||||
it('returns expected scripts', () => {
|
||||
// arrange
|
||||
const script = getTestScript();
|
||||
const expected = [ parseScript(script) ];
|
||||
const category: YamlCategory = {
|
||||
category: 'category name',
|
||||
children: [ script ],
|
||||
};
|
||||
// act
|
||||
const actual = parseCategory(category).scripts;
|
||||
// assert
|
||||
expect(actual).to.deep.equal(expected);
|
||||
});
|
||||
|
||||
it('returns expected subcategories', () => {
|
||||
// arrange
|
||||
const expected: YamlCategory[] = [ {
|
||||
category: 'test category',
|
||||
children: [ getTestScript() ],
|
||||
}];
|
||||
const category: YamlCategory = {
|
||||
category: 'category name',
|
||||
children: expected,
|
||||
};
|
||||
// act
|
||||
const actual = parseCategory(category).subCategories;
|
||||
// assert
|
||||
expect(actual).to.have.lengthOf(1);
|
||||
expect(actual[0].name).to.equal(expected[0].category);
|
||||
expect(actual[0].scripts.length).to.equal(expected[0].children.length);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
function getTestChildren(): ReadonlyArray<CategoryOrScript> {
|
||||
return [
|
||||
getTestScript(),
|
||||
];
|
||||
}
|
||||
|
||||
function getTestScript(): YamlScript {
|
||||
return {
|
||||
name: 'script name',
|
||||
code: 'script code',
|
||||
revertCode: 'revert code',
|
||||
recommend: true,
|
||||
};
|
||||
}
|
||||
39
tests/unit/application/Parser/DocumentationParser.spec.ts
Normal file
39
tests/unit/application/Parser/DocumentationParser.spec.ts
Normal file
@@ -0,0 +1,39 @@
|
||||
import 'mocha';
|
||||
import { expect } from 'chai';
|
||||
import { YamlDocumentable } from 'js-yaml-loader!./application.yaml';
|
||||
import { parseDocUrls } from '@/application/Parser/DocumentationParser';
|
||||
|
||||
describe('DocumentationParser', () => {
|
||||
describe('parseDocUrls', () => {
|
||||
it('throws when undefined', () => {
|
||||
expect(() => parseDocUrls(undefined)).to.throw('documentable is null or undefined');
|
||||
});
|
||||
it('returns empty when empty', () => {
|
||||
// arrange
|
||||
const empty: YamlDocumentable = { };
|
||||
// act
|
||||
const actual = parseDocUrls(empty);
|
||||
// assert
|
||||
expect(actual).to.have.lengthOf(0);
|
||||
});
|
||||
it('returns single item when string', () => {
|
||||
// arrange
|
||||
const url = 'https://privacy.sexy';
|
||||
const expected = [ url ];
|
||||
const sut: YamlDocumentable = { docs: url };
|
||||
// act
|
||||
const actual = parseDocUrls(sut);
|
||||
// assert
|
||||
expect(actual).to.deep.equal(expected);
|
||||
});
|
||||
it('returns all when array', () => {
|
||||
// arrange
|
||||
const expected = [ 'https://privacy.sexy', 'https://github.com/undergroundwires/privacy.sexy' ];
|
||||
const sut: YamlDocumentable = { docs: expected };
|
||||
// act
|
||||
const actual = parseDocUrls(sut);
|
||||
// assert
|
||||
expect(actual).to.deep.equal(expected);
|
||||
});
|
||||
});
|
||||
});
|
||||
28
tests/unit/application/Parser/ScriptParser.spec.ts
Normal file
28
tests/unit/application/Parser/ScriptParser.spec.ts
Normal file
@@ -0,0 +1,28 @@
|
||||
import { YamlScript } from 'js-yaml-loader!./application.yaml';
|
||||
import 'mocha';
|
||||
import { expect } from 'chai';
|
||||
import { parseScript } from '@/application/Parser/ScriptParser';
|
||||
import { parseDocUrls } from '@/application/Parser/DocumentationParser';
|
||||
|
||||
describe('ScriptParser', () => {
|
||||
describe('parseScript', () => {
|
||||
it('parseScript parses as expected', () => {
|
||||
// arrange
|
||||
const expected: YamlScript = {
|
||||
name: 'expected name',
|
||||
code: 'expected code',
|
||||
revertCode: 'expected revert code',
|
||||
docs: ['hello.com'],
|
||||
recommend: true,
|
||||
};
|
||||
// act
|
||||
const actual = parseScript(expected);
|
||||
// assert
|
||||
expect(actual.name).to.equal(expected.name);
|
||||
expect(actual.code).to.equal(expected.code);
|
||||
expect(actual.revertCode).to.equal(expected.revertCode);
|
||||
expect(actual.documentationUrls).to.deep.equal(parseDocUrls(expected));
|
||||
expect(actual.isRecommended).to.equal(expected.recommend);
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user