Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -166,15 +166,20 @@ export const householdAuditChecks: { [errorCode: string]: HouseholdAuditCheckFun
/**
* Check if car number and vehicles count mismatch
* validate car number is equal to vehicles count
* @param context - HouseholdAuditCheckContext
* Only check if household has vehicles and car number is defined
* @param _context - HouseholdAuditCheckContext (unused until vehicles exist as objects; see TODO below)
* @returns AuditForObject
*/
HH_L_CarNumberVehiclesCountMismatch: (context: HouseholdAuditCheckContext): AuditForObject | undefined => {
const { household } = context;
HH_L_CarNumberVehiclesCountMismatch: (_context: HouseholdAuditCheckContext): AuditForObject | undefined => {
// TODO: This check should only be run when we will have implemented vehicles as objects.
// For now, we skip it. When implementing below, you may rename `_context` to `context` for
// readability; keeping `_context` is fine too once it is used (either name is valid).

/*const { household } = _context;
const carNumber = household.carNumber;
const vehiclesCount = household.vehicles?.length;
const hasVehicles = household.vehicles !== undefined && Array.isArray(household.vehicles);

if (carNumber !== undefined && vehiclesCount !== undefined && carNumber !== vehiclesCount) {
if (carNumber !== undefined && hasVehicles && carNumber !== household.vehicles!.length) {
return {
objectType: 'household',
objectUuid: household._uuid!,
Expand All @@ -184,7 +189,7 @@ export const householdAuditChecks: { [errorCode: string]: HouseholdAuditCheckFun
message: 'Car number and vehicles count mismatch',
ignore: false
};
}
}*/

return undefined; // No audit needed
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,21 @@
*/

import { v4 as uuidV4 } from 'uuid';
import { householdAuditChecks } from '../../HouseholdAuditChecks';
import { createContextWithHouseholdAndHome } from './testHelper';
import { Vehicle } from 'evolution-common/lib/services/baseObjects/Vehicle';
import { SurveyObjectsRegistry } from 'evolution-common/lib/services/baseObjects/SurveyObjectsRegistry';
import { householdAuditChecks } from '../../HouseholdAuditChecks';
import { createContextWithHouseholdAndHome } from './testHelper';

describe('HH_L_CarNumberVehiclesCountMismatch audit check', () => {
it('is disabled: always returns undefined until vehicle objects are implemented', () => {
const context = createContextWithHouseholdAndHome({ carNumber: 2 });
expect(householdAuditChecks.HH_L_CarNumberVehiclesCountMismatch(context)).toBeUndefined();
});
});

// TODO: Re-enable (replace `describe.skip` with `describe`) once vehicles are
// implemented as first-class objects on Household.
describe.skip('HH_L_CarNumberVehiclesCountMismatch audit check (pending vehicle objects)', () => {
const validHouseholdUuid = uuidV4();
const validHomeUuid = uuidV4();
const surveyObjectsRegistry = new SurveyObjectsRegistry();
Expand Down Expand Up @@ -81,5 +90,22 @@ describe('HH_L_CarNumberVehiclesCountMismatch audit check', () => {
}
);

});
it('should fail when vehicles is empty and carNumber is > 0', () => {
const context = createContextWithHouseholdAndHome({
carNumber: 1,
vehicles: []
}, undefined, validHouseholdUuid, validHomeUuid);

const result = householdAuditChecks.HH_L_CarNumberVehiclesCountMismatch(context);

expect(result).toMatchObject({
objectType: 'household',
objectUuid: validHouseholdUuid,
errorCode: 'HH_L_CarNumberVehiclesCountMismatch',
version: 1,
level: 'error',
message: 'Car number and vehicles count mismatch',
ignore: false
});
});
});
Loading