Skip to content

Commit

Permalink
fix review comments.
Browse files Browse the repository at this point in the history
  • Loading branch information
naif-deriv committed Jun 20, 2024
1 parent 8a4ea31 commit 2780988
Show file tree
Hide file tree
Showing 10 changed files with 118 additions and 31 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import 'package:deriv_auth/deriv_auth.dart';
import 'package:deriv_auth/core/analytics/data/auth_tracking_repository.dart';

///
/// Mixin for tracking user authentication actions.
mixin AuthTrackingMixin {
final AuthTrackingRepository _repository = AuthTrackingRepository.instance;
late final AuthTrackingRepository _repository =
AuthTrackingRepository.instance;

/// Track user opened login form.
void trackUserOpenedLoginForm() => _repository.trackUserOpenedLoginForm();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import 'package:deriv_auth/core/services/token/models/enums.dart';
import 'package:deriv_auth/core/services/token/models/login_request.dart';
import 'package:deriv_auth/features/auth/deriv_auth_io.dart';
import 'package:deriv_auth/features/auth/services/base_auth_service.dart';
import 'package:deriv_auth/features/auth/services/deriv_auth_service.dart';
import 'package:deriv_auth/features/social_auth/models/social_auth_dto.dart';

part 'deriv_auth_state.dart';
Expand All @@ -26,7 +27,9 @@ class DerivAuthCubit extends Cubit<DerivAuthState>
required this.authService,
}) : super(DerivAuthLoadingState()) {
AuthTrackingRepository.init(
authService.connectionInfo.appId,
authService is DerivAuthService
? (authService as DerivAuthService).connectionInfo.appId
: (throw Exception('Connection Info is not provided.')),
derivRudderstack: DerivRudderstack(),
);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,33 +1,12 @@
import 'package:deriv_auth/core/connection_info.dart';
import 'package:deriv_auth/core/models/account_model.dart';
import 'package:deriv_auth/core/models/authorize_model.dart';
import 'package:deriv_auth/core/models/landig_comany_model.dart';
import 'package:deriv_auth/core/services/jwt/services/base_jwt_service.dart';
import 'package:deriv_auth/core/services/token/models/login_request.dart';
import 'package:deriv_auth/core/services/token/services/base_token_service.dart';
import 'package:deriv_auth/features/auth/repository/base_auth_repository.dart';

/// Interface to define all authentication-related functionality.
abstract class BaseAuthService {
/// Constructor for [BaseAuthService].
BaseAuthService({
required this.authRepository,
required this.jwtService,
required this.connectionInfo,
required this.tokenService,
});

/// Client connection info.
final AuthConnectionInfo connectionInfo;

/// Interface for all jwtRelated functions.
final BaseJwtService jwtService;

/// Interface of all client related functions.
final BaseAuthRepository authRepository;

/// Token service.
final BaseTokenService tokenService;
BaseAuthService();

/// Function before logging user in.
Future<AuthorizeEntity> onLoginRequest({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'package:collection/collection.dart';
import 'package:deriv_auth/core/connection_info.dart';

import 'package:deriv_auth/core/constants/constants.dart';
import 'package:deriv_auth/core/exceptions/deriv_auth_exception.dart';
Expand All @@ -7,8 +8,11 @@ import 'package:deriv_auth/core/models/account_model.dart';
import 'package:deriv_auth/core/models/auth_error/auth_error.dart';
import 'package:deriv_auth/core/models/authorize_model.dart';
import 'package:deriv_auth/core/models/landig_comany_model.dart';
import 'package:deriv_auth/core/services/jwt/services/base_jwt_service.dart';
import 'package:deriv_auth/core/services/token/models/login_request.dart';
import 'package:deriv_auth/core/services/token/models/login_response.dart';
import 'package:deriv_auth/core/services/token/services/base_token_service.dart';
import 'package:deriv_auth/features/auth/repository/base_auth_repository.dart';
import 'package:deriv_http_client/deriv_http_client.dart';

import 'base_auth_service.dart';
Expand All @@ -17,12 +21,24 @@ import 'base_auth_service.dart';
class DerivAuthService extends BaseAuthService {
/// Initializes a [DerivAuthService] class.
DerivAuthService({
required super.authRepository,
required super.jwtService,
required super.connectionInfo,
required super.tokenService,
required this.authRepository,
required this.jwtService,
required this.connectionInfo,
required this.tokenService,
});

/// Client connection info.
final AuthConnectionInfo connectionInfo;

/// Interface for all jwtRelated functions.
final BaseJwtService jwtService;

/// Interface of all client related functions.
final BaseAuthRepository authRepository;

/// Token service.
final BaseTokenService tokenService;

@override
Future<AuthorizeEntity> onLoginRequest({
required GetTokensRequestModel request,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'dart:async';

import 'package:deriv_auth/core/analytics/service/auth_tracking_mixin.dart';
import 'package:deriv_auth/deriv_auth.dart';
import 'package:deriv_passkeys/deriv_passkeys.dart';
import 'package:deriv_theme/deriv_theme.dart';
Expand Down Expand Up @@ -100,7 +101,8 @@ class DerivLoginLayout extends StatefulWidget {
State<DerivLoginLayout> createState() => _DerivLoginLayoutState();
}

class _DerivLoginLayoutState extends State<DerivLoginLayout> {
class _DerivLoginLayoutState extends State<DerivLoginLayout>
with AuthTrackingMixin {
final GlobalKey<FormState> _formKey = GlobalKey<FormState>();

final TextEditingController _emailController = TextEditingController();
Expand Down Expand Up @@ -162,7 +164,9 @@ class _DerivLoginLayoutState extends State<DerivLoginLayout> {
if (widget.isSocialAuthEnabled)
const SizedBox(height: ThemeProvider.margin24),
widget.isPasskeysEnabled
? const ContinueWithPasskeyButton()
? ContinueWithPasskeyButton(
onTap: trackLoginWithPasskey,
)
: const SizedBox.shrink(),
DerivSocialAuthPanel(
socialAuthStateHandler: widget.socialAuthStateHandler,
Expand Down
6 changes: 6 additions & 0 deletions packages/deriv_auth/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ dependencies:
flutter:
sdk: flutter

analytics:
git:
url: [email protected]:regentmarkets/flutter-deriv-packages.git
path: packages/analytics
ref: analytics-v2.0.0

deriv_theme:
git:
url: [email protected]:regentmarkets/flutter-deriv-packages.git
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import 'package:analytics/sdk/rudderstack/sdk/deriv_rudderstack_sdk.dart';
import 'package:bloc_test/bloc_test.dart';
import 'package:deriv_auth/core/analytics/data/auth_tracking_repository.dart';
import 'package:deriv_auth/core/exceptions/deriv_auth_exception.dart';
import 'package:deriv_auth/core/models/account_model.dart';
import 'package:deriv_auth/core/models/auth_error/auth_error.dart';
Expand All @@ -16,11 +18,28 @@ import '../mocked_data/mocked_auth_models.dart';

class MockAuthService extends Mock implements BaseAuthService {}

class MockDerivRudderStack extends Mock implements DerivRudderstack {}

void main() {
late final MockDerivRudderStack mockDerivRudderstack;

late final DerivAuthCubit authCubit;
late final MockAuthService service;

setUpAll(() async {
mockDerivRudderstack = MockDerivRudderStack();

AuthTrackingRepository.init(
'test',
derivRudderstack: mockDerivRudderstack,
);

when(() => mockDerivRudderstack.track(
eventName: any(named: 'eventName'),
properties: any(named: 'properties'))).thenAnswer(
(_) => Future<bool>.value(true),
);

service = MockAuthService();
authCubit = DerivAuthCubit(authService: service);
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// ignore_for_file: always_specify_types

import 'package:analytics/sdk/rudderstack/sdk/deriv_rudderstack_sdk.dart';
import 'package:bloc_test/bloc_test.dart';
import 'package:deriv_auth/core/analytics/data/auth_tracking_repository.dart';
import 'package:deriv_auth/features/get_started/models/deriv_get_started_slide_model.dart';
import 'package:deriv_auth/features/get_started/presentation/layouts/deriv_get_started_layout.dart';
import 'package:deriv_language_selector/deriv_language_selector.dart';
Expand All @@ -14,6 +16,8 @@ import 'package:patrol_finders/patrol_finders.dart';

import '../../../../pump_app.dart';

class MockDerivRudderStack extends Mock implements DerivRudderstack {}

class MockDerivGetStartedSlideModel extends Mock
implements DerivGetStartedSlideModel {}

Expand All @@ -22,6 +26,8 @@ class MockLanguageCubit extends MockCubit<LanguageState>

void main() {
group('DerivGetStartedLayout', () {
late final MockDerivRudderStack mockDerivRudderstack;

late MockDerivGetStartedSlideModel mockSlideModel;

const String appLogoIconPath = 'assets/icons/ic_logo_extended.svg';
Expand All @@ -31,6 +37,23 @@ void main() {

setUpAll(() {
mockSlideModel = MockDerivGetStartedSlideModel();

mockDerivRudderstack = MockDerivRudderStack();

AuthTrackingRepository.init(
'test',
derivRudderstack: mockDerivRudderstack,
);

when(() => mockDerivRudderstack.track(
eventName: any(named: 'eventName'),
properties: any(named: 'properties'))).thenAnswer(
(_) => Future<bool>.value(true),
);

when(() => mockSlideModel.imagePath)
.thenReturn('assets/images/charts.svg');
when(() => mockSlideModel.supportingText).thenReturn('Supporting text');
when(() => mockSlideModel.imagePath)
.thenReturn('assets/images/charts.svg');
when(() => mockSlideModel.supportingText).thenReturn('Supporting text');
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import 'package:analytics/sdk/rudderstack/sdk/deriv_rudderstack_sdk.dart';
import 'package:bloc_test/bloc_test.dart';
import 'package:deriv_auth/core/analytics/data/auth_tracking_repository.dart';
import 'package:deriv_auth/core/models/landig_comany_model.dart';
import 'package:deriv_auth/deriv_auth.dart';
import 'package:deriv_passkeys/deriv_passkeys.dart';
Expand All @@ -18,19 +20,35 @@ class MockDerivPasskeysBloc
extends MockBloc<DerivPasskeysEvent, DerivPasskeysState>
implements DerivPasskeysBloc {}

class MockDerivRudderStackService extends Mock implements DerivRudderstack {}

void main() {
group('DerivLoginLayout', () {
late MockDerivRudderStackService mockDerivRudderstack;
late MockAuthCubit authCubit;
late MockSocialAuthCubit socialAuthCubit;
late MockDerivPasskeysBloc derivPasskeysBloc;

const String welcomeLabel = 'Welcome Back';

setUpAll(() {
mockDerivRudderstack = MockDerivRudderStackService();
authCubit = MockAuthCubit();
socialAuthCubit = MockSocialAuthCubit();
derivPasskeysBloc = MockDerivPasskeysBloc();

AuthTrackingRepository.init(
'test',
derivRudderstack: mockDerivRudderstack,
);

when(() => mockDerivRudderstack.track(
eventName: any(named: 'eventName'),
properties: any(named: 'properties'),
)).thenAnswer(
(_) => Future<bool>.value(true),
);

when(() => derivPasskeysBloc.state).thenReturn(
DerivPasskeysInitializedState(),
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import 'package:analytics/sdk/rudderstack/sdk/deriv_rudderstack_sdk.dart';
import 'package:deriv_auth/core/analytics/data/auth_tracking_repository.dart';
import 'package:deriv_auth/deriv_auth.dart';
import 'package:deriv_ui/deriv_ui.dart';
import 'package:flutter/material.dart';
Expand All @@ -11,8 +13,11 @@ import '../../../../mocks.dart';
import '../../../../pump_app.dart';
import '../../../social_auth/mocks/mock_social_provider_model.dart';

class MockDerivRudderStack extends Mock implements DerivRudderstack {}

void main() {
group('DerivSignupLayout', () {
late final MockDerivRudderStack mockDerivRudderstack;
late MockSignupCubit signupCubit;
late MockAuthCubit authCubit;
late MockSocialAuthCubit socialAuthCubit;
Expand All @@ -25,6 +30,19 @@ void main() {
authCubit = MockAuthCubit();
socialAuthCubit = MockSocialAuthCubit();

mockDerivRudderstack = MockDerivRudderStack();

AuthTrackingRepository.init(
'test',
derivRudderstack: mockDerivRudderstack,
);

when(() => mockDerivRudderstack.track(
eventName: any(named: 'eventName'),
properties: any(named: 'properties'))).thenAnswer(
(_) => Future<bool>.value(true),
);

registerFallbackValue(SocialAuthProvider.google);

when(() => signupCubit.state)
Expand Down

0 comments on commit 2780988

Please sign in to comment.