Skip to content

Commit

Permalink
unit test, to ensure max payments can be removed
Browse files Browse the repository at this point in the history
Signed-off-by: Ruben <[email protected]>
  • Loading branch information
Ruben authored and PeterSmallenbroek committed Jan 13, 2025
1 parent f4eae9a commit f4ee1c3
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ export interface ValidateRegistrationErrorObject {
readonly lineNumber: number;
readonly column: string;
readonly error: string;
readonly value: string | number | undefined | boolean;
readonly value: string | number | undefined | boolean | null;
}
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,8 @@ describe('RegistrationsInputValidator', () => {
id: 1,
name: 'Test Program',
languages: ['en'],
enableMaxPayments: true,
enableScope: true,
programFinancialServiceProviderConfigurations: [
{
financialServiceProviderName:
Expand Down Expand Up @@ -324,4 +326,26 @@ describe('RegistrationsInputValidator', () => {
},
]);
});

it('should add max payment when its null', async () => {
const csvArray = [
{
maxPayments: null,
},
];

const result = await validator.validateAndCleanInput({
registrationInputArray: csvArray,
programId,
userId,
typeOfInput: RegistrationValidationInputType.update,
validationConfig: {
validateExistingReferenceId: true,
validatePhoneNumberLookup: true,
validateUniqueReferenceId: true,
},
});

expect(result[0]).toHaveProperty('maxPayments');
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import { RegistrationsPaginationService } from '@121-service/src/registration/se
import { LanguageEnum } from '@121-service/src/shared/enum/language.enums';
import { UserService } from '@121-service/src/user/user.service';

type InputAttributeType = string | boolean | number | undefined;
type InputAttributeType = string | boolean | number | undefined | null;

@Injectable()
export class RegistrationsInputValidator {
Expand Down Expand Up @@ -888,7 +888,7 @@ export class RegistrationsInputValidator {
attribute,
i,
}: {
value: string[] | string | number | boolean | undefined;
value: string[] | string | number | boolean | undefined | null;
type: string;
attribute: string;
i: number;
Expand Down Expand Up @@ -932,15 +932,15 @@ export class RegistrationsInputValidator {
attribute,
}: {
type: string;
value: string[] | string | number | boolean | undefined;
value: string[] | string | number | boolean | undefined | null;
attribute: string;
}): string {
const valueString = Array.isArray(value) ? JSON.stringify(value) : value;
return `The value '${valueString}' given for the attribute '${attribute}' does not have the correct format for type '${type}'`;
}

private valueIsBool(
value: string[] | string | number | boolean | undefined,
value: string[] | string | number | boolean | undefined | null,
): boolean {
if (typeof value === 'boolean') {
return true;
Expand Down

0 comments on commit f4ee1c3

Please sign in to comment.