-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7e6a693
commit dcc4783
Showing
4 changed files
with
153 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import 'package:flutter_showcase/core/errors/exceptions.dart'; | ||
import 'package:flutter_showcase/features/auth/data/models/signup_res_model.dart'; | ||
import 'package:flutter_test/flutter_test.dart'; | ||
|
||
void main() { | ||
group('SignUpResModel', () { | ||
test('should throw JsonParseException when data is missing', () { | ||
// Arrange | ||
final json = <String, dynamic>{}; | ||
|
||
// Act and Assert | ||
expect( | ||
() => SignUpResModel.fromJson(json), | ||
throwsA(isA<JsonParseException>()), | ||
); | ||
}); | ||
|
||
test('should return SignUpResModel when data is valid', () { | ||
// Arrange | ||
final json = <String, dynamic>{ | ||
'success': true, | ||
'message': 'sign up success', | ||
}; | ||
|
||
// Act | ||
final result = SignUpResModel.fromJson(json); | ||
|
||
// Assert | ||
expect(result, isA<SignUpResModel>()); | ||
expect(result.success, true); | ||
expect(result.message, 'sign up success'); | ||
}); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import 'package:flutter_showcase/core/errors/exceptions.dart'; | ||
import 'package:flutter_showcase/features/auth/data/models/token_model.dart'; | ||
import 'package:flutter_showcase/features/auth/domain/models/token.dart'; | ||
import 'package:flutter_test/flutter_test.dart'; | ||
|
||
void main() { | ||
test('test token model with valid json', () { | ||
// Arrange | ||
final json = <String, dynamic>{ | ||
'access_token': 'access_token', | ||
'refresh_token': 'refresh_token', | ||
}; | ||
|
||
// Act | ||
final tokenModel = TokenModel.fromJson(json); | ||
|
||
// Assert | ||
expect(tokenModel, isA<TokenModel>()); | ||
expect(tokenModel.accessToken, 'access_token'); | ||
expect(tokenModel.refreshToken, 'refresh_token'); | ||
}); | ||
|
||
test('test token model with invalid json', () { | ||
// Arrange | ||
final json = <String, dynamic>{}; | ||
|
||
// Assert | ||
expect( | ||
() => TokenModel.fromJson(json), | ||
throwsA(isA<JsonParseException>()), | ||
); | ||
}); | ||
|
||
test('test token model to json', () { | ||
// Arrange | ||
final tokenModel = TokenModel( | ||
accessToken: 'access_token', | ||
refreshToken: 'refresh_token', | ||
); | ||
|
||
// Act | ||
final json = tokenModel.toJson(); | ||
|
||
// Assert | ||
expect(json, isA<Map<String, dynamic>>()); | ||
expect(json[TokensType.access_token.name], 'access_token'); | ||
expect(json[TokensType.refresh_token.name], 'refresh_token'); | ||
}); | ||
} |
34 changes: 34 additions & 0 deletions
34
test/features/auth/data/models/token_validation_model_test.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import 'package:flutter_showcase/core/errors/exceptions.dart'; | ||
import 'package:flutter_showcase/features/auth/data/models/token_validation_model.dart'; | ||
import 'package:flutter_test/flutter_test.dart'; | ||
|
||
void main() { | ||
group('TokenValidationResponseModel', () { | ||
test('should throw JsonParseException when data is missing', () { | ||
// Arrange | ||
final json = <String, dynamic>{}; | ||
|
||
// Act and Assert | ||
expect( | ||
() => TokenValidationResponseModel.fromJson(json), | ||
throwsA(isA<JsonParseException>()), | ||
); | ||
}); | ||
|
||
test('should return TokenValidationResponseModel when data is valid', () { | ||
// Arrange | ||
final json = <String, dynamic>{ | ||
'success': true, | ||
'message': 'token is valid', | ||
}; | ||
|
||
// Act | ||
final result = TokenValidationResponseModel.fromJson(json); | ||
|
||
// Assert | ||
expect(result, isA<TokenValidationResponseModel>()); | ||
expect(result.isValid, true); | ||
expect(result.message, 'token is valid'); | ||
}); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import 'package:flutter_showcase/core/errors/exceptions.dart'; | ||
import 'package:flutter_showcase/features/auth/data/models/user_model.dart'; | ||
import 'package:flutter_test/flutter_test.dart'; | ||
|
||
void main() { | ||
group('UserModel', () { | ||
test('should throw JsonParseException when data is missing', () { | ||
// Arrange | ||
final json = <String, dynamic>{}; | ||
|
||
// Act and Assert | ||
expect( | ||
() => UserModel.fromJson(json), | ||
throwsA(isA<JsonParseException>()), | ||
); | ||
}); | ||
|
||
test('should return UserModel when data is valid', () { | ||
// Arrange | ||
final json = <String, dynamic>{ | ||
'id': 1, | ||
'email': 'email', | ||
'password': 'password', | ||
}; | ||
|
||
// Act | ||
final result = UserModel.fromJson(json); | ||
|
||
// Assert | ||
expect(result, isA<UserModel>()); | ||
expect(result.id, 1); | ||
expect(result.email, 'email'); | ||
expect(result.password, 'password'); | ||
}); | ||
}); | ||
} |