-
Notifications
You must be signed in to change notification settings - Fork 140
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: created pared-down version of User object (#2499)
- Loading branch information
1 parent
20f2641
commit 9c6d652
Showing
13 changed files
with
112 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -127,7 +127,7 @@ void main() { | |
authProvider: AuthProvider.google, | ||
); | ||
const email = '[email protected]'; | ||
const user = User( | ||
const user = PrivateUser( | ||
id: 42, | ||
email: email, | ||
jwtIssuer: googleJwtIssuer, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -100,7 +100,7 @@ void main() { | |
}); | ||
|
||
group('getCurrentUser', () { | ||
const user = User( | ||
const user = PrivateUser( | ||
id: 123, | ||
email: '[email protected]', | ||
jwtIssuer: 'https://accounts.google.com', | ||
|
@@ -1221,7 +1221,7 @@ void main() { | |
|
||
group('createUser', () { | ||
const userName = 'Jane Doe'; | ||
final user = User( | ||
final user = PrivateUser( | ||
id: 1, | ||
email: '[email protected]', | ||
displayName: userName, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
packages/shorebird_code_push_protocol/lib/src/models/organization_user.g.dart
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,18 @@ | ||
import 'package:json_annotation/json_annotation.dart'; | ||
import 'package:meta/meta.dart'; | ||
import 'package:shorebird_code_push_protocol/shorebird_code_push_protocol.dart'; | ||
|
||
part 'user.g.dart'; | ||
part 'private_user.g.dart'; | ||
|
||
/// {@template user} | ||
/// A user account which contains zero or more apps. | ||
/// A fully-detailed user object, possibly including sensitive information. | ||
/// This should only be used when querying the user's own information. For other | ||
/// users, use [PublicUser]. | ||
/// {@endtemplate} | ||
@JsonSerializable() | ||
class User { | ||
class PrivateUser { | ||
/// {@macro user} | ||
const User({ | ||
const PrivateUser({ | ||
required this.id, | ||
required this.email, | ||
required this.jwtIssuer, | ||
|
@@ -19,13 +22,14 @@ class User { | |
this.patchOverageLimit, | ||
}); | ||
|
||
/// Converts a Map<String, dynamic> to a [User] | ||
factory User.fromJson(Map<String, dynamic> json) => _$UserFromJson(json); | ||
/// Converts a Map<String, dynamic> to a [PrivateUser] | ||
factory PrivateUser.fromJson(Map<String, dynamic> json) => | ||
_$PrivateUserFromJson(json); | ||
|
||
// coverage:ignore-start | ||
/// Constructs a user with arbitrary default values for testing. | ||
@visibleForTesting | ||
factory User.forTest({ | ||
factory PrivateUser.forTest({ | ||
int id = 42, | ||
String email = '[email protected]', | ||
String jwtIssuer = 'https://accounts.google.com', | ||
|
@@ -34,7 +38,7 @@ class User { | |
String? stripeCustomerId, | ||
int? patchOverageLimit = 0, | ||
}) => | ||
User( | ||
PrivateUser( | ||
id: id, | ||
email: email, | ||
jwtIssuer: jwtIssuer, | ||
|
@@ -45,8 +49,8 @@ class User { | |
); | ||
// coverage:ignore-end | ||
|
||
/// Converts a [User] to a Map<String, dynamic> | ||
Map<String, dynamic> toJson() => _$UserToJson(this); | ||
/// Converts a [PrivateUser] to a Map<String, dynamic> | ||
Map<String, dynamic> toJson() => _$PrivateUserToJson(this); | ||
|
||
/// The unique user identifier. | ||
final int id; | ||
|
11 changes: 6 additions & 5 deletions
11
..._push_protocol/lib/src/models/user.g.dart → ...otocol/lib/src/models/private_user.g.dart
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
43 changes: 43 additions & 0 deletions
43
packages/shorebird_code_push_protocol/lib/src/models/public_user.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import 'package:json_annotation/json_annotation.dart'; | ||
import 'package:shorebird_code_push_protocol/shorebird_code_push_protocol.dart'; | ||
|
||
part 'public_user.g.dart'; | ||
|
||
/// {@template user} | ||
/// A Shorebird user. This is a pared down version of [PrivateUser]. | ||
/// {@endtemplate} | ||
@JsonSerializable() | ||
class PublicUser { | ||
/// {@macro user} | ||
PublicUser({ | ||
required this.id, | ||
required this.email, | ||
required this.displayName, | ||
}); | ||
|
||
/// Converts a Map<String, dynamic> to a [PublicUser] | ||
factory PublicUser.fromJson(Map<String, dynamic> json) => | ||
_$PublicUserFromJson(json); | ||
|
||
/// Constructs a [PublicUser] from a [PrivateUser], removing sensitive | ||
/// information. | ||
factory PublicUser.fromPrivateUser(PrivateUser fullUser) { | ||
return PublicUser( | ||
id: fullUser.id, | ||
email: fullUser.email, | ||
displayName: fullUser.displayName, | ||
); | ||
} | ||
|
||
/// Converts a [PublicUser] to a JSON map. | ||
Map<String, dynamic> toJson() => _$PublicUserToJson(this); | ||
|
||
/// The user's unique identifier. | ||
final int id; | ||
|
||
/// The user's email address. | ||
final String email; | ||
|
||
/// The user's name. | ||
final String? displayName; | ||
} |
30 changes: 30 additions & 0 deletions
30
packages/shorebird_code_push_protocol/lib/src/models/public_user.g.dart
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,9 +2,9 @@ import 'package:shorebird_code_push_protocol/shorebird_code_push_protocol.dart'; | |
import 'package:test/test.dart'; | ||
|
||
void main() { | ||
group(User, () { | ||
group(PrivateUser, () { | ||
test('can be (de)serialized', () { | ||
const user = User( | ||
const user = PrivateUser( | ||
id: 1, | ||
email: '[email protected]', | ||
stripeCustomerId: 'test-customer-id', | ||
|
@@ -13,7 +13,7 @@ void main() { | |
patchOverageLimit: 123, | ||
); | ||
expect( | ||
User.fromJson(user.toJson()).toJson(), | ||
PrivateUser.fromJson(user.toJson()).toJson(), | ||
equals(user.toJson()), | ||
); | ||
}); | ||
|