@@ -7,23 +7,23 @@ import 'package:ht_shared/ht_shared.dart';
77import 'package:mocktail/mocktail.dart' ;
88import 'package:test/test.dart' ;
99
10- import '../../../../helpers/create_mock_request_context.dart' ;
11- import '../../../../helpers/mock_classes.dart' ;
1210// Import the actual route handler
1311import '../../../../../routes/api/v1/auth/anonymous.dart' as route;
12+ import '../../../../helpers/create_mock_request_context.dart' ;
13+ import '../../../../helpers/mock_classes.dart' ;
1414
1515void main () {
1616 group ('POST /api/v1/auth/anonymous' , () {
1717 late MockAuthService mockAuthService;
1818 late MockRequest mockRequest;
1919
2020 // Define a sample user and token for success cases
21- final testUser = User (id: 'anon-123' , isAnonymous: true );
21+ const testUser = User (id: 'anon-123' , isAnonymous: true );
2222 const testToken = 'test-auth-token' ;
23- final authResult = (user: testUser, token: testToken);
23+ const authResult = (user: testUser, token: testToken);
2424
2525 // Expected success response payload
26- final successPayload = SuccessApiResponse <AuthSuccessResponse >(
26+ const successPayload = SuccessApiResponse <AuthSuccessResponse >(
2727 data: AuthSuccessResponse (user: testUser, token: testToken),
2828 );
2929 final expectedSuccessBody = jsonEncode (
@@ -40,7 +40,8 @@ void main() {
4040 when (() => mockRequest.headers).thenReturn ({});
4141 // Default stub for body (can be overridden)
4242 when (() => mockRequest.body ()).thenAnswer ((_) async => '' );
43- when (() => mockRequest.json ()).thenAnswer ((_) async => < String , dynamic > {});
43+ when (() => mockRequest.json ())
44+ .thenAnswer ((_) async => < String , dynamic > {});
4445 });
4546
4647 test ('returns 200 OK with user and token on successful anonymous sign-in' ,
@@ -90,7 +91,8 @@ void main() {
9091 verifyNever (() => mockAuthService.performAnonymousSignIn ());
9192 });
9293
93- test ('returns 500 Internal Server Error when AuthService throws OperationFailedException' ,
94+ test (
95+ 'returns 500 Internal Server Error when AuthService throws OperationFailedException' ,
9496 () async {
9597 // Arrange
9698 const exception = OperationFailedException ('Database connection failed' );
@@ -114,7 +116,7 @@ void main() {
114116 // The final 500 response format is tested in the error handler middleware tests.
115117 });
116118
117- test ('returns 500 Internal Server Error for unexpected errors' , () async {
119+ test ('returns 500 Internal Server Error for unexpected errors' , () async {
118120 // Arrange
119121 final exception = Exception ('Something unexpected went wrong' );
120122 when (() => mockAuthService.performAnonymousSignIn ()).thenThrow (exception);
@@ -130,11 +132,13 @@ void main() {
130132 // The handler catches generic exceptions and throws OperationFailedException
131133 expect (
132134 () => route.onRequest (context),
133- throwsA (isA <OperationFailedException >().having (
134- (e) => e.message,
135- 'message' ,
136- 'An unexpected error occurred during anonymous sign-in.' ,
137- )),
135+ throwsA (
136+ isA <OperationFailedException >().having (
137+ (e) => e.message,
138+ 'message' ,
139+ 'An unexpected error occurred during anonymous sign-in.' ,
140+ ),
141+ ),
138142 );
139143 verify (() => mockAuthService.performAnonymousSignIn ()).called (1 );
140144 });
0 commit comments