Renamed folder to "models"
This commit is contained in:
@@ -3,8 +3,8 @@ import 'package:drift/drift.dart' hide isNull;
|
||||
import 'package:drift/native.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:tallee/data/db/database.dart';
|
||||
import 'package:tallee/data/dto/group.dart';
|
||||
import 'package:tallee/data/dto/player.dart';
|
||||
import 'package:tallee/data/models/group.dart';
|
||||
import 'package:tallee/data/models/player.dart';
|
||||
|
||||
void main() {
|
||||
late AppDatabase database;
|
||||
@@ -62,7 +62,6 @@ void main() {
|
||||
await database.close();
|
||||
});
|
||||
group('Group Tests', () {
|
||||
|
||||
// Verifies that a single group can be added and retrieved with all fields and members intact.
|
||||
test('Adding and fetching a single group works correctly', () async {
|
||||
await database.groupDao.addGroup(group: testGroup1);
|
||||
@@ -277,20 +276,20 @@ void main() {
|
||||
});
|
||||
|
||||
// Verifies that updateGroupDescription returns false for a non-existent group.
|
||||
test('updateGroupDescription returns false for non-existent group',
|
||||
() async {
|
||||
final updated = await database.groupDao.updateGroupDescription(
|
||||
groupId: 'non-existent-id',
|
||||
newDescription: 'New Description',
|
||||
);
|
||||
expect(updated, false);
|
||||
});
|
||||
test(
|
||||
'updateGroupDescription returns false for non-existent group',
|
||||
() async {
|
||||
final updated = await database.groupDao.updateGroupDescription(
|
||||
groupId: 'non-existent-id',
|
||||
newDescription: 'New Description',
|
||||
);
|
||||
expect(updated, false);
|
||||
},
|
||||
);
|
||||
|
||||
// Verifies that deleteAllGroups removes all groups from the database.
|
||||
test('deleteAllGroups removes all groups', () async {
|
||||
await database.groupDao.addGroupsAsList(
|
||||
groups: [testGroup1, testGroup2],
|
||||
);
|
||||
await database.groupDao.addGroupsAsList(groups: [testGroup1, testGroup2]);
|
||||
|
||||
final countBefore = await database.groupDao.getGroupCount();
|
||||
expect(countBefore, 2);
|
||||
|
||||
@@ -4,10 +4,10 @@ import 'package:drift/native.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:tallee/core/enums.dart';
|
||||
import 'package:tallee/data/db/database.dart';
|
||||
import 'package:tallee/data/dto/game.dart';
|
||||
import 'package:tallee/data/dto/group.dart';
|
||||
import 'package:tallee/data/dto/match.dart';
|
||||
import 'package:tallee/data/dto/player.dart';
|
||||
import 'package:tallee/data/models/game.dart';
|
||||
import 'package:tallee/data/models/group.dart';
|
||||
import 'package:tallee/data/models/match.dart';
|
||||
import 'package:tallee/data/models/player.dart';
|
||||
|
||||
void main() {
|
||||
late AppDatabase database;
|
||||
|
||||
@@ -2,12 +2,12 @@ import 'package:clock/clock.dart';
|
||||
import 'package:drift/drift.dart';
|
||||
import 'package:drift/native.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:tallee/data/db/database.dart';
|
||||
import 'package:tallee/data/dto/game.dart';
|
||||
import 'package:tallee/data/dto/match.dart';
|
||||
import 'package:tallee/data/dto/player.dart';
|
||||
import 'package:tallee/data/dto/team.dart';
|
||||
import 'package:tallee/core/enums.dart';
|
||||
import 'package:tallee/data/db/database.dart';
|
||||
import 'package:tallee/data/models/game.dart';
|
||||
import 'package:tallee/data/models/match.dart';
|
||||
import 'package:tallee/data/models/player.dart';
|
||||
import 'package:tallee/data/models/team.dart';
|
||||
|
||||
void main() {
|
||||
late AppDatabase database;
|
||||
@@ -37,20 +37,23 @@ void main() {
|
||||
testPlayer2 = Player(name: 'Bob', description: '');
|
||||
testPlayer3 = Player(name: 'Charlie', description: '');
|
||||
testPlayer4 = Player(name: 'Diana', description: '');
|
||||
testTeam1 = Team(
|
||||
name: 'Team Alpha',
|
||||
members: [testPlayer1, testPlayer2],
|
||||
testTeam1 = Team(name: 'Team Alpha', members: [testPlayer1, testPlayer2]);
|
||||
testTeam2 = Team(name: 'Team Beta', members: [testPlayer3, testPlayer4]);
|
||||
testTeam3 = Team(name: 'Team Gamma', members: [testPlayer1, testPlayer3]);
|
||||
testGame1 = Game(
|
||||
name: 'Game 1',
|
||||
ruleset: Ruleset.singleWinner,
|
||||
description: 'Test game 1',
|
||||
color: GameColor.blue,
|
||||
icon: '',
|
||||
);
|
||||
testTeam2 = Team(
|
||||
name: 'Team Beta',
|
||||
members: [testPlayer3, testPlayer4],
|
||||
testGame2 = Game(
|
||||
name: 'Game 2',
|
||||
ruleset: Ruleset.highestScore,
|
||||
description: 'Test game 2',
|
||||
color: GameColor.red,
|
||||
icon: '',
|
||||
);
|
||||
testTeam3 = Team(
|
||||
name: 'Team Gamma',
|
||||
members: [testPlayer1, testPlayer3],
|
||||
);
|
||||
testGame1 = Game(name: 'Game 1', ruleset: Ruleset.singleWinner, description: 'Test game 1', color: GameColor.blue, icon: '');
|
||||
testGame2 = Game(name: 'Game 2', ruleset: Ruleset.highestScore, description: 'Test game 2', color: GameColor.red, icon: '');
|
||||
});
|
||||
|
||||
await database.playerDao.addPlayersAsList(
|
||||
@@ -65,7 +68,6 @@ void main() {
|
||||
});
|
||||
|
||||
group('Team Tests', () {
|
||||
|
||||
// Verifies that a single team can be added and retrieved with all fields intact.
|
||||
test('Adding and fetching a single team works correctly', () async {
|
||||
final added = await database.teamDao.addTeam(team: testTeam1);
|
||||
@@ -285,10 +287,7 @@ void main() {
|
||||
test('Updating team name to empty string works', () async {
|
||||
await database.teamDao.addTeam(team: testTeam1);
|
||||
|
||||
await database.teamDao.updateTeamName(
|
||||
teamId: testTeam1.id,
|
||||
newName: '',
|
||||
);
|
||||
await database.teamDao.updateTeamName(teamId: testTeam1.id, newName: '');
|
||||
|
||||
final updatedTeam = await database.teamDao.getTeamById(
|
||||
teamId: testTeam1.id,
|
||||
@@ -350,9 +349,7 @@ void main() {
|
||||
await database.matchDao.addMatch(match: match2);
|
||||
|
||||
// Add teams to database
|
||||
await database.teamDao.addTeamsAsList(
|
||||
teams: [testTeam1, testTeam3],
|
||||
);
|
||||
await database.teamDao.addTeamsAsList(teams: [testTeam1, testTeam3]);
|
||||
|
||||
// Associate players with teams through match1
|
||||
// testTeam1: player1, player2
|
||||
@@ -420,10 +417,11 @@ void main() {
|
||||
final allTeams = await database.teamDao.getAllTeams();
|
||||
|
||||
expect(allTeams.length, 3);
|
||||
expect(
|
||||
allTeams.map((t) => t.id).toSet(),
|
||||
{testTeam1.id, testTeam2.id, testTeam3.id},
|
||||
);
|
||||
expect(allTeams.map((t) => t.id).toSet(), {
|
||||
testTeam1.id,
|
||||
testTeam2.id,
|
||||
testTeam3.id,
|
||||
});
|
||||
});
|
||||
|
||||
// Verifies that teamExists returns false for deleted teams.
|
||||
@@ -462,9 +460,7 @@ void main() {
|
||||
|
||||
// Verifies that addTeam after deleteAllTeams works correctly.
|
||||
test('Adding team after deleteAllTeams works correctly', () async {
|
||||
await database.teamDao.addTeamsAsList(
|
||||
teams: [testTeam1, testTeam2],
|
||||
);
|
||||
await database.teamDao.addTeamsAsList(teams: [testTeam1, testTeam2]);
|
||||
expect(await database.teamDao.getTeamCount(), 2);
|
||||
|
||||
await database.teamDao.deleteAllTeams();
|
||||
@@ -524,4 +520,4 @@ void main() {
|
||||
expect(fetchedTeam.createdAt, testTeam1.createdAt);
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@ import 'package:drift/native.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:tallee/core/enums.dart';
|
||||
import 'package:tallee/data/db/database.dart';
|
||||
import 'package:tallee/data/dto/game.dart';
|
||||
import 'package:tallee/data/models/game.dart';
|
||||
|
||||
void main() {
|
||||
late AppDatabase database;
|
||||
@@ -54,7 +54,6 @@ void main() {
|
||||
});
|
||||
|
||||
group('Game Tests', () {
|
||||
|
||||
// Verifies that getAllGames returns an empty list when the database has no games.
|
||||
test('getAllGames returns empty list when no games exist', () async {
|
||||
final allGames = await database.gameDao.getAllGames();
|
||||
@@ -106,7 +105,7 @@ void main() {
|
||||
// Verifies that getGameById throws a StateError when the game doesn't exist.
|
||||
test('getGameById throws exception for non-existent game', () async {
|
||||
expect(
|
||||
() => database.gameDao.getGameById(gameId: 'non-existent-id'),
|
||||
() => database.gameDao.getGameById(gameId: 'non-existent-id'),
|
||||
throwsA(isA<StateError>()),
|
||||
);
|
||||
});
|
||||
@@ -134,7 +133,13 @@ void main() {
|
||||
|
||||
// Verifies that a game with empty optional fields can be added and retrieved.
|
||||
test('addGame handles game with null optional fields', () async {
|
||||
final gameWithNulls = Game(name: 'Simple Game', ruleset: Ruleset.lowestScore, description: 'A simple game', color: GameColor.green, icon: '');
|
||||
final gameWithNulls = Game(
|
||||
name: 'Simple Game',
|
||||
ruleset: Ruleset.lowestScore,
|
||||
description: 'A simple game',
|
||||
color: GameColor.green,
|
||||
icon: '',
|
||||
);
|
||||
final result = await database.gameDao.addGame(game: gameWithNulls);
|
||||
expect(result, true);
|
||||
|
||||
@@ -419,9 +424,7 @@ void main() {
|
||||
|
||||
// Verifies that getGameCount updates correctly after deleting a game.
|
||||
test('getGameCount updates correctly after deletion', () async {
|
||||
await database.gameDao.addGamesAsList(
|
||||
games: [testGame1, testGame2],
|
||||
);
|
||||
await database.gameDao.addGamesAsList(games: [testGame1, testGame2]);
|
||||
|
||||
final countBefore = await database.gameDao.getGameCount();
|
||||
expect(countBefore, 2);
|
||||
|
||||
@@ -3,7 +3,7 @@ import 'package:drift/drift.dart' hide isNull;
|
||||
import 'package:drift/native.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:tallee/data/db/database.dart';
|
||||
import 'package:tallee/data/dto/player.dart';
|
||||
import 'package:tallee/data/models/player.dart';
|
||||
|
||||
void main() {
|
||||
late AppDatabase database;
|
||||
@@ -35,7 +35,6 @@ void main() {
|
||||
});
|
||||
|
||||
group('Player Tests', () {
|
||||
|
||||
// Verifies that players can be added and retrieved with all fields intact.
|
||||
test('Adding and fetching single player works correctly', () async {
|
||||
await database.playerDao.addPlayer(player: testPlayer1);
|
||||
@@ -264,16 +263,22 @@ void main() {
|
||||
});
|
||||
|
||||
// Verifies that a player with special characters in name is stored correctly.
|
||||
test('Player with special characters in name is stored correctly', () async {
|
||||
final specialPlayer = Player(name: 'Test!@#\$%^&*()_+-=[]{}|;\':",.<>?/`~', description: '');
|
||||
test(
|
||||
'Player with special characters in name is stored correctly',
|
||||
() async {
|
||||
final specialPlayer = Player(
|
||||
name: 'Test!@#\$%^&*()_+-=[]{}|;\':",.<>?/`~',
|
||||
description: '',
|
||||
);
|
||||
|
||||
await database.playerDao.addPlayer(player: specialPlayer);
|
||||
await database.playerDao.addPlayer(player: specialPlayer);
|
||||
|
||||
final fetchedPlayer = await database.playerDao.getPlayerById(
|
||||
playerId: specialPlayer.id,
|
||||
);
|
||||
expect(fetchedPlayer.name, specialPlayer.name);
|
||||
});
|
||||
final fetchedPlayer = await database.playerDao.getPlayerById(
|
||||
playerId: specialPlayer.id,
|
||||
);
|
||||
expect(fetchedPlayer.name, specialPlayer.name);
|
||||
},
|
||||
);
|
||||
|
||||
// Verifies that a player with description is stored correctly.
|
||||
test('Player with description is stored correctly', () async {
|
||||
@@ -293,7 +298,10 @@ void main() {
|
||||
|
||||
// Verifies that a player with null description is stored correctly.
|
||||
test('Player with null description is stored correctly', () async {
|
||||
final playerWithoutDescription = Player(name: 'No Description Player', description: '');
|
||||
final playerWithoutDescription = Player(
|
||||
name: 'No Description Player',
|
||||
description: '',
|
||||
);
|
||||
|
||||
await database.playerDao.addPlayer(player: playerWithoutDescription);
|
||||
|
||||
|
||||
@@ -3,8 +3,8 @@ import 'package:drift/drift.dart';
|
||||
import 'package:drift/native.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:tallee/data/db/database.dart';
|
||||
import 'package:tallee/data/dto/group.dart';
|
||||
import 'package:tallee/data/dto/player.dart';
|
||||
import 'package:tallee/data/models/group.dart';
|
||||
import 'package:tallee/data/models/player.dart';
|
||||
|
||||
void main() {
|
||||
late AppDatabase database;
|
||||
@@ -42,7 +42,6 @@ void main() {
|
||||
});
|
||||
|
||||
group('Player-Group Tests', () {
|
||||
|
||||
// Verifies that a player can be added to an existing group and isPlayerInGroup returns true.
|
||||
test('Adding a player to a group works correctly', () async {
|
||||
await database.groupDao.addGroup(group: testGroup);
|
||||
@@ -127,67 +126,83 @@ void main() {
|
||||
});
|
||||
|
||||
// Verifies that addPlayerToGroup returns false when player already in group.
|
||||
test('addPlayerToGroup returns false when player already in group', () async {
|
||||
await database.groupDao.addGroup(group: testGroup);
|
||||
test(
|
||||
'addPlayerToGroup returns false when player already in group',
|
||||
() async {
|
||||
await database.groupDao.addGroup(group: testGroup);
|
||||
|
||||
// testPlayer1 is already in testGroup via group creation
|
||||
final result = await database.playerGroupDao.addPlayerToGroup(
|
||||
player: testPlayer1,
|
||||
groupId: testGroup.id,
|
||||
);
|
||||
// testPlayer1 is already in testGroup via group creation
|
||||
final result = await database.playerGroupDao.addPlayerToGroup(
|
||||
player: testPlayer1,
|
||||
groupId: testGroup.id,
|
||||
);
|
||||
|
||||
expect(result, false);
|
||||
});
|
||||
expect(result, false);
|
||||
},
|
||||
);
|
||||
|
||||
// Verifies that addPlayerToGroup adds player to player table if not exists.
|
||||
test('addPlayerToGroup adds player to player table if not exists', () async {
|
||||
await database.groupDao.addGroup(group: testGroup);
|
||||
test(
|
||||
'addPlayerToGroup adds player to player table if not exists',
|
||||
() async {
|
||||
await database.groupDao.addGroup(group: testGroup);
|
||||
|
||||
// testPlayer4 is not in the database yet
|
||||
var playerExists = await database.playerDao.playerExists(
|
||||
playerId: testPlayer4.id,
|
||||
);
|
||||
expect(playerExists, false);
|
||||
// testPlayer4 is not in the database yet
|
||||
var playerExists = await database.playerDao.playerExists(
|
||||
playerId: testPlayer4.id,
|
||||
);
|
||||
expect(playerExists, false);
|
||||
|
||||
await database.playerGroupDao.addPlayerToGroup(
|
||||
player: testPlayer4,
|
||||
groupId: testGroup.id,
|
||||
);
|
||||
await database.playerGroupDao.addPlayerToGroup(
|
||||
player: testPlayer4,
|
||||
groupId: testGroup.id,
|
||||
);
|
||||
|
||||
// Now player should exist in player table
|
||||
playerExists = await database.playerDao.playerExists(
|
||||
playerId: testPlayer4.id,
|
||||
);
|
||||
expect(playerExists, true);
|
||||
});
|
||||
// Now player should exist in player table
|
||||
playerExists = await database.playerDao.playerExists(
|
||||
playerId: testPlayer4.id,
|
||||
);
|
||||
expect(playerExists, true);
|
||||
},
|
||||
);
|
||||
|
||||
// Verifies that removePlayerFromGroup returns false for non-existent player.
|
||||
test('removePlayerFromGroup returns false for non-existent player', () async {
|
||||
await database.groupDao.addGroup(group: testGroup);
|
||||
test(
|
||||
'removePlayerFromGroup returns false for non-existent player',
|
||||
() async {
|
||||
await database.groupDao.addGroup(group: testGroup);
|
||||
|
||||
final result = await database.playerGroupDao.removePlayerFromGroup(
|
||||
playerId: 'non-existent-player-id',
|
||||
groupId: testGroup.id,
|
||||
);
|
||||
final result = await database.playerGroupDao.removePlayerFromGroup(
|
||||
playerId: 'non-existent-player-id',
|
||||
groupId: testGroup.id,
|
||||
);
|
||||
|
||||
expect(result, false);
|
||||
});
|
||||
expect(result, false);
|
||||
},
|
||||
);
|
||||
|
||||
// Verifies that removePlayerFromGroup returns false for non-existent group.
|
||||
test('removePlayerFromGroup returns false for non-existent group', () async {
|
||||
await database.playerDao.addPlayer(player: testPlayer1);
|
||||
test(
|
||||
'removePlayerFromGroup returns false for non-existent group',
|
||||
() async {
|
||||
await database.playerDao.addPlayer(player: testPlayer1);
|
||||
|
||||
final result = await database.playerGroupDao.removePlayerFromGroup(
|
||||
playerId: testPlayer1.id,
|
||||
groupId: 'non-existent-group-id',
|
||||
);
|
||||
final result = await database.playerGroupDao.removePlayerFromGroup(
|
||||
playerId: testPlayer1.id,
|
||||
groupId: 'non-existent-group-id',
|
||||
);
|
||||
|
||||
expect(result, false);
|
||||
});
|
||||
expect(result, false);
|
||||
},
|
||||
);
|
||||
|
||||
// Verifies that getPlayersOfGroup returns empty list for group with no members.
|
||||
test('getPlayersOfGroup returns empty list for empty group', () async {
|
||||
final emptyGroup = Group(name: 'Empty Group', description: '', members: []);
|
||||
final emptyGroup = Group(
|
||||
name: 'Empty Group',
|
||||
description: '',
|
||||
members: [],
|
||||
);
|
||||
await database.groupDao.addGroup(group: emptyGroup);
|
||||
|
||||
final players = await database.playerGroupDao.getPlayersOfGroup(
|
||||
@@ -198,13 +213,16 @@ void main() {
|
||||
});
|
||||
|
||||
// Verifies that getPlayersOfGroup returns empty list for non-existent group.
|
||||
test('getPlayersOfGroup returns empty list for non-existent group', () async {
|
||||
final players = await database.playerGroupDao.getPlayersOfGroup(
|
||||
groupId: 'non-existent-group-id',
|
||||
);
|
||||
test(
|
||||
'getPlayersOfGroup returns empty list for non-existent group',
|
||||
() async {
|
||||
final players = await database.playerGroupDao.getPlayersOfGroup(
|
||||
groupId: 'non-existent-group-id',
|
||||
);
|
||||
|
||||
expect(players, isEmpty);
|
||||
});
|
||||
expect(players, isEmpty);
|
||||
},
|
||||
);
|
||||
|
||||
// Verifies that removing all players from a group leaves the group empty.
|
||||
test('Removing all players from a group leaves group empty', () async {
|
||||
@@ -231,7 +249,11 @@ void main() {
|
||||
|
||||
// Verifies that a player can be in multiple groups.
|
||||
test('Player can be in multiple groups', () async {
|
||||
final secondGroup = Group(name: 'Second Group', description: '', members: []);
|
||||
final secondGroup = Group(
|
||||
name: 'Second Group',
|
||||
description: '',
|
||||
members: [],
|
||||
);
|
||||
await database.groupDao.addGroup(group: testGroup);
|
||||
await database.groupDao.addGroup(group: secondGroup);
|
||||
|
||||
@@ -255,29 +277,36 @@ void main() {
|
||||
});
|
||||
|
||||
// Verifies that removing player from one group doesn't affect other groups.
|
||||
test('Removing player from one group does not affect other groups', () async {
|
||||
final secondGroup = Group(name: 'Second Group', description: '', members: [testPlayer1]);
|
||||
await database.groupDao.addGroup(group: testGroup);
|
||||
await database.groupDao.addGroup(group: secondGroup);
|
||||
test(
|
||||
'Removing player from one group does not affect other groups',
|
||||
() async {
|
||||
final secondGroup = Group(
|
||||
name: 'Second Group',
|
||||
description: '',
|
||||
members: [testPlayer1],
|
||||
);
|
||||
await database.groupDao.addGroup(group: testGroup);
|
||||
await database.groupDao.addGroup(group: secondGroup);
|
||||
|
||||
// Remove testPlayer1 from testGroup
|
||||
await database.playerGroupDao.removePlayerFromGroup(
|
||||
playerId: testPlayer1.id,
|
||||
groupId: testGroup.id,
|
||||
);
|
||||
// Remove testPlayer1 from testGroup
|
||||
await database.playerGroupDao.removePlayerFromGroup(
|
||||
playerId: testPlayer1.id,
|
||||
groupId: testGroup.id,
|
||||
);
|
||||
|
||||
final inFirstGroup = await database.playerGroupDao.isPlayerInGroup(
|
||||
playerId: testPlayer1.id,
|
||||
groupId: testGroup.id,
|
||||
);
|
||||
final inSecondGroup = await database.playerGroupDao.isPlayerInGroup(
|
||||
playerId: testPlayer1.id,
|
||||
groupId: secondGroup.id,
|
||||
);
|
||||
final inFirstGroup = await database.playerGroupDao.isPlayerInGroup(
|
||||
playerId: testPlayer1.id,
|
||||
groupId: testGroup.id,
|
||||
);
|
||||
final inSecondGroup = await database.playerGroupDao.isPlayerInGroup(
|
||||
playerId: testPlayer1.id,
|
||||
groupId: secondGroup.id,
|
||||
);
|
||||
|
||||
expect(inFirstGroup, false);
|
||||
expect(inSecondGroup, true);
|
||||
});
|
||||
expect(inFirstGroup, false);
|
||||
expect(inSecondGroup, true);
|
||||
},
|
||||
);
|
||||
|
||||
// Verifies that addPlayerToGroup returns true on successful addition.
|
||||
test('addPlayerToGroup returns true on successful addition', () async {
|
||||
@@ -293,21 +322,26 @@ void main() {
|
||||
});
|
||||
|
||||
// Verifies that removing the same player twice returns false on second attempt.
|
||||
test('Removing same player twice returns false on second attempt', () async {
|
||||
await database.groupDao.addGroup(group: testGroup);
|
||||
test(
|
||||
'Removing same player twice returns false on second attempt',
|
||||
() async {
|
||||
await database.groupDao.addGroup(group: testGroup);
|
||||
|
||||
final firstRemoval = await database.playerGroupDao.removePlayerFromGroup(
|
||||
playerId: testPlayer1.id,
|
||||
groupId: testGroup.id,
|
||||
);
|
||||
expect(firstRemoval, true);
|
||||
final firstRemoval = await database.playerGroupDao
|
||||
.removePlayerFromGroup(
|
||||
playerId: testPlayer1.id,
|
||||
groupId: testGroup.id,
|
||||
);
|
||||
expect(firstRemoval, true);
|
||||
|
||||
final secondRemoval = await database.playerGroupDao.removePlayerFromGroup(
|
||||
playerId: testPlayer1.id,
|
||||
groupId: testGroup.id,
|
||||
);
|
||||
expect(secondRemoval, false);
|
||||
});
|
||||
final secondRemoval = await database.playerGroupDao
|
||||
.removePlayerFromGroup(
|
||||
playerId: testPlayer1.id,
|
||||
groupId: testGroup.id,
|
||||
);
|
||||
expect(secondRemoval, false);
|
||||
},
|
||||
);
|
||||
|
||||
// Verifies that replaceGroupPlayers removes all existing players and replaces with new list.
|
||||
test('replaceGroupPlayers replaces all group members correctly', () async {
|
||||
|
||||
@@ -4,11 +4,11 @@ import 'package:drift/native.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:tallee/core/enums.dart';
|
||||
import 'package:tallee/data/db/database.dart';
|
||||
import 'package:tallee/data/dto/game.dart';
|
||||
import 'package:tallee/data/dto/group.dart';
|
||||
import 'package:tallee/data/dto/match.dart';
|
||||
import 'package:tallee/data/dto/player.dart';
|
||||
import 'package:tallee/data/dto/team.dart';
|
||||
import 'package:tallee/data/models/game.dart';
|
||||
import 'package:tallee/data/models/group.dart';
|
||||
import 'package:tallee/data/models/match.dart';
|
||||
import 'package:tallee/data/models/player.dart';
|
||||
import 'package:tallee/data/models/team.dart';
|
||||
|
||||
void main() {
|
||||
late AppDatabase database;
|
||||
@@ -48,7 +48,13 @@ void main() {
|
||||
description: '',
|
||||
members: [testPlayer1, testPlayer2, testPlayer3],
|
||||
);
|
||||
testGame = Game(name: 'Test Game', ruleset: Ruleset.singleWinner, description: 'A test game', color: GameColor.blue, icon: '');
|
||||
testGame = Game(
|
||||
name: 'Test Game',
|
||||
ruleset: Ruleset.singleWinner,
|
||||
description: 'A test game',
|
||||
color: GameColor.blue,
|
||||
icon: '',
|
||||
);
|
||||
testMatchOnlyGroup = Match(
|
||||
name: 'Test Match with Group',
|
||||
game: testGame,
|
||||
@@ -61,14 +67,8 @@ void main() {
|
||||
players: [testPlayer4, testPlayer5, testPlayer6],
|
||||
notes: '',
|
||||
);
|
||||
testTeam1 = Team(
|
||||
name: 'Team Alpha',
|
||||
members: [testPlayer1, testPlayer2],
|
||||
);
|
||||
testTeam2 = Team(
|
||||
name: 'Team Beta',
|
||||
members: [testPlayer3, testPlayer4],
|
||||
);
|
||||
testTeam1 = Team(name: 'Team Alpha', members: [testPlayer1, testPlayer2]);
|
||||
testTeam2 = Team(name: 'Team Beta', members: [testPlayer3, testPlayer4]);
|
||||
});
|
||||
await database.playerDao.addPlayersAsList(
|
||||
players: [
|
||||
@@ -88,7 +88,6 @@ void main() {
|
||||
});
|
||||
|
||||
group('Player-Match Tests', () {
|
||||
|
||||
// Verifies that matchHasPlayers returns false initially and true after adding a player.
|
||||
test('Match has player works correctly', () async {
|
||||
await database.matchDao.addMatch(match: testMatchOnlyGroup);
|
||||
@@ -153,26 +152,23 @@ void main() {
|
||||
);
|
||||
expect(result.players.length, testMatchOnlyPlayers.players.length - 1);
|
||||
|
||||
final playerExists = result.players.any(
|
||||
(p) => p.id == playerToRemove.id,
|
||||
);
|
||||
final playerExists = result.players.any((p) => p.id == playerToRemove.id);
|
||||
expect(playerExists, false);
|
||||
});
|
||||
|
||||
// Verifies that getPlayersOfMatch returns all players of a match with correct data.
|
||||
test('Retrieving players of a match works correctly', () async {
|
||||
await database.matchDao.addMatch(match: testMatchOnlyPlayers);
|
||||
final players = await database.playerMatchDao.getPlayersOfMatch(
|
||||
matchId: testMatchOnlyPlayers.id,
|
||||
) ?? [];
|
||||
final players =
|
||||
await database.playerMatchDao.getPlayersOfMatch(
|
||||
matchId: testMatchOnlyPlayers.id,
|
||||
) ??
|
||||
[];
|
||||
|
||||
for (int i = 0; i < players.length; i++) {
|
||||
expect(players[i].id, testMatchOnlyPlayers.players[i].id);
|
||||
expect(players[i].name, testMatchOnlyPlayers.players[i].name);
|
||||
expect(
|
||||
players[i].createdAt,
|
||||
testMatchOnlyPlayers.players[i].createdAt,
|
||||
);
|
||||
expect(players[i].createdAt, testMatchOnlyPlayers.players[i].createdAt);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -223,10 +219,20 @@ void main() {
|
||||
// Verifies that the same player can be added to multiple different matches.
|
||||
test(
|
||||
'Adding the same player to separate matches works correctly',
|
||||
() async {
|
||||
() async {
|
||||
final playersList = [testPlayer1, testPlayer2, testPlayer3];
|
||||
final match1 = Match(name: 'Match 1', game: testGame, players: playersList, notes: '');
|
||||
final match2 = Match(name: 'Match 2', game: testGame, players: playersList, notes: '');
|
||||
final match1 = Match(
|
||||
name: 'Match 1',
|
||||
game: testGame,
|
||||
players: playersList,
|
||||
notes: '',
|
||||
);
|
||||
final match2 = Match(
|
||||
name: 'Match 2',
|
||||
game: testGame,
|
||||
players: playersList,
|
||||
notes: '',
|
||||
);
|
||||
|
||||
await Future.wait([
|
||||
database.matchDao.addMatch(match: match1),
|
||||
@@ -299,16 +305,19 @@ void main() {
|
||||
});
|
||||
|
||||
// Verifies that getPlayerScore returns null for non-existent player-match combination.
|
||||
test('getPlayerScore returns null for non-existent player in match', () async {
|
||||
await database.matchDao.addMatch(match: testMatchOnlyGroup);
|
||||
test(
|
||||
'getPlayerScore returns null for non-existent player in match',
|
||||
() async {
|
||||
await database.matchDao.addMatch(match: testMatchOnlyGroup);
|
||||
|
||||
final score = await database.playerMatchDao.getPlayerScore(
|
||||
matchId: testMatchOnlyGroup.id,
|
||||
playerId: 'non-existent-player-id',
|
||||
);
|
||||
final score = await database.playerMatchDao.getPlayerScore(
|
||||
matchId: testMatchOnlyGroup.id,
|
||||
playerId: 'non-existent-player-id',
|
||||
);
|
||||
|
||||
expect(score, isNull);
|
||||
});
|
||||
expect(score, isNull);
|
||||
},
|
||||
);
|
||||
|
||||
// Verifies that updatePlayerScore updates the score correctly.
|
||||
test('updatePlayerScore updates score correctly', () async {
|
||||
@@ -331,17 +340,20 @@ void main() {
|
||||
});
|
||||
|
||||
// Verifies that updatePlayerScore returns false for non-existent player-match.
|
||||
test('updatePlayerScore returns false for non-existent player-match', () async {
|
||||
await database.matchDao.addMatch(match: testMatchOnlyGroup);
|
||||
test(
|
||||
'updatePlayerScore returns false for non-existent player-match',
|
||||
() async {
|
||||
await database.matchDao.addMatch(match: testMatchOnlyGroup);
|
||||
|
||||
final updated = await database.playerMatchDao.updatePlayerScore(
|
||||
matchId: testMatchOnlyGroup.id,
|
||||
playerId: 'non-existent-player-id',
|
||||
newScore: 50,
|
||||
);
|
||||
final updated = await database.playerMatchDao.updatePlayerScore(
|
||||
matchId: testMatchOnlyGroup.id,
|
||||
playerId: 'non-existent-player-id',
|
||||
newScore: 50,
|
||||
);
|
||||
|
||||
expect(updated, false);
|
||||
});
|
||||
expect(updated, false);
|
||||
},
|
||||
);
|
||||
|
||||
// Verifies that adding a player with teamId works correctly.
|
||||
test('Adding player with teamId works correctly', () async {
|
||||
@@ -431,17 +443,20 @@ void main() {
|
||||
});
|
||||
|
||||
// Verifies that updatePlayerTeam returns false for non-existent player-match.
|
||||
test('updatePlayerTeam returns false for non-existent player-match', () async {
|
||||
await database.matchDao.addMatch(match: testMatchOnlyGroup);
|
||||
test(
|
||||
'updatePlayerTeam returns false for non-existent player-match',
|
||||
() async {
|
||||
await database.matchDao.addMatch(match: testMatchOnlyGroup);
|
||||
|
||||
final updated = await database.playerMatchDao.updatePlayerTeam(
|
||||
matchId: testMatchOnlyGroup.id,
|
||||
playerId: 'non-existent-player-id',
|
||||
teamId: testTeam1.id,
|
||||
);
|
||||
final updated = await database.playerMatchDao.updatePlayerTeam(
|
||||
matchId: testMatchOnlyGroup.id,
|
||||
playerId: 'non-existent-player-id',
|
||||
teamId: testTeam1.id,
|
||||
);
|
||||
|
||||
expect(updated, false);
|
||||
});
|
||||
expect(updated, false);
|
||||
},
|
||||
);
|
||||
|
||||
// Verifies that getPlayersInTeam returns empty list for non-existent team.
|
||||
test('getPlayersInTeam returns empty list for non-existent team', () async {
|
||||
@@ -483,16 +498,19 @@ void main() {
|
||||
});
|
||||
|
||||
// Verifies that removePlayerFromMatch returns false for non-existent player.
|
||||
test('removePlayerFromMatch returns false for non-existent player', () async {
|
||||
await database.matchDao.addMatch(match: testMatchOnlyPlayers);
|
||||
test(
|
||||
'removePlayerFromMatch returns false for non-existent player',
|
||||
() async {
|
||||
await database.matchDao.addMatch(match: testMatchOnlyPlayers);
|
||||
|
||||
final removed = await database.playerMatchDao.removePlayerFromMatch(
|
||||
playerId: 'non-existent-player-id',
|
||||
matchId: testMatchOnlyPlayers.id,
|
||||
);
|
||||
final removed = await database.playerMatchDao.removePlayerFromMatch(
|
||||
playerId: 'non-existent-player-id',
|
||||
matchId: testMatchOnlyPlayers.id,
|
||||
);
|
||||
|
||||
expect(removed, false);
|
||||
});
|
||||
expect(removed, false);
|
||||
},
|
||||
);
|
||||
|
||||
// Verifies that adding the same player twice to the same match is ignored.
|
||||
test('Adding same player twice to same match is ignored', () async {
|
||||
@@ -528,27 +546,30 @@ void main() {
|
||||
});
|
||||
|
||||
// Verifies that updatePlayersFromMatch with empty list removes all players.
|
||||
test('updatePlayersFromMatch with empty list removes all players', () async {
|
||||
await database.matchDao.addMatch(match: testMatchOnlyPlayers);
|
||||
test(
|
||||
'updatePlayersFromMatch with empty list removes all players',
|
||||
() async {
|
||||
await database.matchDao.addMatch(match: testMatchOnlyPlayers);
|
||||
|
||||
// Verify players exist initially
|
||||
var players = await database.playerMatchDao.getPlayersOfMatch(
|
||||
matchId: testMatchOnlyPlayers.id,
|
||||
);
|
||||
expect(players?.length, 3);
|
||||
// Verify players exist initially
|
||||
var players = await database.playerMatchDao.getPlayersOfMatch(
|
||||
matchId: testMatchOnlyPlayers.id,
|
||||
);
|
||||
expect(players?.length, 3);
|
||||
|
||||
// Update with empty list
|
||||
await database.playerMatchDao.updatePlayersFromMatch(
|
||||
matchId: testMatchOnlyPlayers.id,
|
||||
newPlayer: [],
|
||||
);
|
||||
// Update with empty list
|
||||
await database.playerMatchDao.updatePlayersFromMatch(
|
||||
matchId: testMatchOnlyPlayers.id,
|
||||
newPlayer: [],
|
||||
);
|
||||
|
||||
// Verify all players are removed
|
||||
players = await database.playerMatchDao.getPlayersOfMatch(
|
||||
matchId: testMatchOnlyPlayers.id,
|
||||
);
|
||||
expect(players, isNull);
|
||||
});
|
||||
// Verify all players are removed
|
||||
players = await database.playerMatchDao.getPlayersOfMatch(
|
||||
matchId: testMatchOnlyPlayers.id,
|
||||
);
|
||||
expect(players, isNull);
|
||||
},
|
||||
);
|
||||
|
||||
// Verifies that updatePlayersFromMatch with same players makes no changes.
|
||||
test('updatePlayersFromMatch with same players makes no changes', () async {
|
||||
@@ -702,16 +723,19 @@ void main() {
|
||||
});
|
||||
|
||||
// Verifies that getPlayersInTeam returns empty list for non-existent match.
|
||||
test('getPlayersInTeam returns empty list for non-existent match', () async {
|
||||
await database.teamDao.addTeam(team: testTeam1);
|
||||
test(
|
||||
'getPlayersInTeam returns empty list for non-existent match',
|
||||
() async {
|
||||
await database.teamDao.addTeam(team: testTeam1);
|
||||
|
||||
final players = await database.playerMatchDao.getPlayersInTeam(
|
||||
matchId: 'non-existent-match-id',
|
||||
teamId: testTeam1.id,
|
||||
);
|
||||
final players = await database.playerMatchDao.getPlayersInTeam(
|
||||
matchId: 'non-existent-match-id',
|
||||
teamId: testTeam1.id,
|
||||
);
|
||||
|
||||
expect(players.isEmpty, true);
|
||||
});
|
||||
expect(players.isEmpty, true);
|
||||
},
|
||||
);
|
||||
|
||||
// Verifies that players in different teams within the same match are returned correctly.
|
||||
test('Players in different teams within same match are separate', () async {
|
||||
@@ -759,8 +783,18 @@ void main() {
|
||||
// Verifies that removePlayerFromMatch does not affect other matches.
|
||||
test('removePlayerFromMatch does not affect other matches', () async {
|
||||
final playersList = [testPlayer1, testPlayer2];
|
||||
final match1 = Match(name: 'Match 1', game: testGame, players: playersList, notes: '');
|
||||
final match2 = Match(name: 'Match 2', game: testGame, players: playersList, notes: '');
|
||||
final match1 = Match(
|
||||
name: 'Match 1',
|
||||
game: testGame,
|
||||
players: playersList,
|
||||
notes: '',
|
||||
);
|
||||
final match2 = Match(
|
||||
name: 'Match 2',
|
||||
game: testGame,
|
||||
players: playersList,
|
||||
notes: '',
|
||||
);
|
||||
|
||||
await Future.wait([
|
||||
database.matchDao.addMatch(match: match1),
|
||||
@@ -792,8 +826,18 @@ void main() {
|
||||
// Verifies that updating scores for players in different matches are independent.
|
||||
test('Player scores are independent across matches', () async {
|
||||
final playersList = [testPlayer1];
|
||||
final match1 = Match(name: 'Match 1', game: testGame, players: playersList, notes: '');
|
||||
final match2 = Match(name: 'Match 2', game: testGame, players: playersList, notes: '');
|
||||
final match1 = Match(
|
||||
name: 'Match 1',
|
||||
game: testGame,
|
||||
players: playersList,
|
||||
notes: '',
|
||||
);
|
||||
final match2 = Match(
|
||||
name: 'Match 2',
|
||||
game: testGame,
|
||||
players: playersList,
|
||||
notes: '',
|
||||
);
|
||||
|
||||
await Future.wait([
|
||||
database.matchDao.addMatch(match: match1),
|
||||
@@ -829,16 +873,19 @@ void main() {
|
||||
});
|
||||
|
||||
// Verifies that updatePlayersFromMatch on non-existent match fails with constraint error.
|
||||
test('updatePlayersFromMatch on non-existent match fails with foreign key constraint', () async {
|
||||
// Should throw due to foreign key constraint - match doesn't exist
|
||||
await expectLater(
|
||||
database.playerMatchDao.updatePlayersFromMatch(
|
||||
matchId: 'non-existent-match-id',
|
||||
newPlayer: [testPlayer1, testPlayer2],
|
||||
),
|
||||
throwsA(anything),
|
||||
);
|
||||
});
|
||||
test(
|
||||
'updatePlayersFromMatch on non-existent match fails with foreign key constraint',
|
||||
() async {
|
||||
// Should throw due to foreign key constraint - match doesn't exist
|
||||
await expectLater(
|
||||
database.playerMatchDao.updatePlayersFromMatch(
|
||||
matchId: 'non-existent-match-id',
|
||||
newPlayer: [testPlayer1, testPlayer2],
|
||||
),
|
||||
throwsA(anything),
|
||||
);
|
||||
},
|
||||
);
|
||||
|
||||
// Verifies that a player can be in a match without being assigned to a team.
|
||||
test('Player can exist in match without team assignment', () async {
|
||||
|
||||
@@ -2,11 +2,11 @@ import 'package:clock/clock.dart';
|
||||
import 'package:drift/drift.dart' hide isNull, isNotNull;
|
||||
import 'package:drift/native.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:tallee/data/db/database.dart';
|
||||
import 'package:tallee/data/dto/game.dart';
|
||||
import 'package:tallee/data/dto/match.dart';
|
||||
import 'package:tallee/data/dto/player.dart';
|
||||
import 'package:tallee/core/enums.dart';
|
||||
import 'package:tallee/data/db/database.dart';
|
||||
import 'package:tallee/data/models/game.dart';
|
||||
import 'package:tallee/data/models/match.dart';
|
||||
import 'package:tallee/data/models/player.dart';
|
||||
|
||||
void main() {
|
||||
late AppDatabase database;
|
||||
@@ -32,7 +32,13 @@ void main() {
|
||||
testPlayer1 = Player(name: 'Alice', description: '');
|
||||
testPlayer2 = Player(name: 'Bob', description: '');
|
||||
testPlayer3 = Player(name: 'Charlie', description: '');
|
||||
testGame = Game(name: 'Test Game', ruleset: Ruleset.singleWinner, description: 'A test game', color: GameColor.blue, icon: '');
|
||||
testGame = Game(
|
||||
name: 'Test Game',
|
||||
ruleset: Ruleset.singleWinner,
|
||||
description: 'A test game',
|
||||
color: GameColor.blue,
|
||||
icon: '',
|
||||
);
|
||||
testMatch1 = Match(
|
||||
name: 'Test Match 1',
|
||||
game: testGame,
|
||||
@@ -60,7 +66,6 @@ void main() {
|
||||
});
|
||||
|
||||
group('Score Tests', () {
|
||||
|
||||
// Verifies that a score can be added and retrieved with all fields intact.
|
||||
test('Adding and fetching a score works correctly', () async {
|
||||
await database.scoreDao.addScore(
|
||||
@@ -431,13 +436,16 @@ void main() {
|
||||
});
|
||||
|
||||
// Verifies that getScoresForMatch returns empty list for match with no scores.
|
||||
test('Getting scores for match with no scores returns empty list', () async {
|
||||
final scores = await database.scoreDao.getScoresForMatch(
|
||||
matchId: testMatch1.id,
|
||||
);
|
||||
test(
|
||||
'Getting scores for match with no scores returns empty list',
|
||||
() async {
|
||||
final scores = await database.scoreDao.getScoresForMatch(
|
||||
matchId: testMatch1.id,
|
||||
);
|
||||
|
||||
expect(scores.isEmpty, true);
|
||||
});
|
||||
expect(scores.isEmpty, true);
|
||||
},
|
||||
);
|
||||
|
||||
// Verifies that getPlayerScoresInMatch returns empty list when player has no scores.
|
||||
test('Getting player scores with no scores returns empty list', () async {
|
||||
@@ -666,46 +674,58 @@ void main() {
|
||||
});
|
||||
|
||||
// Verifies that updating one player's score doesn't affect another player's score in same round.
|
||||
test('Updating one player score does not affect other players in same round', () async {
|
||||
await database.scoreDao.addScore(
|
||||
playerId: testPlayer1.id,
|
||||
matchId: testMatch1.id,
|
||||
roundNumber: 1,
|
||||
score: 10,
|
||||
change: 10,
|
||||
);
|
||||
await database.scoreDao.addScore(
|
||||
playerId: testPlayer2.id,
|
||||
matchId: testMatch1.id,
|
||||
roundNumber: 1,
|
||||
score: 20,
|
||||
change: 20,
|
||||
);
|
||||
await database.scoreDao.addScore(
|
||||
playerId: testPlayer3.id,
|
||||
matchId: testMatch1.id,
|
||||
roundNumber: 1,
|
||||
score: 30,
|
||||
change: 30,
|
||||
);
|
||||
test(
|
||||
'Updating one player score does not affect other players in same round',
|
||||
() async {
|
||||
await database.scoreDao.addScore(
|
||||
playerId: testPlayer1.id,
|
||||
matchId: testMatch1.id,
|
||||
roundNumber: 1,
|
||||
score: 10,
|
||||
change: 10,
|
||||
);
|
||||
await database.scoreDao.addScore(
|
||||
playerId: testPlayer2.id,
|
||||
matchId: testMatch1.id,
|
||||
roundNumber: 1,
|
||||
score: 20,
|
||||
change: 20,
|
||||
);
|
||||
await database.scoreDao.addScore(
|
||||
playerId: testPlayer3.id,
|
||||
matchId: testMatch1.id,
|
||||
roundNumber: 1,
|
||||
score: 30,
|
||||
change: 30,
|
||||
);
|
||||
|
||||
await database.scoreDao.updateScore(
|
||||
playerId: testPlayer2.id,
|
||||
matchId: testMatch1.id,
|
||||
roundNumber: 1,
|
||||
newScore: 99,
|
||||
newChange: 89,
|
||||
);
|
||||
await database.scoreDao.updateScore(
|
||||
playerId: testPlayer2.id,
|
||||
matchId: testMatch1.id,
|
||||
roundNumber: 1,
|
||||
newScore: 99,
|
||||
newChange: 89,
|
||||
);
|
||||
|
||||
final scores = await database.scoreDao.getScoresForMatch(
|
||||
matchId: testMatch1.id,
|
||||
);
|
||||
final scores = await database.scoreDao.getScoresForMatch(
|
||||
matchId: testMatch1.id,
|
||||
);
|
||||
|
||||
expect(scores.length, 3);
|
||||
expect(scores.where((s) => s.playerId == testPlayer1.id).first.score, 10);
|
||||
expect(scores.where((s) => s.playerId == testPlayer2.id).first.score, 99);
|
||||
expect(scores.where((s) => s.playerId == testPlayer3.id).first.score, 30);
|
||||
});
|
||||
expect(scores.length, 3);
|
||||
expect(
|
||||
scores.where((s) => s.playerId == testPlayer1.id).first.score,
|
||||
10,
|
||||
);
|
||||
expect(
|
||||
scores.where((s) => s.playerId == testPlayer2.id).first.score,
|
||||
99,
|
||||
);
|
||||
expect(
|
||||
scores.where((s) => s.playerId == testPlayer3.id).first.score,
|
||||
30,
|
||||
);
|
||||
},
|
||||
);
|
||||
|
||||
// Verifies that deleting a player's scores only affects that specific player.
|
||||
test('Deleting player scores only affects target player', () async {
|
||||
@@ -724,9 +744,7 @@ void main() {
|
||||
change: 20,
|
||||
);
|
||||
|
||||
await database.scoreDao.deleteScoresForPlayer(
|
||||
playerId: testPlayer1.id,
|
||||
);
|
||||
await database.scoreDao.deleteScoresForPlayer(playerId: testPlayer1.id);
|
||||
|
||||
final match1Scores = await database.scoreDao.getScoresForMatch(
|
||||
matchId: testMatch1.id,
|
||||
|
||||
Reference in New Issue
Block a user