feat(shorebird_code_push_protocol): Add email field to User (#276)

This commit is contained in:
Bryan Oltman
2023-04-12 11:32:14 -04:00
committed by GitHub
parent 34cfb4b6bc
commit 28a925d58d
3 changed files with 11 additions and 2 deletions
@@ -8,7 +8,11 @@ part 'user.g.dart';
@JsonSerializable()
class User {
/// {@macro user}
const User({required this.id, this.hasActiveSubscription = false});
const User({
required this.id,
required this.email,
this.hasActiveSubscription = false,
});
/// Converts a Map<String, dynamic> to a [User]
factory User.fromJson(Map<String, dynamic> json) => _$UserFromJson(json);
@@ -19,6 +23,9 @@ class User {
/// The unique user identifier.
final int id;
/// The user's email address, as provided by the user during signup.
final String email;
/// Whether the user is currently a paying customer.
final bool hasActiveSubscription;
}
@@ -14,6 +14,7 @@ User _$UserFromJson(Map<String, dynamic> json) => $checkedCreate(
($checkedConvert) {
final val = User(
id: $checkedConvert('id', (v) => v as int),
email: $checkedConvert('email', (v) => v as String),
hasActiveSubscription: $checkedConvert(
'has_active_subscription', (v) => v as bool? ?? false),
);
@@ -24,5 +25,6 @@ User _$UserFromJson(Map<String, dynamic> json) => $checkedCreate(
Map<String, dynamic> _$UserToJson(User instance) => <String, dynamic>{
'id': instance.id,
'email': instance.email,
'has_active_subscription': instance.hasActiveSubscription,
};
@@ -4,7 +4,7 @@ import 'package:test/test.dart';
void main() {
group('User', () {
test('can be (de)serialized', () {
const user = User(id: 1);
const user = User(id: 1, email: 'test@shorebird.dev');
expect(
User.fromJson(user.toJson()).toJson(),
equals(user.toJson()),