Skip to content
Closed
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
15 changes: 15 additions & 0 deletions src/subdomains/generic/kyc/dto/output/kyc-financial-out.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,14 @@ export class KycFinancialOption {
text: string;
}

export class KycFinancialCondition {
@ApiProperty({ description: 'Key of the prerequisite question that must be answered first.' })
question: string;

@ApiProperty({ description: 'Answer value of the prerequisite question that activates this question.' })
response: string;
}

export class KycFinancialQuestion {
@ApiProperty({ description: 'Question key' })
key: string;
Expand All @@ -25,6 +33,13 @@ export class KycFinancialQuestion {

@ApiPropertyOptional({ description: 'Response options', type: KycFinancialOption, isArray: true })
options?: KycFinancialOption[];

@ApiPropertyOptional({
description: 'Preconditions under which this question applies. Omitted when the question is always applicable.',
type: KycFinancialCondition,
isArray: true,
})
conditions?: KycFinancialCondition[];
}

export class KycFinancialOutData extends KycFinancialInData {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import { mock } from 'jest-mock-extended';
import { I18nService } from 'nestjs-i18n';
import { AccountType } from 'src/subdomains/generic/user/models/user-data/account-type.enum';
import { getFinancialQuestions } from '../../../config/financial-questions';
import { FinancialService } from '../financial.service';

describe('FinancialService', () => {
let service: FinancialService;
const i18n = mock<I18nService>();

beforeEach(() => {
jest.clearAllMocks();
i18n.translate.mockImplementation((key: string) => key);
service = new FinancialService(i18n);
});

describe('getQuestions', () => {
it('maps conditions from the catalog and omits them when absent', () => {
const accountType = AccountType.PERSONAL;
const catalog = getFinancialQuestions(accountType);
const withConditions = catalog.filter((q) => q.conditions?.length);
const withoutConditions = catalog.filter((q) => !q.conditions?.length);

expect(withConditions.length).toBeGreaterThan(0);
expect(withoutConditions.length).toBeGreaterThan(0);

const questions = service.getQuestions('en', accountType);

expect(questions).toHaveLength(catalog.length);

catalog.forEach((catalogQuestion, index) => {
const mapped = questions[index];
expect(mapped.key).toBe(catalogQuestion.key);

if (catalogQuestion.conditions?.length) {
expect(mapped.conditions).toEqual(catalogQuestion.conditions);
for (const condition of mapped.conditions) {
expect(Object.keys(condition).sort()).toEqual(['question', 'response']);
expect(typeof condition.question).toBe('string');
expect(typeof condition.response).toBe('string');
}
} else {
expect(mapped.conditions).toBeUndefined();
}
});
});
});
});