Skip to content

Commit 724c2c6

Browse files
committed
test: fix changenow test to explicitly pass an invalid api key
on github, the changenow api key is populated and real so the tests were throwing
1 parent 578b5ca commit 724c2c6

1 file changed

Lines changed: 19 additions & 10 deletions

File tree

test/services/change_now/change_now_test.dart

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ import 'change_now_test.mocks.dart';
1616

1717
@GenerateMocks([HTTP])
1818
void main() {
19+
const testApiKey = 'testAPIKEY';
20+
1921
Uri buildV2Uri(String path, [Map<String, String>? params]) {
2022
return Uri.https('api.changenow.io', '/v2$path', params);
2123
}
@@ -70,15 +72,15 @@ void main() {
7072
when(
7173
client.get(
7274
url: buildV2Uri('/exchange/currencies', {'flow': 'standard'}),
73-
headers: changeNowHeaders(),
75+
headers: changeNowHeaders(testApiKey),
7476
proxyInfo: null,
7577
),
7678
).thenAnswer(
7779
(_) async =>
7880
Response(utf8.encode(jsonEncode(availableCurrenciesJSON)), 200),
7981
);
8082

81-
final result = await instance.getAvailableCurrencies();
83+
final result = await instance.getAvailableCurrencies(apiKey: testApiKey);
8284

8385
expect(result.exception, null);
8486
expect(result.value == null, false);
@@ -95,7 +97,7 @@ void main() {
9597
'flow': 'standard',
9698
'active': 'true',
9799
}),
98-
headers: changeNowHeaders(),
100+
headers: changeNowHeaders(testApiKey),
99101
proxyInfo: null,
100102
),
101103
).thenAnswer(
@@ -105,7 +107,10 @@ void main() {
105107
),
106108
);
107109

108-
final result = await instance.getAvailableCurrencies(active: true);
110+
final result = await instance.getAvailableCurrencies(
111+
active: true,
112+
apiKey: testApiKey,
113+
);
109114

110115
expect(result.exception, null);
111116
expect(result.value == null, false);
@@ -119,7 +124,7 @@ void main() {
119124
when(
120125
client.get(
121126
url: buildV2Uri('/exchange/currencies', {'flow': 'fixed-rate'}),
122-
headers: changeNowHeaders(),
127+
headers: changeNowHeaders(testApiKey),
123128
proxyInfo: null,
124129
),
125130
).thenAnswer(
@@ -131,6 +136,7 @@ void main() {
131136

132137
final result = await instance.getAvailableCurrencies(
133138
flow: CNFlow.fixedRate,
139+
apiKey: testApiKey,
134140
);
135141

136142
expect(result.exception, null);
@@ -150,7 +156,7 @@ void main() {
150156
'flow': 'fixed-rate',
151157
'active': 'true',
152158
}),
153-
headers: changeNowHeaders(),
159+
headers: changeNowHeaders(testApiKey),
154160
proxyInfo: null,
155161
),
156162
).thenAnswer(
@@ -163,6 +169,7 @@ void main() {
163169
final result = await instance.getAvailableCurrencies(
164170
active: true,
165171
flow: CNFlow.fixedRate,
172+
apiKey: testApiKey,
166173
);
167174

168175
expect(result.exception, null);
@@ -180,7 +187,7 @@ void main() {
180187
when(
181188
client.get(
182189
url: buildV2Uri('/exchange/currencies', {'flow': 'standard'}),
183-
headers: changeNowHeaders(),
190+
headers: changeNowHeaders(testApiKey),
184191
proxyInfo: null,
185192
),
186193
).thenAnswer(
@@ -190,7 +197,9 @@ void main() {
190197
),
191198
);
192199

193-
final result = await instance.getAvailableCurrencies();
200+
final result = await instance.getAvailableCurrencies(
201+
apiKey: testApiKey,
202+
);
194203

195204
expect(
196205
result.exception!.type,
@@ -207,12 +216,12 @@ void main() {
207216
when(
208217
client.get(
209218
url: buildV2Uri('/exchange/currencies', {'flow': 'standard'}),
210-
headers: changeNowHeaders(),
219+
headers: changeNowHeaders(testApiKey),
211220
proxyInfo: null,
212221
),
213222
).thenAnswer((_) async => Response(utf8.encode(''), 400));
214223

215-
final result = await instance.getAvailableCurrencies();
224+
final result = await instance.getAvailableCurrencies(apiKey: testApiKey);
216225

217226
expect(result.exception!.type, ExchangeExceptionType.generic);
218227
expect(result.value == null, true);

0 commit comments

Comments
 (0)