Skip to content

Commit

Permalink
isPurchaseAllowed should be an answer
Browse files Browse the repository at this point in the history
... instead of a question.
  • Loading branch information
CarlosNihelton committed Oct 17, 2023
1 parent 0a70e5a commit 407ae02
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ class SubscribeNowPage extends StatelessWidget {
mainAxisAlignment: MainAxisAlignment.start,
children: [
Tooltip(
message: model.isPurchaseAllowed()
message: model.purchaseAllowed()
? ''
: lang.subscribeNowTooltipDisabled,
child: ElevatedButton(
onPressed: model.isPurchaseAllowed()
onPressed: model.purchaseAllowed()
? () async {
final subs = await model.purchaseSubscription();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ class SubscribeNowModel extends SubscriptionStatusModel {
/// Returns true if the environment variable 'UP4W_ALLOW_STORE_PURCHASE' has been set.
/// Since this reading won't change during the app lifetime, even if the user changes
/// it's value from outside, the value is cached so we don't check the environment more than once.
bool isPurchaseAllowed() {
bool purchaseAllowed() {
return _isPurchaseAllowed ??= ['true', '1', 'on']
.contains(Environment()['UP4W_ALLOW_STORE_PURCHASE']?.toLowerCase());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import 'token_samples.dart' as tks;
void main() {
testWidgets('launch web page', (tester) async {
final model = MockSubscribeNowModel();
when(model.isPurchaseAllowed()).thenReturn(true);
when(model.purchaseAllowed()).thenReturn(true);
var called = false;
when(model.launchProWebPage()).thenAnswer((_) async {
called = true;
Expand All @@ -36,7 +36,7 @@ void main() {
group('purchase button enabled by model', () {
testWidgets('disabled', (tester) async {
final model = MockSubscribeNowModel();
when(model.isPurchaseAllowed()).thenReturn(false);
when(model.purchaseAllowed()).thenReturn(false);
final app = buildApp(model, (_) {});
await tester.pumpWidget(app);
final context = tester.element(find.byType(SubscribeNowPage));
Expand All @@ -52,7 +52,7 @@ void main() {
});
testWidgets('enabled', (tester) async {
final model = MockSubscribeNowModel();
when(model.isPurchaseAllowed()).thenReturn(true);
when(model.purchaseAllowed()).thenReturn(true);
final app = buildApp(model, (_) {});
await tester.pumpWidget(app);
final context = tester.element(find.byType(SubscribeNowPage));
Expand All @@ -70,7 +70,7 @@ void main() {
group('subscribe', () {
testWidgets('calls back on success', (tester) async {
final model = MockSubscribeNowModel();
when(model.isPurchaseAllowed()).thenReturn(true);
when(model.purchaseAllowed()).thenReturn(true);
var called = false;
when(model.purchaseSubscription()).thenAnswer((_) async {
final info = SubscriptionInfo()..ensureMicrosoftStore();
Expand All @@ -93,7 +93,7 @@ void main() {
testWidgets('feedback on error', (tester) async {
const purchaseError = PurchaseStatus.networkError;
final model = MockSubscribeNowModel();
when(model.isPurchaseAllowed()).thenReturn(true);
when(model.purchaseAllowed()).thenReturn(true);
var called = false;
when(model.purchaseSubscription()).thenAnswer((_) async {
return purchaseError.left();
Expand All @@ -116,7 +116,7 @@ void main() {
});
testWidgets('feedback when applying token', (tester) async {
final model = MockSubscribeNowModel();
when(model.isPurchaseAllowed()).thenReturn(true);
when(model.purchaseAllowed()).thenReturn(true);
when(model.applyProToken(any)).thenAnswer((_) async {
return SubscriptionInfo()..ensureUser();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,9 @@ class MockSubscribeNowModel extends _i1.Mock implements _i5.SubscribeNowModel {
) as _i6
.Future<_i4.Either<_i8.PurchaseStatus, _i3.SubscriptionInfo>>);
@override
bool isPurchaseAllowed() => (super.noSuchMethod(
bool purchaseAllowed() => (super.noSuchMethod(
Invocation.method(
#isPurchaseAllowed,
#purchaseAllowed,
[],
),
returnValue: false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ void main() {

test('disabled by default', () {
final model = SubscribeNowModel(client);
expect(model.isPurchaseAllowed(), isFalse);
expect(model.purchaseAllowed(), isFalse);
});

test('expected failure', () async {
Expand Down

0 comments on commit 407ae02

Please sign in to comment.