Skip to content

Commit 09a8324

Browse files
committed
🎨 Formatted code and fixed lints
1 parent f8ada4c commit 09a8324

File tree

4 files changed

+30
-16
lines changed

4 files changed

+30
-16
lines changed

lib/src/oauth_chopper.dart

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,9 @@ class OAuthChopper {
6161
/// Get stored [OAuthToken].
6262
Future<OAuthToken?> get token async {
6363
final credentialsJson = await _storage.fetchCredentials();
64-
return credentialsJson != null ? OAuthToken.fromJson(credentialsJson) : null;
64+
return credentialsJson != null
65+
? OAuthToken.fromJson(credentialsJson)
66+
: null;
6567
}
6668

6769
/// Provides an [OAuthInterceptor] instance.

lib/src/oauth_interceptor.dart

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@ class OAuthInterceptor implements Interceptor {
2929
final OAuthChopper oauthChopper;
3030

3131
@override
32-
FutureOr<Response<BodyType>> intercept<BodyType>(Chain<BodyType> chain) async {
32+
FutureOr<Response<BodyType>> intercept<BodyType>(
33+
Chain<BodyType> chain,
34+
) async {
3335
// Add oauth token to the request.
3436
final token = await oauthChopper.token;
3537

@@ -48,7 +50,8 @@ class OAuthInterceptor implements Interceptor {
4850
try {
4951
final credentials = await oauthChopper.refresh();
5052
if (credentials != null) {
51-
final request = chain.request.addAuthorizationHeader(credentials.accessToken);
53+
final request =
54+
chain.request.addAuthorizationHeader(credentials.accessToken);
5255
return chain.proceed(request);
5356
}
5457
} catch (e, s) {

test/oauth_chopper_test.dart

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ void main() {
3939
expect(oauthChopper, inteceptor.oauthChopper);
4040
});
4141

42-
4342
test('Returns token from storage', () async {
4443
// arrange
4544
when(storageMock.fetchCredentials).thenAnswer((_) => testJson);

test/oauth_interceptor_test.dart

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,16 @@ import 'package:test/test.dart';
1313

1414
class MockOAuthChopper extends Mock implements OAuthChopper {}
1515

16-
class MockChain extends Mock implements Chain {}
16+
class MockChain extends Mock implements Chain<dynamic> {}
1717

1818
void main() {
1919
final testRequest = Request(
2020
'GET',
2121
Uri(host: 'test'),
2222
Uri(host: 'test'),
2323
);
24-
final authorizedResponse = Response(http.Response('body', HttpStatus.accepted), 'body');
24+
final authorizedResponse =
25+
Response(http.Response('body', HttpStatus.accepted), 'body');
2526
registerFallbackValue(testRequest);
2627
registerFallbackValue(authorizedResponse);
2728

@@ -46,7 +47,8 @@ void main() {
4647
);
4748

4849
when(() => mockChain.request).thenReturn(testRequest);
49-
when(() => mockChain.proceed(any())).thenAnswer((_) async => authorizedResponse);
50+
when(() => mockChain.proceed(any()))
51+
.thenAnswer((_) async => authorizedResponse);
5052

5153
test('HeaderInterceptor adds available token to headers', () async {
5254
// arrange
@@ -58,10 +60,12 @@ void main() {
5860
await interceptor.intercept(mockChain);
5961

6062
// assert
61-
verify(() => mockChain.proceed(testRequest.copyWith(headers: expected))).called(1);
63+
verify(() => mockChain.proceed(testRequest.copyWith(headers: expected)))
64+
.called(1);
6265
});
6366

64-
test('HeaderInterceptor does not add IDToken when available to headers', () async {
67+
test('HeaderInterceptor does not add IDToken when available to headers',
68+
() async {
6569
// arrange
6670
when(() => mockOAuthChopper.token).thenAnswer((_) async => testIDtoken);
6771
final interceptor = OAuthInterceptor(mockOAuthChopper, null);
@@ -71,7 +75,8 @@ void main() {
7175
await interceptor.intercept(mockChain);
7276

7377
// assert
74-
verify(() => mockChain.proceed(testRequest.copyWith(headers: expected))).called(1);
78+
verify(() => mockChain.proceed(testRequest.copyWith(headers: expected)))
79+
.called(1);
7580
});
7681

7782
test('HeaderInterceptor adds no token to headers', () async {
@@ -84,7 +89,8 @@ void main() {
8489
await interceptor.intercept(mockChain);
8590

8691
// assert
87-
verify(() => mockChain.proceed(testRequest.copyWith(headers: expected))).called(1);
92+
verify(() => mockChain.proceed(testRequest.copyWith(headers: expected)))
93+
.called(1);
8894
});
8995
});
9096

@@ -98,10 +104,12 @@ void main() {
98104
expiration: DateTime(2022, 9, 1),
99105
),
100106
);
101-
final unauthorizedResponse = Response(http.Response('body', HttpStatus.unauthorized), 'body');
107+
final unauthorizedResponse =
108+
Response(http.Response('body', HttpStatus.unauthorized), 'body');
102109
setUp(() {
103110
when(() => mockChain.request).thenReturn(testRequest);
104-
when(() => mockChain.proceed(any())).thenAnswer((_) async => unauthorizedResponse);
111+
when(() => mockChain.proceed(any()))
112+
.thenAnswer((_) async => unauthorizedResponse);
105113
});
106114

107115
test('only refresh on unauthorized and token', () async {
@@ -116,12 +124,14 @@ void main() {
116124

117125
// assert
118126
verify(mockOAuthChopper.refresh).called(1);
119-
verify(() => mockChain.proceed(testRequest.copyWith(headers: expected))).called(2);
127+
verify(() => mockChain.proceed(testRequest.copyWith(headers: expected)))
128+
.called(2);
120129
});
121130

122131
test("Don't refresh on authorized", () async {
123132
// arrange
124-
when(() => mockChain.proceed(any())).thenAnswer((_) async => authorizedResponse);
133+
when(() => mockChain.proceed(any()))
134+
.thenAnswer((_) async => authorizedResponse);
125135
when(mockOAuthChopper.refresh).thenAnswer((_) async => testToken);
126136
when(() => mockOAuthChopper.token).thenAnswer((_) async => testToken);
127137
final interceptor = OAuthInterceptor(mockOAuthChopper, null);
@@ -186,7 +196,7 @@ void main() {
186196
);
187197

188198
// act
189-
await interceptor.intercept(mockChain);
199+
await interceptor.intercept(mockChain);
190200

191201
// assert
192202
expect(result?.message, 'failed');

0 commit comments

Comments
 (0)