Implemented updateGameName() and tests for it
This commit is contained in:
@@ -306,4 +306,17 @@ class GameDao extends DatabaseAccessor<AppDatabase> with _$GameDaoMixin {
|
|||||||
final result = await query.getSingleOrNull();
|
final result = await query.getSingleOrNull();
|
||||||
return result != null;
|
return result != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Changes the title of the game with the given [gameId] to [newName].
|
||||||
|
/// Returns `true` if more than 0 rows were affected, otherwise `false`.
|
||||||
|
Future<bool> updateGameName({
|
||||||
|
required String gameId,
|
||||||
|
required String newName,
|
||||||
|
}) async {
|
||||||
|
final query = update(gameTable)..where((g) => g.id.equals(gameId));
|
||||||
|
final rowsAffected = await query.write(
|
||||||
|
GameTableCompanion(name: Value(newName)),
|
||||||
|
);
|
||||||
|
return rowsAffected > 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -308,5 +308,23 @@ void main() {
|
|||||||
|
|
||||||
expect(removedWinner, null);
|
expect(removedWinner, null);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('Renaming a game works correctly', () async {
|
||||||
|
await database.gameDao.addGame(game: testGame1);
|
||||||
|
|
||||||
|
var fetchedGame = await database.gameDao.getGameById(
|
||||||
|
gameId: testGame1.id,
|
||||||
|
);
|
||||||
|
expect(fetchedGame.name, testGame1.name);
|
||||||
|
|
||||||
|
const newName = 'Updated Game Name';
|
||||||
|
await database.gameDao.updateGameName(
|
||||||
|
gameId: testGame1.id,
|
||||||
|
newName: newName,
|
||||||
|
);
|
||||||
|
|
||||||
|
fetchedGame = await database.gameDao.getGameById(gameId: testGame1.id);
|
||||||
|
expect(fetchedGame.name, newName);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user