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}
/// 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.
///
/// Example:
/// ```json
/// {
/// "username" : "test123",
/// "playerInitials" : "ABC",
/// "score" : 1500,
/// "character" : "dash"
/// }
@ -39,7 +40,7 @@ enum CharacterType {
class LeaderboardEntry extends Equatable {
/// {@macro leaderboard_entry}
const LeaderboardEntry({
required this.username,
required this.playerInitials,
required this.score,
required this.character,
});
@ -52,11 +53,11 @@ class LeaderboardEntry extends Equatable {
/// Converts the [LeaderboardEntry] to [Map].
Map<String, dynamic> toJson() => _$LeaderboardEntryToJson(this);
/// Username for [LeaderboardEntry].
/// Player's chosen initials for [LeaderboardEntry].
///
/// Example: 'test123'.
@JsonKey(name: 'username')
final String username;
/// Example: 'ABC'.
@JsonKey(name: 'playerInitials')
final String playerInitials;
/// Score for [LeaderboardEntry].
///
@ -72,11 +73,11 @@ class LeaderboardEntry extends Equatable {
/// An empty [LeaderboardEntry] object.
static const empty = LeaderboardEntry(
username: '',
playerInitials: '',
score: 0,
character: CharacterType.dash,
);
@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(
username: json['username'] as String,
playerInitials: json['playerInitials'] as String,
score: json['score'] as int,
character: $enumDecode(_$CharacterTypeEnumMap, json['character']),
);
Map<String, dynamic> _$LeaderboardEntryToJson(LeaderboardEntry instance) =>
<String, dynamic>{
'username': instance.username,
'playerInitials': instance.playerInitials,
'score': instance.score,
'character': _$CharacterTypeEnumMap[instance.character],
};

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

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

Loading…
Cancel
Save