refactor: username to playerInitials

pull/54/head
Allison Ryan 4 years ago
parent 721de958da
commit 533ba656fe

@ -22,14 +22,15 @@ enum CharacterType {
} }
/// {@template leaderboard_entry} /// {@template leaderboard_entry}
/// A model representing a leaderboard entry containing a score and a username. /// A model representing a leaderboard entry containing the player's initials,
/// score, and chosen character.
/// ///
/// Stored in Firestore `leaderboard` collection. /// Stored in Firestore `leaderboard` collection.
/// ///
/// Example: /// Example:
/// ```json /// ```json
/// { /// {
/// "username" : "test123", /// "playerInitials" : "ABC",
/// "score" : 1500, /// "score" : 1500,
/// "character" : "dash" /// "character" : "dash"
/// } /// }
@ -39,7 +40,7 @@ enum CharacterType {
class LeaderboardEntry extends Equatable { class LeaderboardEntry extends Equatable {
/// {@macro leaderboard_entry} /// {@macro leaderboard_entry}
const LeaderboardEntry({ const LeaderboardEntry({
required this.username, required this.playerInitials,
required this.score, required this.score,
required this.character, required this.character,
}); });
@ -52,11 +53,11 @@ class LeaderboardEntry extends Equatable {
/// Converts the [LeaderboardEntry] to [Map]. /// Converts the [LeaderboardEntry] to [Map].
Map<String, dynamic> toJson() => _$LeaderboardEntryToJson(this); Map<String, dynamic> toJson() => _$LeaderboardEntryToJson(this);
/// Username for [LeaderboardEntry]. /// Player's chosen initials for [LeaderboardEntry].
/// ///
/// Example: 'test123'. /// Example: 'ABC'.
@JsonKey(name: 'username') @JsonKey(name: 'playerInitials')
final String username; final String playerInitials;
/// Score for [LeaderboardEntry]. /// Score for [LeaderboardEntry].
/// ///
@ -72,11 +73,11 @@ class LeaderboardEntry extends Equatable {
/// An empty [LeaderboardEntry] object. /// An empty [LeaderboardEntry] object.
static const empty = LeaderboardEntry( static const empty = LeaderboardEntry(
username: '', playerInitials: '',
score: 0, score: 0,
character: CharacterType.dash, character: CharacterType.dash,
); );
@override @override
List<Object?> get props => [username, score, character]; List<Object?> get props => [playerInitials, score, character];
} }

@ -8,14 +8,14 @@ part of 'leaderboard_entry.dart';
LeaderboardEntry _$LeaderboardEntryFromJson(Map<String, dynamic> json) => LeaderboardEntry _$LeaderboardEntryFromJson(Map<String, dynamic> json) =>
LeaderboardEntry( LeaderboardEntry(
username: json['username'] as String, playerInitials: json['playerInitials'] as String,
score: json['score'] as int, score: json['score'] as int,
character: $enumDecode(_$CharacterTypeEnumMap, json['character']), character: $enumDecode(_$CharacterTypeEnumMap, json['character']),
); );
Map<String, dynamic> _$LeaderboardEntryToJson(LeaderboardEntry instance) => Map<String, dynamic> _$LeaderboardEntryToJson(LeaderboardEntry instance) =>
<String, dynamic>{ <String, dynamic>{
'username': instance.username, 'playerInitials': instance.playerInitials,
'score': instance.score, 'score': instance.score,
'character': _$CharacterTypeEnumMap[instance.character], 'character': _$CharacterTypeEnumMap[instance.character],
}; };

@ -58,7 +58,7 @@ void main() {
final top10Leaderboard = top10Scores final top10Leaderboard = top10Scores
.map( .map(
(score) => LeaderboardEntry( (score) => LeaderboardEntry(
username: 'user$score', playerInitials: 'user$score',
score: score, score: score,
character: CharacterType.dash, character: CharacterType.dash,
), ),
@ -145,7 +145,7 @@ void main() {
1000, 1000,
]; ];
final leaderboardEntry = LeaderboardEntry( final leaderboardEntry = LeaderboardEntry(
username: 'test123', playerInitials: 'test123',
score: entryScore, score: entryScore,
character: CharacterType.dash, character: CharacterType.dash,
); );

@ -4,13 +4,13 @@ import 'package:test/test.dart';
void main() { void main() {
group('LeaderboardEntry', () { group('LeaderboardEntry', () {
const data = <String, dynamic>{ const data = <String, dynamic>{
'username': 'test123', 'playerInitials': 'ABC',
'score': 1500, 'score': 1500,
'character': 'dash', 'character': 'dash',
}; };
const leaderboardEntry = LeaderboardEntry( const leaderboardEntry = LeaderboardEntry(
username: 'test123', playerInitials: 'ABC',
score: 1500, score: 1500,
character: CharacterType.dash, character: CharacterType.dash,
); );
@ -29,12 +29,6 @@ void main() {
}); });
test('can be converted to json', () { test('can be converted to json', () {
const leaderboardEntry = LeaderboardEntry(
username: 'test123',
score: 1500,
character: CharacterType.dash,
);
expect(leaderboardEntry.toJson(), equals(data)); expect(leaderboardEntry.toJson(), equals(data));
}); });

Loading…
Cancel
Save