feat(shorebird_code_push_protocol): Add email field to User (#276)
This commit is contained in:
@@ -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()),
|
||||
|
||||
Reference in New Issue
Block a user