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,29 +4,36 @@ import { CodeSubstituter } from '@/application/Parser/ScriptingDefinition/CodeSu
|
||||
import { IExpressionsCompiler } from '@/application/Parser/Script/Compiler/Expressions/IExpressionsCompiler';
|
||||
import { ProjectInformationStub } from '@tests/unit/stubs/ProjectInformationStub';
|
||||
import { ExpressionsCompilerStub } from '@tests/unit/stubs/ExpressionsCompilerStub';
|
||||
import { AbsentObjectTestCases, AbsentStringTestCases } from '@tests/unit/shared/TestCases/AbsentTests';
|
||||
|
||||
describe('CodeSubstituter', () => {
|
||||
describe('throws with invalid parameters', () => {
|
||||
// arrange
|
||||
const testCases = [{
|
||||
expectedError: 'undefined code',
|
||||
parameters: {
|
||||
code: undefined,
|
||||
info: new ProjectInformationStub(),
|
||||
},
|
||||
},
|
||||
{
|
||||
expectedError: 'undefined info',
|
||||
parameters: {
|
||||
code: 'non empty code',
|
||||
info: undefined,
|
||||
},
|
||||
}];
|
||||
const testCases = [
|
||||
...AbsentStringTestCases.map((testCase) => ({
|
||||
name: `given code: ${testCase.valueName}`,
|
||||
expectedError: 'missing code',
|
||||
parameters: {
|
||||
code: testCase.absentValue,
|
||||
info: new ProjectInformationStub(),
|
||||
},
|
||||
})),
|
||||
...AbsentObjectTestCases.map((testCase) => ({
|
||||
name: `given info: ${testCase.valueName}`,
|
||||
expectedError: 'missing info',
|
||||
parameters: {
|
||||
code: 'non empty code',
|
||||
info: testCase.absentValue,
|
||||
},
|
||||
})),
|
||||
];
|
||||
for (const testCase of testCases) {
|
||||
it(`throws "${testCase.expectedError}" as expected`, () => {
|
||||
it(`${testCase.name} throws "${testCase.expectedError}"`, () => {
|
||||
// arrange
|
||||
const sut = new CodeSubstituterBuilder().build();
|
||||
const { code, info } = testCase.parameters;
|
||||
// act
|
||||
const act = () => sut.substitute(testCase.parameters.code, testCase.parameters.info);
|
||||
const act = () => sut.substitute(code, info);
|
||||
// assert
|
||||
expect(act).to.throw(testCase.expectedError);
|
||||
});
|
||||
|
||||
@@ -9,30 +9,37 @@ import { ProjectInformationStub } from '@tests/unit/stubs/ProjectInformationStub
|
||||
import { EnumParserStub } from '@tests/unit/stubs/EnumParserStub';
|
||||
import { ScriptingDefinitionDataStub } from '@tests/unit/stubs/ScriptingDefinitionDataStub';
|
||||
import { CodeSubstituterStub } from '@tests/unit/stubs/CodeSubstituterStub';
|
||||
import { itEachAbsentObjectValue } from '@tests/unit/shared/TestCases/AbsentTests';
|
||||
|
||||
describe('ScriptingDefinitionParser', () => {
|
||||
describe('parseScriptingDefinition', () => {
|
||||
it('throws when info is undefined', () => {
|
||||
// arrange
|
||||
const info = undefined;
|
||||
const definition = new ScriptingDefinitionDataStub();
|
||||
const sut = new ScriptingDefinitionParserBuilder()
|
||||
.build();
|
||||
// act
|
||||
const act = () => sut.parse(definition, info);
|
||||
// assert
|
||||
expect(act).to.throw('undefined info');
|
||||
describe('throws when info is missing', () => {
|
||||
itEachAbsentObjectValue((absentValue) => {
|
||||
// arrange
|
||||
const expectedError = 'missing info';
|
||||
const info = absentValue;
|
||||
const definition = new ScriptingDefinitionDataStub();
|
||||
const sut = new ScriptingDefinitionParserBuilder()
|
||||
.build();
|
||||
// act
|
||||
const act = () => sut.parse(definition, info);
|
||||
// assert
|
||||
expect(act).to.throw(expectedError);
|
||||
});
|
||||
});
|
||||
it('throws when definition is undefined', () => {
|
||||
// arrange
|
||||
const info = new ProjectInformationStub();
|
||||
const definition = undefined;
|
||||
const sut = new ScriptingDefinitionParserBuilder()
|
||||
.build();
|
||||
// act
|
||||
const act = () => sut.parse(definition, info);
|
||||
// assert
|
||||
expect(act).to.throw('undefined definition');
|
||||
describe('throws when definition is missing', () => {
|
||||
itEachAbsentObjectValue((absentValue) => {
|
||||
// arrange
|
||||
const expectedError = 'missing definition';
|
||||
const info = new ProjectInformationStub();
|
||||
const definition = absentValue;
|
||||
const sut = new ScriptingDefinitionParserBuilder()
|
||||
.build();
|
||||
// act
|
||||
const act = () => sut.parse(definition, info);
|
||||
// assert
|
||||
expect(act).to.throw(expectedError);
|
||||
});
|
||||
});
|
||||
describe('language', () => {
|
||||
it('parses as expected', () => {
|
||||
|
||||
Reference in New Issue
Block a user