@@ -13,15 +13,16 @@ import 'package:test/test.dart';
13
13
14
14
class MockOAuthChopper extends Mock implements OAuthChopper {}
15
15
16
- class MockChain extends Mock implements Chain {}
16
+ class MockChain extends Mock implements Chain < dynamic > {}
17
17
18
18
void main () {
19
19
final testRequest = Request (
20
20
'GET' ,
21
21
Uri (host: 'test' ),
22
22
Uri (host: 'test' ),
23
23
);
24
- final authorizedResponse = Response (http.Response ('body' , HttpStatus .accepted), 'body' );
24
+ final authorizedResponse =
25
+ Response (http.Response ('body' , HttpStatus .accepted), 'body' );
25
26
registerFallbackValue (testRequest);
26
27
registerFallbackValue (authorizedResponse);
27
28
@@ -46,7 +47,8 @@ void main() {
46
47
);
47
48
48
49
when (() => mockChain.request).thenReturn (testRequest);
49
- when (() => mockChain.proceed (any ())).thenAnswer ((_) async => authorizedResponse);
50
+ when (() => mockChain.proceed (any ()))
51
+ .thenAnswer ((_) async => authorizedResponse);
50
52
51
53
test ('HeaderInterceptor adds available token to headers' , () async {
52
54
// arrange
@@ -58,10 +60,12 @@ void main() {
58
60
await interceptor.intercept (mockChain);
59
61
60
62
// assert
61
- verify (() => mockChain.proceed (testRequest.copyWith (headers: expected))).called (1 );
63
+ verify (() => mockChain.proceed (testRequest.copyWith (headers: expected)))
64
+ .called (1 );
62
65
});
63
66
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 {
65
69
// arrange
66
70
when (() => mockOAuthChopper.token).thenAnswer ((_) async => testIDtoken);
67
71
final interceptor = OAuthInterceptor (mockOAuthChopper, null );
@@ -71,7 +75,8 @@ void main() {
71
75
await interceptor.intercept (mockChain);
72
76
73
77
// assert
74
- verify (() => mockChain.proceed (testRequest.copyWith (headers: expected))).called (1 );
78
+ verify (() => mockChain.proceed (testRequest.copyWith (headers: expected)))
79
+ .called (1 );
75
80
});
76
81
77
82
test ('HeaderInterceptor adds no token to headers' , () async {
@@ -84,7 +89,8 @@ void main() {
84
89
await interceptor.intercept (mockChain);
85
90
86
91
// assert
87
- verify (() => mockChain.proceed (testRequest.copyWith (headers: expected))).called (1 );
92
+ verify (() => mockChain.proceed (testRequest.copyWith (headers: expected)))
93
+ .called (1 );
88
94
});
89
95
});
90
96
@@ -98,10 +104,12 @@ void main() {
98
104
expiration: DateTime (2022 , 9 , 1 ),
99
105
),
100
106
);
101
- final unauthorizedResponse = Response (http.Response ('body' , HttpStatus .unauthorized), 'body' );
107
+ final unauthorizedResponse =
108
+ Response (http.Response ('body' , HttpStatus .unauthorized), 'body' );
102
109
setUp (() {
103
110
when (() => mockChain.request).thenReturn (testRequest);
104
- when (() => mockChain.proceed (any ())).thenAnswer ((_) async => unauthorizedResponse);
111
+ when (() => mockChain.proceed (any ()))
112
+ .thenAnswer ((_) async => unauthorizedResponse);
105
113
});
106
114
107
115
test ('only refresh on unauthorized and token' , () async {
@@ -116,12 +124,14 @@ void main() {
116
124
117
125
// assert
118
126
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 );
120
129
});
121
130
122
131
test ("Don't refresh on authorized" , () async {
123
132
// arrange
124
- when (() => mockChain.proceed (any ())).thenAnswer ((_) async => authorizedResponse);
133
+ when (() => mockChain.proceed (any ()))
134
+ .thenAnswer ((_) async => authorizedResponse);
125
135
when (mockOAuthChopper.refresh).thenAnswer ((_) async => testToken);
126
136
when (() => mockOAuthChopper.token).thenAnswer ((_) async => testToken);
127
137
final interceptor = OAuthInterceptor (mockOAuthChopper, null );
@@ -186,7 +196,7 @@ void main() {
186
196
);
187
197
188
198
// act
189
- await interceptor.intercept (mockChain);
199
+ await interceptor.intercept (mockChain);
190
200
191
201
// assert
192
202
expect (result? .message, 'failed' );
0 commit comments