Add more and unify tests for absent object cases
- Unify test data for nonexistence of an object/string and collection. - Introduce more test through adding missing test data to existing tests. - Improve logic for checking absence of values to match tests. - Add missing tests for absent value validation. - Update documentation to include shared test functionality.
This commit is contained in:
@@ -4,6 +4,8 @@ import { Application } from '@/domain/Application';
|
||||
import { OperatingSystem } from '@/domain/OperatingSystem';
|
||||
import { CategoryCollectionStub } from '@tests/unit/stubs/CategoryCollectionStub';
|
||||
import { ProjectInformationStub } from '@tests/unit/stubs/ProjectInformationStub';
|
||||
import { AbsentObjectTestCases, getAbsentCollectionTestCases, itEachAbsentObjectValue } from '@tests/unit/shared/TestCases/AbsentTests';
|
||||
import { ICategoryCollection } from '@/domain/ICategoryCollection';
|
||||
|
||||
describe('Application', () => {
|
||||
describe('getCollection', () => {
|
||||
@@ -33,15 +35,17 @@ describe('Application', () => {
|
||||
});
|
||||
describe('ctor', () => {
|
||||
describe('info', () => {
|
||||
it('throws if undefined', () => {
|
||||
// arrange
|
||||
const expectedError = 'undefined project information';
|
||||
const info = undefined;
|
||||
const collections = [new CategoryCollectionStub()];
|
||||
// act
|
||||
const act = () => new Application(info, collections);
|
||||
// assert
|
||||
expect(act).to.throw(expectedError);
|
||||
describe('throws if missing', () => {
|
||||
itEachAbsentObjectValue((absentValue) => {
|
||||
// arrange
|
||||
const expectedError = 'missing project information';
|
||||
const info = absentValue;
|
||||
const collections = [new CategoryCollectionStub()];
|
||||
// act
|
||||
const act = () => new Application(info, collections);
|
||||
// assert
|
||||
expect(act).to.throw(expectedError);
|
||||
});
|
||||
});
|
||||
it('sets as expected', () => {
|
||||
// arrange
|
||||
@@ -56,22 +60,21 @@ describe('Application', () => {
|
||||
describe('collections', () => {
|
||||
describe('throws on invalid value', () => {
|
||||
// arrange
|
||||
const testCases = [
|
||||
{
|
||||
name: 'undefined',
|
||||
expectedError: 'undefined collections',
|
||||
value: undefined,
|
||||
},
|
||||
{
|
||||
name: 'empty',
|
||||
expectedError: 'no collection in the list',
|
||||
value: [],
|
||||
},
|
||||
{
|
||||
name: 'undefined value in list',
|
||||
expectedError: 'undefined collection in the list',
|
||||
value: [new CategoryCollectionStub(), undefined],
|
||||
},
|
||||
const testCases: readonly {
|
||||
name: string,
|
||||
expectedError: string,
|
||||
value: readonly ICategoryCollection[],
|
||||
}[] = [
|
||||
...getAbsentCollectionTestCases<ICategoryCollection>().map((testCase) => ({
|
||||
name: testCase.valueName,
|
||||
expectedError: 'missing collections',
|
||||
value: testCase.absentValue,
|
||||
})),
|
||||
...AbsentObjectTestCases.map((testCase) => ({
|
||||
name: `${testCase.valueName} value in list`,
|
||||
expectedError: 'missing collection in the list',
|
||||
value: [new CategoryCollectionStub(), testCase.absentValue],
|
||||
})),
|
||||
{
|
||||
name: 'two collections with same OS',
|
||||
expectedError: 'multiple collections with same os: windows',
|
||||
@@ -83,12 +86,14 @@ describe('Application', () => {
|
||||
},
|
||||
];
|
||||
for (const testCase of testCases) {
|
||||
const info = new ProjectInformationStub();
|
||||
const collections = testCase.value;
|
||||
// act
|
||||
const act = () => new Application(info, collections);
|
||||
// assert
|
||||
expect(act).to.throw(testCase.expectedError);
|
||||
it(testCase.name, () => {
|
||||
const info = new ProjectInformationStub();
|
||||
const collections = testCase.value;
|
||||
// act
|
||||
const act = () => new Application(info, collections);
|
||||
// assert
|
||||
expect(act).to.throw(testCase.expectedError);
|
||||
});
|
||||
}
|
||||
});
|
||||
it('sets as expected', () => {
|
||||
|
||||
@@ -3,13 +3,20 @@ import { expect } from 'chai';
|
||||
import { Category } from '@/domain/Category';
|
||||
import { CategoryStub } from '@tests/unit/stubs/CategoryStub';
|
||||
import { ScriptStub } from '@tests/unit/stubs/ScriptStub';
|
||||
import { itEachAbsentStringValue } from '@tests/unit/shared/TestCases/AbsentTests';
|
||||
|
||||
describe('Category', () => {
|
||||
describe('ctor', () => {
|
||||
it('throws when name is empty', () => {
|
||||
const expectedError = 'undefined or empty name';
|
||||
const construct = () => new Category(5, '', [], [new CategoryStub(5)], []);
|
||||
expect(construct).to.throw(expectedError);
|
||||
describe('throws when name is absent', () => {
|
||||
itEachAbsentStringValue((absentValue) => {
|
||||
// arrange
|
||||
const expectedError = 'missing name';
|
||||
const name = absentValue;
|
||||
// act
|
||||
const construct = () => new Category(5, name, [], [new CategoryStub(5)], []);
|
||||
// assert
|
||||
expect(construct).to.throw(expectedError);
|
||||
});
|
||||
});
|
||||
it('throws when has no children', () => {
|
||||
const expectedError = 'A category must have at least one sub-category or script';
|
||||
|
||||
@@ -10,6 +10,7 @@ import { CategoryCollection } from '@/domain/CategoryCollection';
|
||||
import { ScriptStub } from '@tests/unit/stubs/ScriptStub';
|
||||
import { CategoryStub } from '@tests/unit/stubs/CategoryStub';
|
||||
import { EnumRangeTestRunner } from '@tests/unit/application/Common/EnumRangeTestRunner';
|
||||
import { itEachAbsentObjectValue } from '@tests/unit/shared/TestCases/AbsentTests';
|
||||
|
||||
describe('CategoryCollection', () => {
|
||||
describe('getScriptsByLevel', () => {
|
||||
@@ -72,24 +73,18 @@ describe('CategoryCollection', () => {
|
||||
// assert
|
||||
expect(expected).to.deep.equal(actual);
|
||||
});
|
||||
it('throws when level is undefined', () => {
|
||||
// arrange
|
||||
const sut = new CategoryCollectionBuilder()
|
||||
.construct();
|
||||
// act
|
||||
const act = () => sut.getScriptsByLevel(undefined);
|
||||
describe('throws when given invalid level', () => {
|
||||
new EnumRangeTestRunner<RecommendationLevel>((level) => {
|
||||
// arrange
|
||||
const sut = new CategoryCollectionBuilder()
|
||||
.construct();
|
||||
// act
|
||||
sut.getScriptsByLevel(level);
|
||||
})
|
||||
// assert
|
||||
expect(act).to.throw('undefined level');
|
||||
});
|
||||
it('throws when level is out of range', () => {
|
||||
// arrange
|
||||
const invalidValue = 66;
|
||||
const sut = new CategoryCollectionBuilder()
|
||||
.construct();
|
||||
// act
|
||||
const act = () => sut.getScriptsByLevel(invalidValue);
|
||||
// assert
|
||||
expect(act).to.throw(`invalid level: ${invalidValue}`);
|
||||
.testAbsentValueThrows()
|
||||
.testOutOfRangeThrows()
|
||||
.testValidValueDoesNotThrow(RecommendationLevel.Standard);
|
||||
});
|
||||
});
|
||||
describe('actions', () => {
|
||||
@@ -221,7 +216,7 @@ describe('CategoryCollection', () => {
|
||||
// assert
|
||||
new EnumRangeTestRunner(act)
|
||||
.testOutOfRangeThrows()
|
||||
.testUndefinedValueThrows();
|
||||
.testAbsentValueThrows();
|
||||
});
|
||||
});
|
||||
describe('scriptingDefinition', () => {
|
||||
@@ -235,17 +230,20 @@ describe('CategoryCollection', () => {
|
||||
// assert
|
||||
expect(sut.scripting).to.deep.equal(expected);
|
||||
});
|
||||
it('cannot construct without initial script', () => {
|
||||
// arrange
|
||||
const scriptingDefinition = undefined;
|
||||
// act
|
||||
function construct() {
|
||||
return new CategoryCollectionBuilder()
|
||||
.withScripting(scriptingDefinition)
|
||||
.construct();
|
||||
}
|
||||
// assert
|
||||
expect(construct).to.throw('undefined scripting definition');
|
||||
describe('cannot construct without initial script', () => {
|
||||
itEachAbsentObjectValue((absentValue) => {
|
||||
// arrange
|
||||
const expectedError = 'missing scripting definition';
|
||||
const scriptingDefinition = absentValue;
|
||||
// act
|
||||
function construct() {
|
||||
return new CategoryCollectionBuilder()
|
||||
.withScripting(scriptingDefinition)
|
||||
.construct();
|
||||
}
|
||||
// assert
|
||||
expect(construct).to.throw(expectedError);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -124,7 +124,7 @@ describe('ProjectInformation', () => {
|
||||
// assert
|
||||
new EnumRangeTestRunner(act)
|
||||
.testOutOfRangeThrows()
|
||||
.testUndefinedValueThrows()
|
||||
.testAbsentValueThrows()
|
||||
.testInvalidValueThrows(OperatingSystem.KaiOS, `Unsupported os: ${OperatingSystem[OperatingSystem.KaiOS]}`);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -5,6 +5,7 @@ import { Script } from '@/domain/Script';
|
||||
import { RecommendationLevel } from '@/domain/RecommendationLevel';
|
||||
import { IScriptCode } from '@/domain/IScriptCode';
|
||||
import { ScriptCodeStub } from '@tests/unit/stubs/ScriptCodeStub';
|
||||
import { itEachAbsentObjectValue } from '@tests/unit/shared/TestCases/AbsentTests';
|
||||
|
||||
describe('Script', () => {
|
||||
describe('ctor', () => {
|
||||
@@ -20,18 +21,20 @@ describe('Script', () => {
|
||||
// assert
|
||||
expect(actual).to.deep.equal(expected);
|
||||
});
|
||||
it('throws if undefined', () => {
|
||||
// arrange
|
||||
const name = 'script-name';
|
||||
const expectedError = `undefined code (script: ${name})`;
|
||||
const code: IScriptCode = undefined;
|
||||
// act
|
||||
const construct = () => new ScriptBuilder()
|
||||
.withName(name)
|
||||
.withCode(code)
|
||||
.build();
|
||||
// assert
|
||||
expect(construct).to.throw(expectedError);
|
||||
describe('throws when missing', () => {
|
||||
itEachAbsentObjectValue((absentValue) => {
|
||||
// arrange
|
||||
const name = 'script-name';
|
||||
const expectedError = `missing code (script: ${name})`;
|
||||
const code: IScriptCode = absentValue;
|
||||
// act
|
||||
const construct = () => new ScriptBuilder()
|
||||
.withName(name)
|
||||
.withCode(code)
|
||||
.build();
|
||||
// assert
|
||||
expect(construct).to.throw(expectedError);
|
||||
});
|
||||
});
|
||||
});
|
||||
describe('canRevert', () => {
|
||||
@@ -114,7 +117,7 @@ class ScriptBuilder {
|
||||
|
||||
private level = RecommendationLevel.Standard;
|
||||
|
||||
private documentationUrls: readonly string[] = undefined;
|
||||
private documentationUrls: readonly string[];
|
||||
|
||||
public withCodes(code: string, revertCode = ''): ScriptBuilder {
|
||||
this.code = new ScriptCodeStub()
|
||||
|
||||
@@ -3,6 +3,7 @@ import { expect } from 'chai';
|
||||
import { ScriptCode, ILanguageSyntax } from '@/domain/ScriptCode';
|
||||
import { IScriptCode } from '@/domain/IScriptCode';
|
||||
import { LanguageSyntaxStub } from '@tests/unit/stubs/LanguageSyntaxStub';
|
||||
import { AbsentStringTestCases, itEachAbsentObjectValue } from '@tests/unit/shared/TestCases/AbsentTests';
|
||||
|
||||
describe('ScriptCode', () => {
|
||||
describe('code', () => {
|
||||
@@ -17,22 +18,14 @@ describe('ScriptCode', () => {
|
||||
},
|
||||
expectedError: '(revert): Code itself and its reverting code cannot be the same',
|
||||
},
|
||||
{
|
||||
name: 'cannot construct with undefined "execute"',
|
||||
...AbsentStringTestCases.map((testCase) => ({
|
||||
name: `cannot construct with ${testCase.valueName} "execute"`,
|
||||
code: {
|
||||
execute: undefined,
|
||||
execute: testCase.absentValue,
|
||||
revert: 'code',
|
||||
},
|
||||
expectedError: 'code is empty or undefined',
|
||||
},
|
||||
{
|
||||
name: 'cannot construct with empty "execute"',
|
||||
code: {
|
||||
execute: '',
|
||||
revert: 'code',
|
||||
},
|
||||
expectedError: 'code is empty or undefined',
|
||||
},
|
||||
expectedError: 'missing code',
|
||||
})),
|
||||
];
|
||||
for (const testCase of testCases) {
|
||||
it(testCase.name, () => {
|
||||
@@ -142,16 +135,18 @@ describe('ScriptCode', () => {
|
||||
});
|
||||
});
|
||||
describe('syntax', () => {
|
||||
it('throws if undefined', () => {
|
||||
// arrange
|
||||
const expectedError = 'undefined syntax';
|
||||
const syntax = undefined;
|
||||
// act
|
||||
const act = () => new ScriptCodeBuilder()
|
||||
.withSyntax(syntax)
|
||||
.build();
|
||||
// assert
|
||||
expect(act).to.throw(expectedError);
|
||||
describe('throws if missing', () => {
|
||||
itEachAbsentObjectValue((absentValue) => {
|
||||
// arrange
|
||||
const expectedError = 'missing syntax';
|
||||
const syntax = absentValue;
|
||||
// act
|
||||
const act = () => new ScriptCodeBuilder()
|
||||
.withSyntax(syntax)
|
||||
.build();
|
||||
// assert
|
||||
expect(act).to.throw(expectedError);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -3,6 +3,7 @@ import { expect } from 'chai';
|
||||
import { ScriptingDefinition } from '@/domain/ScriptingDefinition';
|
||||
import { ScriptingLanguage } from '@/domain/ScriptingLanguage';
|
||||
import { getEnumValues } from '@/application/Common/Enum';
|
||||
import { itEachAbsentStringValue } from '@tests/unit/shared/TestCases/AbsentTests';
|
||||
|
||||
describe('ScriptingDefinition', () => {
|
||||
describe('language', () => {
|
||||
@@ -64,18 +65,18 @@ describe('ScriptingDefinition', () => {
|
||||
// assert
|
||||
expect(sut.startCode).to.equal(expected);
|
||||
});
|
||||
it('throws when undefined', () => {
|
||||
// arrange
|
||||
const expectedError = 'undefined start code';
|
||||
const undefinedValues = ['', undefined];
|
||||
for (const undefinedValue of undefinedValues) {
|
||||
describe('throws when absent', () => {
|
||||
itEachAbsentStringValue((absentValue) => {
|
||||
// arrange
|
||||
const expectedError = 'missing start code';
|
||||
const undefinedValue = absentValue;
|
||||
// act
|
||||
const act = () => new ScriptingDefinitionBuilder()
|
||||
.withStartCode(undefinedValue)
|
||||
.build();
|
||||
// assert
|
||||
expect(act).to.throw(expectedError);
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
describe('endCode', () => {
|
||||
@@ -89,18 +90,18 @@ describe('ScriptingDefinition', () => {
|
||||
// assert
|
||||
expect(sut.endCode).to.equal(expected);
|
||||
});
|
||||
it('throws when undefined', () => {
|
||||
// arrange
|
||||
const expectedError = 'undefined end code';
|
||||
const undefinedValues = ['', undefined];
|
||||
for (const undefinedValue of undefinedValues) {
|
||||
describe('throws when undefined', () => {
|
||||
itEachAbsentStringValue((absentValue) => {
|
||||
// arrange
|
||||
const expectedError = 'missing end code';
|
||||
const undefinedValue = absentValue;
|
||||
// act
|
||||
const act = () => new ScriptingDefinitionBuilder()
|
||||
.withEndCode(undefinedValue)
|
||||
.build();
|
||||
// assert
|
||||
expect(act).to.throw(expectedError);
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user