Skip to content

Commit

Permalink
Do not show Sharezone Plus support for teacher and parents (#1762)
Browse files Browse the repository at this point in the history
We showed to teachers and parents that they have the Sharezone Plus
support. This can be confusing for them because they don't know what
Sharezone Plus is.
  • Loading branch information
nilsreichardt authored Oct 12, 2024
1 parent 7e14267 commit 2e6761b
Show file tree
Hide file tree
Showing 4 changed files with 97 additions and 2 deletions.
1 change: 1 addition & 0 deletions app/lib/main/auth_app.dart
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ class _AuthAppState extends State<AuthApp> {
userEmailStream: Stream.value(null),
hasPlusSupportUnlockedStream: Stream.value(false),
isUserInGroupOnboardingStream: Stream.value(false),
typeOfUserStream: Stream.value(null),
),
),
],
Expand Down
1 change: 1 addition & 0 deletions app/lib/main/sharezone_bloc_providers.dart
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,7 @@ class _SharezoneBlocProvidersState extends State<SharezoneBlocProviders> {
hasPlusSupportUnlockedStream: subscriptionService
.hasFeatureUnlockedStream(SharezonePlusFeature.plusSupport),
isUserInGroupOnboardingStream: signUpBloc.signedUp,
typeOfUserStream: typeOfUserStream,
),
),
StreamProvider<TypeOfUser?>.value(
Expand Down
16 changes: 14 additions & 2 deletions app/lib/support/support_page_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,17 @@ import 'dart:async';

import 'package:common_domain_models/common_domain_models.dart';
import 'package:flutter/material.dart';
import 'package:user/user.dart';

class SupportPageController extends ChangeNotifier {
bool hasPlusSupportUnlocked = false;
bool get hasPlusSupportUnlocked =>
_hasSharezonePlus && _typeOfUser == TypeOfUser.student;
bool _hasSharezonePlus = false;
bool isUserInGroupOnboarding = false;
UserId? userId;
String? userEmail;
String? userName;
TypeOfUser? _typeOfUser;

bool get isUserSignedIn => userId != null;

Expand All @@ -25,13 +29,15 @@ class SupportPageController extends ChangeNotifier {
late StreamSubscription<String?> _userEmailSubscription;
late StreamSubscription<bool> _hasPlusSupportUnlockedSubscription;
late StreamSubscription<bool> _isUserInGroupOnboardingSubscription;
late StreamSubscription<TypeOfUser?> _typeOfUserSubscription;

SupportPageController({
required Stream<UserId?> userIdStream,
required Stream<String?> userNameStream,
required Stream<String?> userEmailStream,
required Stream<bool> hasPlusSupportUnlockedStream,
required Stream<bool> isUserInGroupOnboardingStream,
required Stream<TypeOfUser?> typeOfUserStream,
}) {
_userIdSubscription = userIdStream.listen((userId) {
this.userId = userId;
Expand All @@ -50,7 +56,7 @@ class SupportPageController extends ChangeNotifier {

_hasPlusSupportUnlockedSubscription =
hasPlusSupportUnlockedStream.listen((hasPlusSupportUnlocked) {
this.hasPlusSupportUnlocked = hasPlusSupportUnlocked;
_hasSharezonePlus = hasPlusSupportUnlocked;
notifyListeners();
});

Expand All @@ -59,6 +65,11 @@ class SupportPageController extends ChangeNotifier {
this.isUserInGroupOnboarding = isUserInGroupOnboarding;
notifyListeners();
});

_typeOfUserSubscription = typeOfUserStream.listen((typeOfUser) {
_typeOfUser = typeOfUser;
notifyListeners();
});
}

/// Returns the unencoded URL for the video call appointments page, with
Expand Down Expand Up @@ -120,6 +131,7 @@ class SupportPageController extends ChangeNotifier {
_userIdSubscription.cancel();
_hasPlusSupportUnlockedSubscription.cancel();
_isUserInGroupOnboardingSubscription.cancel();
_typeOfUserSubscription.cancel();
super.dispose();
}
}
Expand Down
81 changes: 81 additions & 0 deletions app/test/settings/support/support_page_controller_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import 'package:common_domain_models/common_domain_models.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:sharezone/support/support_page_controller.dart';
import 'package:user/user.dart';

void main() {
group(SupportPageController, () {
Expand All @@ -21,6 +22,7 @@ void main() {
userEmailStream: Stream.value(null),
hasPlusSupportUnlockedStream: Stream.value(false),
isUserInGroupOnboardingStream: Stream.value(false),
typeOfUserStream: Stream.value(null),
);

// Workaround to wait for stream subscription in constructor.
Expand All @@ -39,6 +41,7 @@ void main() {
userEmailStream: Stream.value('[email protected]'),
hasPlusSupportUnlockedStream: Stream.value(false),
isUserInGroupOnboardingStream: Stream.value(false),
typeOfUserStream: Stream.value(null),
);

// Workaround to wait for stream subscription in constructor.
Expand All @@ -50,5 +53,83 @@ void main() {
);
});
});

group('hasPlusSupportUnlocked', () {
test('show free support for parents', () async {
final controller = SupportPageController(
userIdStream: Stream.value(const UserId('userId123')),
userNameStream: Stream.value('My Cool Name'),
userEmailStream: Stream.value('[email protected]'),
hasPlusSupportUnlockedStream: Stream.value(true),
isUserInGroupOnboardingStream: Stream.value(false),
typeOfUserStream: Stream.value(TypeOfUser.parent),
);

// Workaround to wait for stream subscription in constructor.
await Future.delayed(Duration.zero);

expect(
controller.hasPlusSupportUnlocked,
false,
);
});

test('show free support for teachers', () async {
final controller = SupportPageController(
userIdStream: Stream.value(const UserId('userId123')),
userNameStream: Stream.value('My Cool Name'),
userEmailStream: Stream.value('[email protected]'),
hasPlusSupportUnlockedStream: Stream.value(true),
isUserInGroupOnboardingStream: Stream.value(false),
typeOfUserStream: Stream.value(TypeOfUser.teacher),
);

// Workaround to wait for stream subscription in constructor.
await Future.delayed(Duration.zero);

expect(
controller.hasPlusSupportUnlocked,
false,
);
});

test('show free support for students without Sharezone Plus', () async {
final controller = SupportPageController(
userIdStream: Stream.value(const UserId('userId123')),
userNameStream: Stream.value('My Cool Name'),
userEmailStream: Stream.value('[email protected]'),
hasPlusSupportUnlockedStream: Stream.value(false),
isUserInGroupOnboardingStream: Stream.value(false),
typeOfUserStream: Stream.value(TypeOfUser.teacher),
);

// Workaround to wait for stream subscription in constructor.
await Future.delayed(Duration.zero);

expect(
controller.hasPlusSupportUnlocked,
false,
);
});

test('show plus support for students with Sharezone Plus', () async {
final controller = SupportPageController(
userIdStream: Stream.value(const UserId('userId123')),
userNameStream: Stream.value('My Cool Name'),
userEmailStream: Stream.value('[email protected]'),
hasPlusSupportUnlockedStream: Stream.value(true),
isUserInGroupOnboardingStream: Stream.value(false),
typeOfUserStream: Stream.value(TypeOfUser.student),
);

// Workaround to wait for stream subscription in constructor.
await Future.delayed(Duration.zero);

expect(
controller.hasPlusSupportUnlocked,
true,
);
});
});
});
}

0 comments on commit 2e6761b

Please sign in to comment.