144 lines
3.9 KiB
TypeScript
144 lines
3.9 KiB
TypeScript
import { ICollateralType, ICollateralTypesToVehicleType, getCollateralTypesFromVehicleType, IAllowedStatusChange, getViableStatuses } from "./SettingsReducer";
|
|
|
|
describe('Settings Reducer', () => {
|
|
const collateralTypes: ICollateralType[] = [
|
|
{
|
|
id: 1,
|
|
description: 'Collateral Type 1',
|
|
lookupHandler: '',
|
|
},
|
|
{
|
|
id: 4,
|
|
description: 'Collateral Type 4',
|
|
lookupHandler: '',
|
|
},
|
|
{
|
|
id: 2,
|
|
description: 'Collateral Type 2',
|
|
lookupHandler: '',
|
|
},
|
|
{
|
|
id: 3,
|
|
description: 'Collateral Type 3',
|
|
lookupHandler: '',
|
|
},
|
|
];
|
|
const collateralTypeToVehicleTypes: ICollateralTypesToVehicleType[] = [
|
|
{
|
|
id: 1,
|
|
vehicleTypeId: 1,
|
|
collateralTypeId: 1,
|
|
},
|
|
{
|
|
id: 2,
|
|
vehicleTypeId: 1,
|
|
collateralTypeId: 3,
|
|
},
|
|
{
|
|
id: 3,
|
|
vehicleTypeId: 2,
|
|
collateralTypeId: 10,
|
|
},
|
|
{
|
|
id: 2,
|
|
vehicleTypeId: 1,
|
|
collateralTypeId: 3,
|
|
},
|
|
{
|
|
id: 1,
|
|
vehicleTypeId: 1,
|
|
collateralTypeId: 1,
|
|
},
|
|
];
|
|
|
|
it('Get Valid Collateral Types from Vehicle Type', () => {
|
|
const foundCollateral = getCollateralTypesFromVehicleType(
|
|
collateralTypeToVehicleTypes,
|
|
collateralTypes,
|
|
1,
|
|
);
|
|
expect(foundCollateral).toEqual([
|
|
{
|
|
id: 1,
|
|
description: 'Collateral Type 1',
|
|
lookupHandler: '',
|
|
},
|
|
{
|
|
id: 3,
|
|
description: 'Collateral Type 3',
|
|
lookupHandler: '',
|
|
},
|
|
]);
|
|
});
|
|
|
|
it('Get Empty Array For Un-Matched Vehciel Type', () => {
|
|
const foundCollateral = getCollateralTypesFromVehicleType(
|
|
collateralTypeToVehicleTypes,
|
|
collateralTypes,
|
|
5,
|
|
);
|
|
expect(foundCollateral).toEqual([]);
|
|
});
|
|
|
|
it('Get Empty Array For Un-Matched Collateral Type', () => {
|
|
const foundCollateral = getCollateralTypesFromVehicleType(
|
|
collateralTypeToVehicleTypes,
|
|
collateralTypes,
|
|
2,
|
|
);
|
|
expect(foundCollateral).toEqual([]);
|
|
});
|
|
|
|
it('Get Empty Array For Undefined Vehciel Type', () => {
|
|
const foundCollateral = getCollateralTypesFromVehicleType(
|
|
collateralTypeToVehicleTypes,
|
|
collateralTypes,
|
|
);
|
|
expect(foundCollateral).toEqual([]);
|
|
});
|
|
|
|
it ('Viable status changes produces correct relations', () => {
|
|
const dummyAllowedStatusChanges: IAllowedStatusChange[] = [
|
|
{
|
|
id: 0,
|
|
currentStatus: 'A',
|
|
allowedChangeStatus: 'B',
|
|
},
|
|
{
|
|
id: 1,
|
|
currentStatus: 'A',
|
|
allowedChangeStatus: 'B',
|
|
},
|
|
{
|
|
id: 1,
|
|
currentStatus: 'A',
|
|
allowedChangeStatus: 'B',
|
|
},
|
|
{
|
|
id: 1,
|
|
currentStatus: 'A',
|
|
allowedChangeStatus: ' B ',
|
|
},
|
|
{
|
|
id: 2,
|
|
currentStatus: 'A',
|
|
allowedChangeStatus: 'C',
|
|
},
|
|
{
|
|
id: 3,
|
|
currentStatus: 'H',
|
|
allowedChangeStatus: 'A',
|
|
},
|
|
{
|
|
id: 4,
|
|
currentStatus: 'A',
|
|
allowedChangeStatus: 'A',
|
|
}
|
|
];
|
|
|
|
expect(getViableStatuses('A', dummyAllowedStatusChanges)).toStrictEqual(['A', 'B', 'C']);
|
|
expect(getViableStatuses('H', dummyAllowedStatusChanges)).toStrictEqual(['H', 'A']);
|
|
expect(getViableStatuses('F', dummyAllowedStatusChanges)).toStrictEqual(['F']);
|
|
});
|
|
|
|
}); |