description is now a required game parameter
This commit is contained in:
@@ -53,7 +53,7 @@ class GameDao extends DatabaseAccessor<AppDatabase> with _$GameDaoMixin {
|
||||
id: game.id,
|
||||
name: game.name,
|
||||
ruleset: game.ruleset ?? '',
|
||||
description: Value(game.description),
|
||||
description: game.description,
|
||||
color: game.color,
|
||||
icon: Value(game.icon),
|
||||
createdAt: game.createdAt,
|
||||
@@ -79,7 +79,7 @@ class GameDao extends DatabaseAccessor<AppDatabase> with _$GameDaoMixin {
|
||||
id: game.id,
|
||||
name: game.name,
|
||||
ruleset: game.ruleset ?? '',
|
||||
description: Value(game.description),
|
||||
description: game.description,
|
||||
color: game.color,
|
||||
icon: Value(game.icon),
|
||||
createdAt: game.createdAt,
|
||||
@@ -132,7 +132,7 @@ class GameDao extends DatabaseAccessor<AppDatabase> with _$GameDaoMixin {
|
||||
/// Updates the description of the game with the given [gameId].
|
||||
Future<void> updateGameDescription({
|
||||
required String gameId,
|
||||
required String? newDescription,
|
||||
required String newDescription,
|
||||
}) async {
|
||||
await (update(gameTable)..where((g) => g.id.equals(gameId))).write(
|
||||
GameTableCompanion(description: Value(newDescription)),
|
||||
|
||||
@@ -128,7 +128,7 @@ class MatchDao extends DatabaseAccessor<AppDatabase> with _$MatchDaoMixin {
|
||||
id: game.id,
|
||||
name: game.name,
|
||||
ruleset: game.ruleset ?? '',
|
||||
description: Value(game.description),
|
||||
description: game.description,
|
||||
color: game.color,
|
||||
icon: Value(game.icon),
|
||||
createdAt: game.createdAt,
|
||||
|
||||
@@ -46,7 +46,7 @@ class AppDatabase extends _$AppDatabase {
|
||||
AppDatabase([QueryExecutor? executor]) : super(executor ?? _openConnection());
|
||||
|
||||
@override
|
||||
int get schemaVersion => 2;
|
||||
int get schemaVersion => 1;
|
||||
|
||||
@override
|
||||
MigrationStrategy get migration {
|
||||
|
||||
@@ -673,9 +673,9 @@ class $GameTableTable extends GameTable
|
||||
late final GeneratedColumn<String> description = GeneratedColumn<String>(
|
||||
'description',
|
||||
aliasedName,
|
||||
true,
|
||||
false,
|
||||
type: DriftSqlType.string,
|
||||
requiredDuringInsert: false,
|
||||
requiredDuringInsert: true,
|
||||
);
|
||||
static const VerificationMeta _colorMeta = const VerificationMeta('color');
|
||||
@override
|
||||
@@ -757,6 +757,8 @@ class $GameTableTable extends GameTable
|
||||
_descriptionMeta,
|
||||
),
|
||||
);
|
||||
} else if (isInserting) {
|
||||
context.missing(_descriptionMeta);
|
||||
}
|
||||
if (data.containsKey('color')) {
|
||||
context.handle(
|
||||
@@ -804,7 +806,7 @@ class $GameTableTable extends GameTable
|
||||
description: attachedDatabase.typeMapping.read(
|
||||
DriftSqlType.string,
|
||||
data['${effectivePrefix}description'],
|
||||
),
|
||||
)!,
|
||||
color: attachedDatabase.typeMapping.read(
|
||||
DriftSqlType.string,
|
||||
data['${effectivePrefix}color'],
|
||||
@@ -830,7 +832,7 @@ class GameTableData extends DataClass implements Insertable<GameTableData> {
|
||||
final String id;
|
||||
final String name;
|
||||
final String ruleset;
|
||||
final String? description;
|
||||
final String description;
|
||||
final String color;
|
||||
final String? icon;
|
||||
final DateTime createdAt;
|
||||
@@ -838,7 +840,7 @@ class GameTableData extends DataClass implements Insertable<GameTableData> {
|
||||
required this.id,
|
||||
required this.name,
|
||||
required this.ruleset,
|
||||
this.description,
|
||||
required this.description,
|
||||
required this.color,
|
||||
this.icon,
|
||||
required this.createdAt,
|
||||
@@ -849,9 +851,7 @@ class GameTableData extends DataClass implements Insertable<GameTableData> {
|
||||
map['id'] = Variable<String>(id);
|
||||
map['name'] = Variable<String>(name);
|
||||
map['ruleset'] = Variable<String>(ruleset);
|
||||
if (!nullToAbsent || description != null) {
|
||||
map['description'] = Variable<String>(description);
|
||||
}
|
||||
map['description'] = Variable<String>(description);
|
||||
map['color'] = Variable<String>(color);
|
||||
if (!nullToAbsent || icon != null) {
|
||||
map['icon'] = Variable<String>(icon);
|
||||
@@ -865,9 +865,7 @@ class GameTableData extends DataClass implements Insertable<GameTableData> {
|
||||
id: Value(id),
|
||||
name: Value(name),
|
||||
ruleset: Value(ruleset),
|
||||
description: description == null && nullToAbsent
|
||||
? const Value.absent()
|
||||
: Value(description),
|
||||
description: Value(description),
|
||||
color: Value(color),
|
||||
icon: icon == null && nullToAbsent ? const Value.absent() : Value(icon),
|
||||
createdAt: Value(createdAt),
|
||||
@@ -883,7 +881,7 @@ class GameTableData extends DataClass implements Insertable<GameTableData> {
|
||||
id: serializer.fromJson<String>(json['id']),
|
||||
name: serializer.fromJson<String>(json['name']),
|
||||
ruleset: serializer.fromJson<String>(json['ruleset']),
|
||||
description: serializer.fromJson<String?>(json['description']),
|
||||
description: serializer.fromJson<String>(json['description']),
|
||||
color: serializer.fromJson<String>(json['color']),
|
||||
icon: serializer.fromJson<String?>(json['icon']),
|
||||
createdAt: serializer.fromJson<DateTime>(json['createdAt']),
|
||||
@@ -896,7 +894,7 @@ class GameTableData extends DataClass implements Insertable<GameTableData> {
|
||||
'id': serializer.toJson<String>(id),
|
||||
'name': serializer.toJson<String>(name),
|
||||
'ruleset': serializer.toJson<String>(ruleset),
|
||||
'description': serializer.toJson<String?>(description),
|
||||
'description': serializer.toJson<String>(description),
|
||||
'color': serializer.toJson<String>(color),
|
||||
'icon': serializer.toJson<String?>(icon),
|
||||
'createdAt': serializer.toJson<DateTime>(createdAt),
|
||||
@@ -907,7 +905,7 @@ class GameTableData extends DataClass implements Insertable<GameTableData> {
|
||||
String? id,
|
||||
String? name,
|
||||
String? ruleset,
|
||||
Value<String?> description = const Value.absent(),
|
||||
String? description,
|
||||
String? color,
|
||||
Value<String?> icon = const Value.absent(),
|
||||
DateTime? createdAt,
|
||||
@@ -915,7 +913,7 @@ class GameTableData extends DataClass implements Insertable<GameTableData> {
|
||||
id: id ?? this.id,
|
||||
name: name ?? this.name,
|
||||
ruleset: ruleset ?? this.ruleset,
|
||||
description: description.present ? description.value : this.description,
|
||||
description: description ?? this.description,
|
||||
color: color ?? this.color,
|
||||
icon: icon.present ? icon.value : this.icon,
|
||||
createdAt: createdAt ?? this.createdAt,
|
||||
@@ -968,7 +966,7 @@ class GameTableCompanion extends UpdateCompanion<GameTableData> {
|
||||
final Value<String> id;
|
||||
final Value<String> name;
|
||||
final Value<String> ruleset;
|
||||
final Value<String?> description;
|
||||
final Value<String> description;
|
||||
final Value<String> color;
|
||||
final Value<String?> icon;
|
||||
final Value<DateTime> createdAt;
|
||||
@@ -987,7 +985,7 @@ class GameTableCompanion extends UpdateCompanion<GameTableData> {
|
||||
required String id,
|
||||
required String name,
|
||||
required String ruleset,
|
||||
this.description = const Value.absent(),
|
||||
required String description,
|
||||
required String color,
|
||||
this.icon = const Value.absent(),
|
||||
required DateTime createdAt,
|
||||
@@ -995,6 +993,7 @@ class GameTableCompanion extends UpdateCompanion<GameTableData> {
|
||||
}) : id = Value(id),
|
||||
name = Value(name),
|
||||
ruleset = Value(ruleset),
|
||||
description = Value(description),
|
||||
color = Value(color),
|
||||
createdAt = Value(createdAt);
|
||||
static Insertable<GameTableData> custom({
|
||||
@@ -1023,7 +1022,7 @@ class GameTableCompanion extends UpdateCompanion<GameTableData> {
|
||||
Value<String>? id,
|
||||
Value<String>? name,
|
||||
Value<String>? ruleset,
|
||||
Value<String?>? description,
|
||||
Value<String>? description,
|
||||
Value<String>? color,
|
||||
Value<String?>? icon,
|
||||
Value<DateTime>? createdAt,
|
||||
@@ -3663,7 +3662,7 @@ typedef $$GameTableTableCreateCompanionBuilder =
|
||||
required String id,
|
||||
required String name,
|
||||
required String ruleset,
|
||||
Value<String?> description,
|
||||
required String description,
|
||||
required String color,
|
||||
Value<String?> icon,
|
||||
required DateTime createdAt,
|
||||
@@ -3674,7 +3673,7 @@ typedef $$GameTableTableUpdateCompanionBuilder =
|
||||
Value<String> id,
|
||||
Value<String> name,
|
||||
Value<String> ruleset,
|
||||
Value<String?> description,
|
||||
Value<String> description,
|
||||
Value<String> color,
|
||||
Value<String?> icon,
|
||||
Value<DateTime> createdAt,
|
||||
@@ -3908,7 +3907,7 @@ class $$GameTableTableTableManager
|
||||
Value<String> id = const Value.absent(),
|
||||
Value<String> name = const Value.absent(),
|
||||
Value<String> ruleset = const Value.absent(),
|
||||
Value<String?> description = const Value.absent(),
|
||||
Value<String> description = const Value.absent(),
|
||||
Value<String> color = const Value.absent(),
|
||||
Value<String?> icon = const Value.absent(),
|
||||
Value<DateTime> createdAt = const Value.absent(),
|
||||
@@ -3928,7 +3927,7 @@ class $$GameTableTableTableManager
|
||||
required String id,
|
||||
required String name,
|
||||
required String ruleset,
|
||||
Value<String?> description = const Value.absent(),
|
||||
required String description,
|
||||
required String color,
|
||||
Value<String?> icon = const Value.absent(),
|
||||
required DateTime createdAt,
|
||||
|
||||
@@ -4,7 +4,7 @@ class GameTable extends Table {
|
||||
TextColumn get id => text()();
|
||||
TextColumn get name => text()();
|
||||
TextColumn get ruleset => text()();
|
||||
TextColumn get description => text().nullable()();
|
||||
TextColumn get description => text()();
|
||||
TextColumn get color => text()();
|
||||
TextColumn get icon => text().nullable()();
|
||||
DateTimeColumn get createdAt => dateTime()();
|
||||
|
||||
@@ -6,7 +6,7 @@ class Game {
|
||||
final DateTime createdAt;
|
||||
final String name;
|
||||
final String? ruleset;
|
||||
final String? description;
|
||||
final String description;
|
||||
final String color;
|
||||
final String? icon;
|
||||
|
||||
@@ -15,7 +15,7 @@ class Game {
|
||||
DateTime? createdAt,
|
||||
required this.name,
|
||||
this.ruleset,
|
||||
this.description,
|
||||
required this.description,
|
||||
required this.color,
|
||||
this.icon,
|
||||
}) : id = id ?? const Uuid().v4(),
|
||||
|
||||
@@ -131,7 +131,7 @@ void main() {
|
||||
|
||||
// Verifies that a game with null optional fields can be added and retrieved.
|
||||
test('addGame handles game with null optional fields', () async {
|
||||
final gameWithNulls = Game(name: 'Simple Game', color: '0xFF000000');
|
||||
final gameWithNulls = Game(name: 'Simple Game', description: 'A simple game', color: '0xFF000000');
|
||||
final result = await database.gameDao.addGame(game: gameWithNulls);
|
||||
expect(result, true);
|
||||
|
||||
@@ -139,7 +139,7 @@ void main() {
|
||||
gameId: gameWithNulls.id,
|
||||
);
|
||||
expect(fetchedGame.name, 'Simple Game');
|
||||
expect(fetchedGame.description, isNull);
|
||||
expect(fetchedGame.description, 'A simple game');
|
||||
expect(fetchedGame.color, '0xFF000000');
|
||||
expect(fetchedGame.icon, isNull);
|
||||
});
|
||||
@@ -305,19 +305,19 @@ void main() {
|
||||
expect(updatedGame.description, 'An updated description');
|
||||
});
|
||||
|
||||
// Verifies that updateGameDescription can set the description to null.
|
||||
test('updateGameDescription can set description to null', () async {
|
||||
// Verifies that updateGameDescription can set the description to an empty string.
|
||||
test('updateGameDescription can set description to empty string', () async {
|
||||
await database.gameDao.addGame(game: testGame1);
|
||||
|
||||
await database.gameDao.updateGameDescription(
|
||||
gameId: testGame1.id,
|
||||
newDescription: null,
|
||||
newDescription: '',
|
||||
);
|
||||
|
||||
final updatedGame = await database.gameDao.getGameById(
|
||||
gameId: testGame1.id,
|
||||
);
|
||||
expect(updatedGame.description, isNull);
|
||||
expect(updatedGame.description, '');
|
||||
});
|
||||
|
||||
// Verifies that updateGameDescription does nothing when game doesn't exist.
|
||||
@@ -502,7 +502,7 @@ void main() {
|
||||
gameId: longGame.id,
|
||||
);
|
||||
expect(fetchedGame.name.length, 10000);
|
||||
expect(fetchedGame.description?.length, 10000);
|
||||
expect(fetchedGame.description.length, 10000);
|
||||
expect(fetchedGame.ruleset?.length, 10000);
|
||||
});
|
||||
|
||||
|
||||
@@ -48,7 +48,7 @@ void main() {
|
||||
name: 'Test Group 2',
|
||||
members: [testPlayer4, testPlayer5],
|
||||
);
|
||||
testGame = Game(name: 'Test Game', color: '0xFF000000');
|
||||
testGame = Game(name: 'Test Game', description: 'A test game', color: '0xFF000000');
|
||||
testMatch1 = Match(
|
||||
name: 'First Test Match',
|
||||
game: testGame,
|
||||
|
||||
@@ -46,7 +46,7 @@ void main() {
|
||||
name: 'Test Group',
|
||||
members: [testPlayer1, testPlayer2, testPlayer3],
|
||||
);
|
||||
testGame = Game(name: 'Test Game', color: '0xFF000000');
|
||||
testGame = Game(name: 'Test Game', description: 'A test game', color: '0xFF000000');
|
||||
testMatchOnlyGroup = Match(
|
||||
name: 'Test Match with Group',
|
||||
game: testGame,
|
||||
|
||||
@@ -31,7 +31,7 @@ void main() {
|
||||
testPlayer1 = Player(name: 'Alice');
|
||||
testPlayer2 = Player(name: 'Bob');
|
||||
testPlayer3 = Player(name: 'Charlie');
|
||||
testGame = Game(name: 'Test Game', color: '0xFF000000');
|
||||
testGame = Game(name: 'Test Game', description: 'A test game', color: '0xFF000000');
|
||||
testMatch1 = Match(
|
||||
name: 'Test Match 1',
|
||||
game: testGame,
|
||||
|
||||
@@ -48,8 +48,8 @@ void main() {
|
||||
name: 'Team Gamma',
|
||||
members: [testPlayer1, testPlayer3],
|
||||
);
|
||||
testGame1 = Game(name: 'Game 1', color: '0xFF000000');
|
||||
testGame2 = Game(name: 'Game 2', color: '0xFF000000');
|
||||
testGame1 = Game(name: 'Game 1', description: 'Test game 1', color: '0xFF000000');
|
||||
testGame2 = Game(name: 'Game 2', description: 'Test game 2', color: '0xFF000000');
|
||||
});
|
||||
|
||||
await database.playerDao.addPlayersAsList(
|
||||
|
||||
Reference in New Issue
Block a user