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:
undergroundwires
2022-01-21 22:34:11 +01:00
parent 0e52a99efa
commit 44d79e2c9a
100 changed files with 1380 additions and 976 deletions

View File

@@ -13,6 +13,7 @@ import { getEnumValues } from '@/application/Common/Enum';
import { CategoryCollectionStub } from '@tests/unit/stubs/CategoryCollectionStub';
import { getProcessEnvironmentStub } from '@tests/unit/stubs/ProcessEnvironmentStub';
import { CollectionDataStub } from '@tests/unit/stubs/CollectionDataStub';
import { getAbsentCollectionTestCases, AbsentObjectTestCases } from '@tests/unit/shared/TestCases/AbsentTests';
describe('ApplicationParser', () => {
describe('parseApplication', () => {
@@ -112,21 +113,23 @@ describe('ApplicationParser', () => {
describe('throws when data is invalid', () => {
// arrange
const testCases = [
{
expectedError: 'no collection provided',
data: [],
},
{
expectedError: 'undefined collection provided',
data: [new CollectionDataStub(), undefined],
},
...getAbsentCollectionTestCases<CollectionData>().map((testCase) => ({
name: `given absent collection "${testCase.valueName}"`,
value: testCase.absentValue,
expectedError: 'missing collections',
})).filter((test) => test.value !== undefined /* the default value is set */),
...AbsentObjectTestCases.map((testCase) => ({
name: `given absent item "${testCase.valueName}"`,
value: [testCase.absentValue],
expectedError: 'missing collection provided',
})),
];
for (const testCase of testCases) {
it(testCase.expectedError, () => {
it(testCase.name, () => {
const parserMock = new CategoryCollectionParserSpy().mockParser();
const env = getProcessEnvironmentStub();
// act
const act = () => parseApplication(parserMock, env, testCase.data);
const act = () => parseApplication(parserMock, env, testCase.value);
// assert
expect(act).to.throw(testCase.expectedError);
});