Skip to content

Commit

Permalink
feat: add game domain package (#4)
Browse files Browse the repository at this point in the history
* feat: add game domain package

* feat: add workflow

* chore: remove unused class and update descriptions
  • Loading branch information
B0berman authored Feb 26, 2024
1 parent 14ddeb8 commit 10a4e6f
Show file tree
Hide file tree
Showing 9 changed files with 174 additions and 0 deletions.
20 changes: 20 additions & 0 deletions .github/workflows/api_game_domain.yaml
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
7 changes: 7 additions & 0 deletions api/packages/game_domain/.gitignore
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
1 change: 1 addition & 0 deletions api/packages/game_domain/analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
include: package:very_good_analysis/analysis_options.5.1.0.yaml
4 changes: 4 additions & 0 deletions api/packages/game_domain/lib/game_domain.dart
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 api/packages/game_domain/lib/src/models/leaderboard_player.dart
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 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.

1 change: 1 addition & 0 deletions api/packages/game_domain/lib/src/models/models.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export 'leaderboard_player.dart';
17 changes: 17 additions & 0 deletions api/packages/game_domain/pubspec.yaml
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
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),
),
);
});
});
}

0 comments on commit 10a4e6f

Please sign in to comment.