Skip to content
This repository was archived by the owner on Dec 12, 2024. It is now read-only.

Commit d421ca1

Browse files
author
Jiyoon Koo
authored
adding auth token in header for listbalances client method. fixed tests (#54)
1 parent d129033 commit d421ca1

File tree

2 files changed

+18
-6
lines changed

2 files changed

+18
-6
lines changed

lib/src/http_client/tbdex_http_client.dart

+4-1
Original file line numberDiff line numberDiff line change
@@ -153,14 +153,17 @@ class TbdexHttpClient {
153153
}
154154

155155
static Future<List<Balance>> listBalances(
156+
BearerDid did,
156157
String pfiDid,
157158
) async {
159+
final requestToken = await _generateRequestToken(did, pfiDid);
160+
final headers = {'Authorization': 'Bearer $requestToken'};
158161
final pfiServiceEndpoint = await _getPfiServiceEndpoint(pfiDid);
159162
final url = Uri.parse('$pfiServiceEndpoint/balances/');
160163

161164
http.Response response;
162165
try {
163-
response = await _client.get(url);
166+
response = await _client.get(url, headers: headers);
164167

165168
if (response.statusCode != 200) {
166169
throw ResponseError(

test/http_client/tbdex_http_client_test.dart

+14-5
Original file line numberDiff line numberDiff line change
@@ -139,28 +139,37 @@ void main() async {
139139

140140
test('can list balances', () async {
141141
when(
142-
() => mockHttpClient.get(Uri.parse('$pfiServiceEndpoint/balances/')),
142+
() => mockHttpClient.get(
143+
Uri.parse('$pfiServiceEndpoint/balances/'),
144+
headers: any(named: 'headers'),
145+
),
143146
).thenAnswer(
144147
(_) async => http.Response(TestData.listBalancesResponse(), 200),
145148
);
146149

147-
final response = await TbdexHttpClient.listBalances(pfiDid);
150+
final response = await TbdexHttpClient.listBalances(TestData.aliceDid, pfiDid);
148151
expect(response.length, 1);
149152

150153
verify(
151-
() => mockHttpClient.get(Uri.parse('$pfiServiceEndpoint/balances/')),
154+
() => mockHttpClient.get(
155+
Uri.parse('$pfiServiceEndpoint/balances/'),
156+
headers: any(named: 'headers'),
157+
),
152158
).called(1);
153159
});
154160

155161
test('list balances throws ResponseError', () async {
156162
when(
157-
() => mockHttpClient.get(Uri.parse('$pfiServiceEndpoint/balances/')),
163+
() => mockHttpClient.get(
164+
Uri.parse('$pfiServiceEndpoint/balances/'),
165+
headers: any(named: 'headers'),
166+
),
158167
).thenAnswer(
159168
(_) async => http.Response('Error', 400),
160169
);
161170

162171
expect(
163-
() async => TbdexHttpClient.listBalances(pfiDid),
172+
() async => TbdexHttpClient.listBalances(TestData.aliceDid, pfiDid),
164173
throwsA(isA<ResponseError>()),
165174
);
166175
});

0 commit comments

Comments
 (0)