Skip to content

Commit 903f222

Browse files
author
serverpod_cloud
committed
feat(scloud): cf751a8f30d1920646823e9e1583bbdf74e12d2d
1 parent a9385ba commit 903f222

2 files changed

Lines changed: 36 additions & 16 deletions

File tree

serverpod_cloud_cli/lib/commands/me/me.dart

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,43 @@ abstract class MeCommands {
99
}) async {
1010
final user = await cloudApiClient.users.readUser();
1111

12-
String planDisplayName = 'No plan';
12+
SubscriptionInfo? subscriptionInfo;
1313
try {
14-
final subscriptionInfo = await cloudApiClient.plans.getSubscriptionInfo();
15-
planDisplayName = subscriptionInfo.planDisplayName;
16-
} on NoSubscriptionException {
17-
planDisplayName = 'No plan';
14+
subscriptionInfo = await cloudApiClient.plans.getSubscriptionInfo();
15+
} on NoSubscriptionException catch (_) {
1816
} on Exception catch (e) {
1917
logger.debug('Failed to fetch subscription info: $e');
2018
}
2119

20+
final planDisplayName = subscriptionInfo?.planDisplayName ?? 'No plan';
21+
final status = _determineStatus(subscriptionInfo) ?? '';
22+
2223
final table = TablePrinter(
23-
headers: ['Email', 'Plan'],
24+
headers: ['Email', 'Plan', 'Status'],
2425
rows: [
25-
[user.email, planDisplayName],
26+
[user.email, planDisplayName, status],
2627
],
2728
);
2829
table.writeLines(logger.line);
2930
}
31+
32+
static String? _determineStatus(final SubscriptionInfo? subscriptionInfo) {
33+
if (subscriptionInfo == null) {
34+
return null;
35+
}
36+
37+
final now = DateTime.now();
38+
final today = DateTime(now.year, now.month, now.day);
39+
40+
final endDate = subscriptionInfo.endDate;
41+
final trialEndDate = subscriptionInfo.trialEndDate;
42+
43+
if (endDate != null && endDate.isBefore(today)) {
44+
return 'Subscription ended ${endDate.toString().substring(0, 10)}';
45+
} else if (trialEndDate != null && !trialEndDate.isBefore(today)) {
46+
return 'Trial until ${trialEndDate.toString().substring(0, 10)}';
47+
} else {
48+
return 'Subscription active';
49+
}
50+
}
3051
}

serverpod_cloud_cli/test_integration/commands/me_command_test.dart

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import 'package:serverpod_cloud_cli/command_runner/helpers/cloud_cli_service_pro
99
import 'package:ground_control_client/ground_control_client.dart';
1010
import 'package:ground_control_client/ground_control_client_test_tools.dart';
1111

12-
import '../../test_utils/command_logger_matchers.dart';
1312
import '../../test_utils/test_command_logger.dart';
1413

1514
void main() {
@@ -60,11 +59,11 @@ void main() {
6059

6160
expect(logger.lineCalls, isNotEmpty);
6261
expect(
63-
logger.lineCalls,
62+
logger.lineCalls.map((final l) => l.line),
6463
containsAllInOrder([
65-
equalsLineCall(line: 'Email | Plan '),
66-
equalsLineCall(line: '-----------------+-------------'),
67-
equalsLineCall(line: 'test@example.com | Early Access'),
64+
'Email | Plan | Status ',
65+
'-----------------+--------------+-----------------------',
66+
contains('test@example.com | Early Access | Trial until 20'),
6867
]),
6968
);
7069
});
@@ -93,11 +92,11 @@ void main() {
9392

9493
expect(logger.lineCalls, isNotEmpty);
9594
expect(
96-
logger.lineCalls,
95+
logger.lineCalls.map((final l) => l.line),
9796
containsAllInOrder([
98-
equalsLineCall(line: 'Email | Plan '),
99-
equalsLineCall(line: '-----------------+--------'),
100-
equalsLineCall(line: 'test@example.com | No plan'),
97+
'Email | Plan | Status',
98+
'-----------------+---------+-------',
99+
'test@example.com | No plan | ',
101100
]),
102101
);
103102
});

0 commit comments

Comments
 (0)