async def test_when_channel_not_found(self, cog: ConfigCog, player: User): with mock_operations(config_action): config_action.safe_fetch_text_channel.return_value = None await self.run(cog.power, level=10) config_action.safe_update_embed.assert_not_called()
async def test_game( self, cog: EventsCog, message: discord.Message, add_user: Callable[..., User], ) -> None: player1 = add_user() player2 = add_user() users = [mock_discord_object(player1), mock_discord_object(player2)] with mock_operations(lfg_action, users=users): lfg_action.safe_followup_channel.return_value = message await self.run( cog.game, players=f"<@{player1.xid}><@{player2.xid}>", format=cast(int, GameFormat.LEGACY.value), ) game = DatabaseSession.query(Game).one() assert game.status == GameStatus.STARTED.value admin = DatabaseSession.query(User).get(self.interaction.user.id) assert admin is not None and admin.game_id is None players = DatabaseSession.query(User).filter(User.xid != self.interaction.user.id).all() assert len(players) == 2 for player in players: assert player.game_id == game.id
async def test_leave_when_not_in_game(self, cog: LeaveGameCog, user: User) -> None: with mock_operations(leave_action): await self.run(cog.leave_command) leave_action.safe_send_channel.assert_called_once_with( self.interaction, "You have been removed from any games your were signed up for.", ephemeral=True, )
async def test_leave_when_no_message(self, cog: LeaveGameCog, player: User) -> None: with mock_operations(leave_action): leave_action.safe_fetch_text_channel.return_value = self.channel leave_action.safe_get_partial_message.return_value = None await self.run(cog.leave_command) leave_action.safe_send_channel.assert_called_once_with( self.interaction, "You have been removed from any games your were signed up for.", ephemeral=True, )
async def test_game_with_one_player( self, cog: EventsCog, add_user: Callable[..., User], ) -> None: player = add_user() users = [mock_discord_object(player)] with mock_operations(lfg_action, users=users): await self.run( cog.game, players=f"<@{player.xid}>", format=cast(int, GameFormat.LEGACY.value), ) lfg_action.safe_followup_channel.assert_called_once_with( self.interaction, "You can't create a Legacy game with 1 players.", )
async def test_game_with_banned_player( self, cog: EventsCog, add_user: Callable[..., User], ) -> None: player = add_user() banned = add_user(banned=True) users = [mock_discord_object(player), mock_discord_object(banned)] with mock_operations(lfg_action, users=users): await self.run( cog.game, players=f"<@{player.xid}><@{banned.xid}>", format=cast(int, GameFormat.LEGACY.value), ) lfg_action.safe_followup_channel.assert_called_once_with( self.interaction, f"Some of the players you mentioned can not be added to a game: <@{banned.xid}>", )
async def test_happy_path(self, cog: ConfigCog, player: User): with mock_operations(config_action): config_action.safe_fetch_text_channel.return_value = self.interaction.channel config_action.safe_get_partial_message.return_value = self.interaction.message await self.run(cog.power, level=10) update_embed_call = config_action.safe_update_embed update_embed_call.assert_called_once() assert update_embed_call.call_args_list[0].kwargs["embed"].to_dict( ) == { "color": self.settings.EMBED_COLOR, "description": ("_A SpellTable link will be created when all players have joined._\n" "\n" f"{player.game.guild.motd}\n" "\n" f"{player.game.channel.motd}"), "fields": [ { "inline": False, "name": "Players", "value": f"<@{player.xid}> (power level: 10)", }, { "inline": True, "name": "Format", "value": "Commander" }, ], "footer": { "text": f"SpellBot Game ID: #SB{player.game.id}" }, "thumbnail": { "url": self.settings.THUMB_URL }, "title": "**Waiting for 3 more players to join...**", "type": "rich", }
async def test_leave(self, cog: LeaveGameCog, message: discord.Message, player: User) -> None: with mock_operations(leave_action): leave_action.safe_fetch_text_channel.return_value = self.interaction.channel leave_action.safe_get_partial_message.return_value = message await self.run(cog.leave_command) leave_action.safe_send_channel.assert_called_once_with( self.interaction, "You have been removed from any games your were signed up for.", ephemeral=True, ) leave_action.safe_update_embed.assert_called_once() safe_update_embed_call = leave_action.safe_update_embed.call_args_list[ 0] assert safe_update_embed_call.kwargs["embed"].to_dict() == { "color": self.settings.EMBED_COLOR, "description": ("_A SpellTable link will be created when all players have joined._\n" "\n" f"{self.guild.motd}\n\n{self.channel.motd}"), "fields": [{ "inline": True, "name": "Format", "value": "Commander" }], "footer": { "text": f"SpellBot Game ID: #SB{self.game.id}" }, "thumbnail": { "url": self.settings.THUMB_URL }, "title": "**Waiting for 4 more players to join...**", "type": "rich", }
async def test_lfg_fully_seated( self, cog: LookingForGameCog, add_channel: Callable[..., Channel], ): channel = add_channel(default_seats=2, xid=self.interaction.channel_id) game = self.factories.game.create( guild=self.guild, channel=channel, seats=2, message_xid=123, ) other_user = self.factories.user.create(xid=self.interaction.user.id + 1, game=game) other_player = mock_discord_object(other_user) with mock_operations(lfg_action, users=[other_player]): message = MagicMock(spec=discord.Message) message.id = game.message_xid lfg_action.safe_get_partial_message.return_value = message await self.run(cog.lfg) DatabaseSession.expire_all() game = DatabaseSession.query(Game).one() mock_call = lfg_action.safe_update_embed assert mock_call.call_args_list[0].kwargs["embed"].to_dict() == { "color": self.settings.EMBED_COLOR, "description": ("Please check your Direct Messages for your SpellTable link.\n\n" f"{self.guild.motd}\n\n{channel.motd}"), "fields": [ { "inline": False, "name": "Players", "value": f"<@{self.interaction.user.id}>, <@{other_player.id}>", }, { "inline": True, "name": "Format", "value": "Commander" }, { "inline": True, "name": "Started at", "value": f"<t:{game.started_at_timestamp}>", }, ], "footer": { "text": f"SpellBot Game ID: #SB{game.id}" }, "thumbnail": { "url": self.settings.THUMB_URL }, "title": "**Your game is ready!**", "type": "rich", }