Skip to content

Commit e15bbd0

Browse files
committed
test: fix and improve jwt token service tests
- Removed duplicated test case - Improved readability
1 parent 5435c4c commit e15bbd0

File tree

1 file changed

+18
-9
lines changed

1 file changed

+18
-9
lines changed

test/src/services/jwt_auth_token_service_test.dart

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,8 @@ void main() {
168168
),
169169
),
170170
);
171-
verifyNever(() => mockUserRepository.read(id: any<String>(named: 'id')));
171+
verifyNever(
172+
() => mockUserRepository.read(id: any<String>(named: 'id')));
172173
});
173174

174175
// Removed the duplicated and incorrect test case above this line.
@@ -188,7 +189,8 @@ void main() {
188189
),
189190
),
190191
);
191-
verifyNever(() => mockUserRepository.read(id: any<String>(named: 'id')));
192+
verifyNever(
193+
() => mockUserRepository.read(id: any<String>(named: 'id')));
192194
});
193195

194196
test('throws BadRequestException for token missing "sub" claim',
@@ -218,13 +220,15 @@ void main() {
218220
),
219221
),
220222
);
221-
verifyNever(() => mockUserRepository.read(id: any<String>(named: 'id')));
223+
verifyNever(
224+
() => mockUserRepository.read(id: any<String>(named: 'id')));
222225
});
223226

224227
test('rethrows NotFoundException if user from token not found', () async {
225228
// Arrange
226229
const exception = NotFoundException('User not found');
227-
when(() => mockUserRepository.read(id: testUser.id)).thenThrow(exception);
230+
when(() => mockUserRepository.read(id: testUser.id))
231+
.thenThrow(exception);
228232

229233
// Act & Assert
230234
await expectLater(
@@ -237,7 +241,8 @@ void main() {
237241
test('rethrows other HtHttpException from user repository', () async {
238242
// Arrange
239243
const exception = ServerException('Database error');
240-
when(() => mockUserRepository.read(id: testUser.id)).thenThrow(exception);
244+
when(() => mockUserRepository.read(id: testUser.id))
245+
.thenThrow(exception);
241246

242247
// Act & Assert
243248
await expectLater(
@@ -251,7 +256,8 @@ void main() {
251256
() async {
252257
// Arrange
253258
final exception = Exception('Unexpected read error');
254-
when(() => mockUserRepository.read(id: testUser.id)).thenThrow(exception);
259+
when(() => mockUserRepository.read(id: testUser.id))
260+
.thenThrow(exception);
255261

256262
// Act & Assert
257263
await expectLater(
@@ -320,7 +326,8 @@ void main() {
320326
),
321327
),
322328
);
323-
verifyNever(() => mockBlacklistService.blacklist(any<String>(), any<DateTime>()));
329+
verifyNever(() =>
330+
mockBlacklistService.blacklist(any<String>(), any<DateTime>()));
324331
});
325332

326333
test('throws InvalidInputException for token missing "jti" claim',
@@ -351,7 +358,8 @@ void main() {
351358
),
352359
),
353360
);
354-
verifyNever(() => mockBlacklistService.blacklist(any<String>(), any<DateTime>()));
361+
verifyNever(() =>
362+
mockBlacklistService.blacklist(any<String>(), any<DateTime>()));
355363
});
356364

357365
test('throws InvalidInputException for token missing "exp" claim',
@@ -380,7 +388,8 @@ void main() {
380388
),
381389
),
382390
);
383-
verifyNever(() => mockBlacklistService.blacklist(any<String>(), any<DateTime>()));
391+
verifyNever(() =>
392+
mockBlacklistService.blacklist(any<String>(), any<DateTime>()));
384393
});
385394

386395
test('rethrows HtHttpException from blacklist service', () async {

0 commit comments

Comments
 (0)