-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: add game domain package * feat: add workflow * chore: remove unused class and update descriptions
- Loading branch information
Showing
9 changed files
with
174 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,20 @@ | ||
name: api_game_domain | ||
|
||
concurrency: | ||
group: ${{ github.workflow }}-${{ github.ref }} | ||
cancel-in-progress: true | ||
|
||
on: | ||
pull_request: | ||
paths: | ||
- "api/packages/game_domain/**" | ||
- ".github/workflows/api_game_domain.yaml" | ||
branches: | ||
- main | ||
|
||
jobs: | ||
build: | ||
uses: VeryGoodOpenSource/very_good_workflows/.github/workflows/dart_package.yml@v1 | ||
with: | ||
dart_sdk: stable | ||
working_directory: api/packages/game_domain |
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,7 @@ | ||
# See https://www.dartlang.org/guides/libraries/private-files | ||
|
||
# Files and directories created by pub | ||
.dart_tool/ | ||
.packages | ||
build/ | ||
pubspec.lock |
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 @@ | ||
include: package:very_good_analysis/analysis_options.5.1.0.yaml |
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,4 @@ | ||
/// Domain classes for the game. | ||
library game_domain; | ||
|
||
export 'src/models/models.dart'; |
35 changes: 35 additions & 0 deletions
35
api/packages/game_domain/lib/src/models/leaderboard_player.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,35 @@ | ||
import 'package:equatable/equatable.dart'; | ||
import 'package:json_annotation/json_annotation.dart'; | ||
|
||
part 'leaderboard_player.g.dart'; | ||
|
||
/// {@template leaderboard_player} | ||
/// A model that represents a player in the leaderboard. | ||
/// {@endtemplate} | ||
@JsonSerializable(ignoreUnannotated: true) | ||
class LeaderboardPlayer extends Equatable { | ||
/// {@macro leaderboard_player} | ||
const LeaderboardPlayer({ | ||
required this.id, | ||
required this.initials, | ||
}); | ||
|
||
/// {@macro leaderboard_player} | ||
factory LeaderboardPlayer.fromJson(Map<String, dynamic> json) => | ||
_$LeaderboardPlayerFromJson(json); | ||
|
||
/// Unique identifier of the leaderboard player object | ||
/// and session id for the player. | ||
@JsonKey() | ||
final String id; | ||
|
||
/// Initials of the player. | ||
@JsonKey() | ||
final String initials; | ||
|
||
/// Returns a json representation from this instance. | ||
Map<String, dynamic> toJson() => _$LeaderboardPlayerToJson(this); | ||
|
||
@override | ||
List<Object?> get props => [id, initials]; | ||
} |
19 changes: 19 additions & 0 deletions
19
api/packages/game_domain/lib/src/models/leaderboard_player.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 |
---|---|---|
@@ -0,0 +1 @@ | ||
export 'leaderboard_player.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,17 @@ | ||
name: game_domain | ||
description: Domain classes for the game. | ||
version: 0.1.0+1 | ||
publish_to: none | ||
|
||
environment: | ||
sdk: ">=3.0.0 <4.0.0" | ||
|
||
dev_dependencies: | ||
build_runner: ^2.4.8 | ||
mocktail: ^1.0.0 | ||
test: ^1.19.2 | ||
very_good_analysis: ^5.1.0 | ||
|
||
dependencies: | ||
equatable: ^2.0.5 | ||
json_annotation: ^4.8.1 |
70 changes: 70 additions & 0 deletions
70
api/packages/game_domain/test/src/models/leaderboard_player_test.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,70 @@ | ||
// ignore_for_file: prefer_const_constructors | ||
|
||
import 'package:game_domain/game_domain.dart'; | ||
import 'package:test/test.dart'; | ||
|
||
void main() { | ||
group('LeaderboardPlayer', () { | ||
test('can be instantiated', () { | ||
expect( | ||
LeaderboardPlayer( | ||
id: 'id', | ||
initials: 'TST', | ||
), | ||
isNotNull, | ||
); | ||
}); | ||
|
||
final leaderboardPlayer = LeaderboardPlayer( | ||
id: 'id', | ||
initials: 'TST', | ||
); | ||
|
||
test('toJson returns the instance as json', () { | ||
expect( | ||
leaderboardPlayer.toJson(), | ||
equals({ | ||
'id': 'id', | ||
'initials': 'TST', | ||
}), | ||
); | ||
}); | ||
|
||
test('fromJson returns the correct instance', () { | ||
expect( | ||
LeaderboardPlayer.fromJson(const { | ||
'id': 'id', | ||
'initials': 'TST', | ||
}), | ||
equals(leaderboardPlayer), | ||
); | ||
}); | ||
|
||
test('supports equality', () { | ||
expect( | ||
LeaderboardPlayer(id: '', initials: 'TST'), | ||
equals(LeaderboardPlayer(id: '', initials: 'TST')), | ||
); | ||
|
||
expect( | ||
LeaderboardPlayer( | ||
id: '', | ||
initials: 'TST', | ||
), | ||
isNot( | ||
equals(leaderboardPlayer), | ||
), | ||
); | ||
|
||
expect( | ||
LeaderboardPlayer( | ||
id: 'id', | ||
initials: 'WOW', | ||
), | ||
isNot( | ||
equals(leaderboardPlayer), | ||
), | ||
); | ||
}); | ||
}); | ||
} |