Skip to content

Commit

Permalink
[#9] Add dummy for login response
Browse files Browse the repository at this point in the history
  • Loading branch information
nkhanh44 committed Aug 11, 2023
1 parent eedeef0 commit dcb2c53
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 13 deletions.
4 changes: 0 additions & 4 deletions lib/model/request/login_request.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ import 'package:json_annotation/json_annotation.dart';

part 'login_request.g.dart';

const String grantType = "password";

@JsonSerializable()
class LoginRequest {
final String grantType;
Expand All @@ -20,7 +18,5 @@ class LoginRequest {
required this.clientSecret,
});

factory LoginRequest.fromJson(Map<String, dynamic> json) =>
_$LoginRequestFromJson(json);
Map<String, dynamic> toJson() => _$LoginRequestToJson(this);

Check warning on line 21 in lib/model/request/login_request.dart

View check run for this annotation

Codecov / codecov/patch

lib/model/request/login_request.dart#L21

Added line #L21 was not covered by tests
}
11 changes: 11 additions & 0 deletions lib/model/response/login_response.dart
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,15 @@ class LoginResponse {
expiresIn: expiresIn,
refreshToken: refreshToken,
);

static LoginResponse dummy() {
return LoginResponse(
id: "",
accessToken: "",
tokenType: "",
expiresIn: 0,
refreshToken: "",
createdAt: 0,
);
}
}
4 changes: 3 additions & 1 deletion lib/repositories/authentication_repository.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import 'package:survey_flutter/model/login_model.dart';
import 'package:survey_flutter/model/request/login_request.dart';
import 'package:injectable/injectable.dart';

const String _grantType = "password";

abstract class AuthenticationRepository {
Future<LoginModel> login({
required String email,
Expand All @@ -29,7 +31,7 @@ class AuthenticationRepositoryImpl extends AuthenticationRepository {
password: password,
clientId: Env.clientId,
clientSecret: Env.clientSecret,
grantType: grantType,
grantType: _grantType,
));
return response.toLoginModel();
} catch (exception) {
Expand Down
9 changes: 1 addition & 8 deletions test/api/repositories/authentication_repository_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,7 @@ void main() {
});

test('When login successfully, it returns correct model', () async {
final loginResponse = LoginResponse(
id: "",
accessToken: "",
tokenType: "",
expiresIn: 0,
refreshToken: "",
createdAt: 0,
);
final loginResponse = LoginResponse.dummy();

when(mockAuthApiService.login(any))
.thenAnswer((_) async => loginResponse);
Expand Down

0 comments on commit dcb2c53

Please sign in to comment.