Skip to content

Commit 0c7b645

Browse files
committed
style: add ignore_for_file lint directives
- Added to avoid linting issues - No functional code changes
1 parent 752e45b commit 0c7b645

File tree

7 files changed

+57
-34
lines changed

7 files changed

+57
-34
lines changed

lib/src/middleware/error_handler.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
//
2+
// ignore_for_file: avoid_catches_without_on_clauses
3+
14
import 'dart:io';
25

36
import 'package:dart_frog/dart_frog.dart';

routes/api/v1/countries/[isoCode].dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
//
2+
// ignore_for_file: avoid_catches_without_on_clauses
3+
14
import 'dart:async';
25
import 'dart:io';
36

routes/api/v1/countries/index.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
//
2+
// ignore_for_file: avoid_catches_without_on_clauses
3+
14
import 'dart:async';
25
import 'dart:io';
36

routes/api/v1/index.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ import 'package:dart_frog/dart_frog.dart';
66
///
77
/// Returns a simple welcome message indicating the API is running.
88
Response onRequest(RequestContext context) {
9-
// You could potentially add more information here
9+
// You could potentially add more information here
1010
// like links to documentation.
1111
return Response.json(
1212
statusCode: HttpStatus.ok, // 200
13-
body: {'message': 'Welcome to the Headlines Toolkit API V1!'},
13+
body: {'message': 'Welcome to the Headlines Toolkit API V1!'},
1414
);
1515
}

test/routes/api/v1/countries/[isoCode]_test.dart

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import 'dart:convert';
21
import 'dart:io';
32

43
import 'package:dart_frog/dart_frog.dart';
@@ -65,7 +64,7 @@ void main() {
6564
});
6665

6766
test('lets CountryNotFound bubble up (handled globally)', () async {
68-
final exception = CountryNotFound('Country $isoCode not found');
67+
const exception = CountryNotFound('Country $isoCode not found');
6968
when(() => mockClient.fetchCountry(isoCode)).thenThrow(exception);
7069

7170
expect(
@@ -76,7 +75,7 @@ void main() {
7675
});
7776

7877
test('lets CountryFetchFailure bubble up (handled globally)', () async {
79-
final exception = CountryFetchFailure('Network error');
78+
const exception = CountryFetchFailure('Network error');
8079
when(() => mockClient.fetchCountry(isoCode)).thenThrow(exception);
8180

8281
expect(
@@ -123,13 +122,15 @@ void main() {
123122
});
124123

125124
test('returns 400 Bad Request for invalid JSON body', () async {
126-
when(() => request.json()).thenThrow(FormatException('Bad JSON'));
125+
when(() => request.json()).thenThrow(const FormatException('Bad JSON'));
127126

128127
final response = await route.onRequest(context, isoCode);
129128

130129
expect(response.statusCode, equals(HttpStatus.badRequest));
131-
expect(await response.body(),
132-
equals('Invalid JSON format in request body.'));
130+
expect(
131+
await response.body(),
132+
equals('Invalid JSON format in request body.'),
133+
);
133134
verifyNever(() => mockClient.updateCountry(any()));
134135
});
135136

@@ -161,14 +162,14 @@ void main() {
161162
await response.json(),
162163
equals({
163164
'error': 'ISO code in request body ("XX") does not match ISO code '
164-
'in URL path ("US").'
165+
'in URL path ("US").',
165166
}),
166167
);
167168
verifyNever(() => mockClient.updateCountry(any()));
168169
});
169170

170171
test('lets CountryNotFound bubble up (handled globally)', () async {
171-
final exception = CountryNotFound('Cannot update non-existent country');
172+
const exception = CountryNotFound('Cannot update non-existent country');
172173
// Ensure the specific exception is thrown by the mock
173174
when(() => mockClient.updateCountry(any())).thenThrow(exception);
174175

@@ -180,7 +181,7 @@ void main() {
180181
});
181182

182183
test('lets CountryUpdateFailure bubble up (handled globally)', () async {
183-
final exception = CountryUpdateFailure('DB conflict during update');
184+
const exception = CountryUpdateFailure('DB conflict during update');
184185
// Ensure the specific exception is thrown by the mock
185186
when(() => mockClient.updateCountry(any())).thenThrow(exception);
186187

@@ -207,7 +208,7 @@ void main() {
207208
});
208209

209210
test('lets CountryNotFound bubble up (handled globally)', () async {
210-
final exception = CountryNotFound('Cannot delete non-existent country');
211+
const exception = CountryNotFound('Cannot delete non-existent country');
211212
when(() => mockClient.deleteCountry(isoCode)).thenThrow(exception);
212213

213214
expect(
@@ -218,7 +219,7 @@ void main() {
218219
});
219220

220221
test('lets CountryDeleteFailure bubble up (handled globally)', () async {
221-
final exception = CountryDeleteFailure('Permission error');
222+
const exception = CountryDeleteFailure('Permission error');
222223
when(() => mockClient.deleteCountry(isoCode)).thenThrow(exception);
223224

224225
expect(

test/routes/api/v1/countries/index.dart

Lines changed: 30 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import 'dart:convert';
21
import 'dart:io';
32

43
import 'package:dart_frog/dart_frog.dart';
@@ -12,7 +11,8 @@ import '../../../../../routes/api/v1/countries/index.dart' as route;
1211
// --- Mocks ---
1312
class _MockRequestContext extends Mock implements RequestContext {}
1413

15-
class _MockHttpRequest extends Mock implements Request {} // Use dart_frog Request
14+
class _MockHttpRequest extends Mock
15+
implements Request {} // Use dart_frog Request
1616

1717
class _MockHtCountriesClient extends Mock implements HtCountriesClient {}
1818
// --- End Mocks ---
@@ -98,7 +98,7 @@ void main() {
9898
).called(1);
9999
});
100100

101-
test('uses max limit when limit parameter exceeds max', () async {
101+
test('uses max limit when limit parameter exceeds max', () async {
102102
final countries = createSampleCountries(5);
103103
// Limit is 150, should be clamped to 100 (defined in route)
104104
uri = Uri.parse('http://localhost/api/v1/countries?limit=150');
@@ -148,20 +148,25 @@ void main() {
148148
equals('Invalid query parameter: "limit" must be an integer.'),
149149
);
150150
verifyNever(
151-
() => mockClient.fetchCountries(limit: any(named: 'limit'), startAfterId: any(named: 'startAfterId')),
151+
() => mockClient.fetchCountries(
152+
limit: any(named: 'limit'),
153+
startAfterId: any(named: 'startAfterId'),
154+
),
152155
);
153156
});
154157

155-
// Add test for client throwing CountryFetchFailure (handled by global handler)
158+
// Add test for client throwing CountryFetchFailure
159+
//(handled by global handler)
156160
test('lets CountryFetchFailure bubble up (handled globally)', () async {
157161
uri = Uri.parse('http://localhost/api/v1/countries?limit=10');
158162
when(() => request.uri).thenReturn(uri);
159-
final exception = CountryFetchFailure('DB error');
163+
const exception = CountryFetchFailure('DB error');
160164
when(
161165
() => mockClient.fetchCountries(limit: 10, startAfterId: null),
162166
).thenThrow(exception);
163167

164-
// Expect the specific exception to be thrown, letting the global handler catch it
168+
// Expect the specific exception to be thrown, letting the global handler
169+
// catch it
165170
expect(
166171
() => route.onRequest(context),
167172
throwsA(isA<CountryFetchFailure>()),
@@ -183,7 +188,6 @@ void main() {
183188
// Remove 'id' as it's generated by client/constructor usually
184189
final requestJson = Map<String, dynamic>.from(newCountryJson)..remove('id');
185190

186-
187191
setUp(() {
188192
// Set request method for all POST tests in this group
189193
when(() => request.method).thenReturn(HttpMethod.post);
@@ -215,7 +219,7 @@ void main() {
215219
test('returns 400 Bad Request for invalid JSON body', () async {
216220
// Override request.json stub to throw format exception
217221
when(() => request.json()).thenThrow(
218-
FormatException('Unexpected character'),
222+
const FormatException('Unexpected character'),
219223
);
220224

221225
final response = await route.onRequest(context);
@@ -228,10 +232,11 @@ void main() {
228232
verifyNever(() => mockClient.createCountry(any()));
229233
});
230234

231-
test('returns 400 Bad Request for invalid country data structure', () async {
232-
// Provide JSON missing a required field
233-
final invalidJson = {'iso_code': 'DE', 'flag_url': '...'}; // Missing name
234-
when(() => request.json()).thenAnswer((_) async => invalidJson);
235+
test('returns 400 Bad Request for invalid country data structure',
236+
() async {
237+
// Provide JSON missing a required field
238+
final invalidJson = {'iso_code': 'DE', 'flag_url': '...'}; // Missing name
239+
when(() => request.json()).thenAnswer((_) async => invalidJson);
235240

236241
final response = await route.onRequest(context);
237242

@@ -243,9 +248,10 @@ void main() {
243248
verifyNever(() => mockClient.createCountry(any()));
244249
});
245250

246-
// Add test for client throwing CountryCreateFailure (handled by global handler)
247-
test('lets CountryCreateFailure bubble up (handled globally)', () async {
248-
final exception = CountryCreateFailure('Duplicate entry');
251+
// Add test for client throwing CountryCreateFailure
252+
// (handled by global handler)
253+
test('lets CountryCreateFailure bubble up (handled globally)', () async {
254+
const exception = CountryCreateFailure('Duplicate entry');
249255
when(() => mockClient.createCountry(any())).thenThrow(exception);
250256

251257
// Expect the specific exception to be thrown
@@ -258,7 +264,7 @@ void main() {
258264
});
259265
});
260266

261-
test('returns 405 Method Not Allowed for unsupported methods', () async {
267+
test('returns 405 Method Not Allowed for unsupported methods', () async {
262268
// Test with PUT, DELETE etc.
263269
when(() => request.method).thenReturn(HttpMethod.put);
264270
final responsePut = await route.onRequest(context);
@@ -268,7 +274,12 @@ void main() {
268274
final responseDelete = await route.onRequest(context);
269275
expect(responseDelete.statusCode, equals(HttpStatus.methodNotAllowed));
270276

271-
verifyNever(() => mockClient.fetchCountries(limit: any(named: 'limit'), startAfterId: any(named: 'startAfterId')));
272-
verifyNever(() => mockClient.createCountry(any()));
277+
verifyNever(
278+
() => mockClient.fetchCountries(
279+
limit: any(named: 'limit'),
280+
startAfterId: any(named: 'startAfterId'),
281+
),
282+
);
283+
verifyNever(() => mockClient.createCountry(any()));
273284
});
274285
}

test/src/middleware/error_handler_test.dart

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import 'package:test/test.dart';
1010
class _MockRequestContext extends Mock implements RequestContext {}
1111

1212
// Define a class that can be called like a Handler function
13+
// ignore: one_member_abstracts
1314
abstract class _CallableHandler {
1415
Future<Response> call(RequestContext context);
1516
}
@@ -42,7 +43,8 @@ void main() {
4243
() async {
4344
final expectedResponse = Response(body: 'Success');
4445
// Configure the mock handler's 'call' method
45-
when(() => mockHandler.call(any())).thenAnswer((_) async => expectedResponse);
46+
when(() => mockHandler.call(any()))
47+
.thenAnswer((_) async => expectedResponse);
4648

4749
// Execute the middleware chain, passing the mock handler's call method
4850
final response = await executeMiddleware(context, mockHandler.call);
@@ -155,4 +157,4 @@ void main() {
155157
verify(() => mockHandler.call(context)).called(1);
156158
});
157159
});
158-
}
160+
}

0 commit comments

Comments
 (0)