Skip to content

Commit 98eba58

Browse files
committed
add test for financial assessment questions
1 parent 8aa0fe6 commit 98eba58

File tree

3 files changed

+352
-0
lines changed

3 files changed

+352
-0
lines changed

lib/services/connection/api_manager/mock_api.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import 'package:flutter_deriv_api/services/connection/api_manager/exceptions/api
1414
import 'package:flutter_deriv_api/services/connection/api_manager/mock_data/account/new_account_wallet_response.dart';
1515
import 'package:flutter_deriv_api/services/connection/api_manager/mock_data/cashier/cashier_payments_response.dart';
1616
import 'package:flutter_deriv_api/services/connection/api_manager/mock_data/common/crypto_config_response.dart';
17+
import 'package:flutter_deriv_api/services/connection/api_manager/mock_data/common/financial_assessment_questions_response.dart';
1718
import 'package:flutter_deriv_api/services/connection/api_manager/mock_data/common/tin_validations_response.dart';
1819
import 'package:flutter_deriv_api/services/connection/api_manager/mock_data/passkeys/passkeys_list_response.dart';
1920
import 'package:flutter_deriv_api/services/connection/api_manager/mock_data/passkeys/passkeys_register_options_response.dart';
@@ -237,6 +238,8 @@ class MockAPI extends BaseAPI {
237238
// case 'document_upload':
238239
case 'exchange_rates':
239240
return exchangeRatesResponse;
241+
case 'financial_assessment_questions':
242+
return financialAssessmentQuestionsResponse;
240243
case 'forget':
241244
return forgetResponse;
242245
case 'forget_all':
Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
const String financialAssessmentQuestionsResponse = '''
2+
{
3+
"echo_req": {
4+
"financial_assessment_questions": 1,
5+
"req_id": 3,
6+
"version": "v1"
7+
},
8+
"financial_assessment_questions": {
9+
"questions": {
10+
"account_turnover": {
11+
"answers": [
12+
{
13+
"hide_if": [],
14+
"key": "less_than_25000",
15+
"next_node": null,
16+
"value": "Less than \$25,000"
17+
}
18+
],
19+
"hide_if": [],
20+
"question": "Anticipated annual turnover",
21+
"type": "single_choice"
22+
},
23+
"education_level": {
24+
"answers": [
25+
{
26+
"hide_if": [],
27+
"key": "primary",
28+
"next_node": "net_income",
29+
"value": "Primary"
30+
}
31+
],
32+
"hide_if": [],
33+
"question": "Education level",
34+
"type": "single_choice"
35+
},
36+
"employment_industry": {
37+
"answers": [
38+
{
39+
"hide_if": [],
40+
"key": "construction",
41+
"next_node": "occupation",
42+
"value": "Construction"
43+
}
44+
],
45+
"hide_if": [],
46+
"question": "Industry of employment",
47+
"type": "single_choice"
48+
},
49+
"employment_status": {
50+
"answers": [
51+
{
52+
"hide_if": [],
53+
"key": "employed",
54+
"next_node": "employment_industry",
55+
"value": "Employed"
56+
}
57+
],
58+
"hide_if": [],
59+
"question": "Employment status",
60+
"type": "single_choice"
61+
},
62+
"estimated_worth": {
63+
"answers": [
64+
{
65+
"hide_if": [],
66+
"key": "less_than_100000",
67+
"next_node": "account_turnover",
68+
"value": "Less than \$100,000"
69+
}
70+
],
71+
"hide_if": [],
72+
"question": "Estimated net worth",
73+
"type": "single_choice"
74+
},
75+
"income_source": {
76+
"answers": [
77+
{
78+
"hide_if": [],
79+
"key": "salaried_employee",
80+
"next_node": "source_of_wealth",
81+
"value": "Salaried Employee"
82+
}
83+
],
84+
"hide_if": [],
85+
"question": "Source of income",
86+
"type": "single_choice"
87+
},
88+
"net_income": {
89+
"answers": [
90+
{
91+
"hide_if": [],
92+
"key": "less_than_25000",
93+
"next_node": "estimated_worth",
94+
"value": "Less than \$25,000"
95+
}
96+
],
97+
"hide_if": [],
98+
"question": "Net annual income",
99+
"type": "single_choice"
100+
},
101+
"occupation": {
102+
"answers": [
103+
{
104+
"hide_if": [],
105+
"key": "chief_executives",
106+
"next_node": "income_source",
107+
"value": "Chief Executives, Senior Officials and Legislators"
108+
}
109+
],
110+
"hide_if": [],
111+
"question": "Occupation",
112+
"type": "single_choice"
113+
},
114+
"source_of_wealth": {
115+
"answers": [
116+
{
117+
"hide_if": [],
118+
"key": "income_savings",
119+
"next_node": "education_level",
120+
"value": "Accumulation of Income/Savings"
121+
}
122+
],
123+
"hide_if": [],
124+
"question": "Source of Wealth",
125+
"type": "single_choice"
126+
}
127+
},
128+
"version": "v1"
129+
},
130+
"msg_type": "financial_assessment_questions",
131+
"req_id": 3
132+
}
133+
''';
Lines changed: 216 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,216 @@
1+
import 'package:deriv_dependency_injector/dependency_injector.dart';
2+
import 'package:flutter_deriv_api/api/api_initializer.dart';
3+
import 'package:flutter_deriv_api/api/response/financial_assessment_questions_response_result.dart';
4+
import 'package:flutter_deriv_api/api/response/financial_assessment_questions_response_result_extended.dart';
5+
import 'package:flutter_deriv_api/basic_api/generated/financial_assessment_questions_send.dart';
6+
import 'package:flutter_deriv_api/services/connection/api_manager/mock_api.dart';
7+
import 'package:test/test.dart';
8+
9+
void main() {
10+
setUp(() => APIInitializer().initialize(api: MockAPI()));
11+
12+
tearDown(() => Injector().dispose());
13+
14+
group(
15+
'Financial Assessment Questions Group -> ',
16+
() {
17+
test(
18+
'Fetch Financial Assessment Questions',
19+
() async {
20+
final FinancialAssessmentQuestionsResponseModel
21+
financialAssessmentQuestions =
22+
await FinancialAssessmentQuestionsResponseExtended()
23+
.fetchFinancialAssessmentQuestions(
24+
request: const FinancialAssessmentQuestionsRequest(
25+
version: 'v1'));
26+
27+
final FinancialAssessmentQuestions? faQuestions =
28+
financialAssessmentQuestions.financialAssessmentQuestions;
29+
30+
// expect(
31+
// faQuestions?.questions?['account_turnover'],
32+
// const QuestionsProperty(
33+
// answers: [
34+
// AnswersItem(
35+
// hideIf: [],
36+
// key: 'less_than_25000',
37+
// value: 'Less than \$25,000',
38+
// ),
39+
// ],
40+
// hideIf: [],
41+
// question: 'Anticipated annual turnover',
42+
// type: TypeEnum.singleChoice,
43+
// ),
44+
// );
45+
// expect(
46+
// faQuestions?.questions?['education_level'],
47+
// const QuestionsProperty(
48+
// answers: [
49+
// AnswersItem(
50+
// hideIf: [],
51+
// key: 'primary',
52+
// value: 'Primary',
53+
// nextNode: 'net_income'),
54+
// ],
55+
// hideIf: [],
56+
// question: 'Education level',
57+
// type: TypeEnum.singleChoice,
58+
// ),
59+
// );
60+
61+
expect(
62+
faQuestions?.questions?['account_turnover'],
63+
const QuestionsProperty(
64+
answers: [
65+
AnswersItem(
66+
hideIf: [],
67+
key: 'less_than_25000',
68+
value: 'Less than \$25,000',
69+
),
70+
],
71+
hideIf: [],
72+
question: 'Anticipated annual turnover',
73+
type: TypeEnum.singleChoice,
74+
),
75+
);
76+
77+
expect(
78+
faQuestions?.questions?['education_level'],
79+
const QuestionsProperty(
80+
answers: [
81+
AnswersItem(
82+
hideIf: [],
83+
key: 'primary',
84+
value: 'Primary',
85+
nextNode: 'net_income',
86+
),
87+
],
88+
hideIf: [],
89+
question: 'Education level',
90+
type: TypeEnum.singleChoice,
91+
),
92+
);
93+
94+
expect(
95+
faQuestions?.questions?['employment_industry'],
96+
const QuestionsProperty(
97+
answers: [
98+
AnswersItem(
99+
hideIf: [],
100+
key: 'construction',
101+
value: 'Construction',
102+
nextNode: 'occupation',
103+
),
104+
],
105+
hideIf: [],
106+
question: 'Industry of employment',
107+
type: TypeEnum.singleChoice,
108+
),
109+
);
110+
111+
expect(
112+
faQuestions?.questions?['employment_status'],
113+
const QuestionsProperty(
114+
answers: [
115+
AnswersItem(
116+
hideIf: [],
117+
key: 'employed',
118+
value: 'Employed',
119+
nextNode: 'employment_industry',
120+
),
121+
],
122+
hideIf: [],
123+
question: 'Employment status',
124+
type: TypeEnum.singleChoice,
125+
),
126+
);
127+
128+
expect(
129+
faQuestions?.questions?['estimated_worth'],
130+
const QuestionsProperty(
131+
answers: [
132+
AnswersItem(
133+
hideIf: [],
134+
key: 'less_than_100000',
135+
value: 'Less than \$100,000',
136+
nextNode: 'account_turnover',
137+
),
138+
],
139+
hideIf: [],
140+
question: 'Estimated net worth',
141+
type: TypeEnum.singleChoice,
142+
),
143+
);
144+
145+
expect(
146+
faQuestions?.questions?['income_source'],
147+
const QuestionsProperty(
148+
answers: [
149+
AnswersItem(
150+
hideIf: [],
151+
key: 'salaried_employee',
152+
value: 'Salaried Employee',
153+
nextNode: 'source_of_wealth',
154+
),
155+
],
156+
hideIf: [],
157+
question: 'Source of income',
158+
type: TypeEnum.singleChoice,
159+
),
160+
);
161+
162+
expect(
163+
faQuestions?.questions?['net_income'],
164+
const QuestionsProperty(
165+
answers: [
166+
AnswersItem(
167+
hideIf: [],
168+
key: 'less_than_25000',
169+
value: 'Less than \$25,000',
170+
nextNode: 'estimated_worth',
171+
),
172+
],
173+
hideIf: [],
174+
question: 'Net annual income',
175+
type: TypeEnum.singleChoice,
176+
),
177+
);
178+
179+
expect(
180+
faQuestions?.questions?['occupation'],
181+
const QuestionsProperty(
182+
answers: [
183+
AnswersItem(
184+
hideIf: [],
185+
key: 'chief_executives',
186+
value: 'Chief Executives, Senior Officials and Legislators',
187+
nextNode: 'income_source',
188+
),
189+
],
190+
hideIf: [],
191+
question: 'Occupation',
192+
type: TypeEnum.singleChoice,
193+
),
194+
);
195+
196+
expect(
197+
faQuestions?.questions?['source_of_wealth'],
198+
const QuestionsProperty(
199+
answers: [
200+
AnswersItem(
201+
hideIf: [],
202+
key: 'income_savings',
203+
value: 'Accumulation of Income/Savings',
204+
nextNode: 'education_level',
205+
),
206+
],
207+
hideIf: [],
208+
question: 'Source of Wealth',
209+
type: TypeEnum.singleChoice,
210+
),
211+
);
212+
},
213+
);
214+
},
215+
);
216+
}

0 commit comments

Comments
 (0)