tests: add test for bulk deletes

This commit is contained in:
Luna 2021-09-13 23:24:05 -03:00
parent 415f1fa3be
commit 8da480db88
2 changed files with 23 additions and 1 deletions

View File

@ -270,9 +270,11 @@ class WrappedMessage:
assert resp.status_code == 200 assert resp.status_code == 200
assert rjson["id"] == str(self.id) assert rjson["id"] == str(self.id)
async def refetch(self) -> dict: async def refetch(self) -> Optional["WrappedMessage"]:
async with self.test_cli.app.app_context(): async with self.test_cli.app.app_context():
message_data = await self.test_cli.app.storage.get_message(self.id) message_data = await self.test_cli.app.storage.get_message(self.id)
if message_data is None:
return None
return WrappedMessage.from_json(self.test_cli, message_data) return WrappedMessage.from_json(self.test_cli, message_data)
@classmethod @classmethod

View File

@ -122,3 +122,23 @@ async def test_channel_message_delete_different_author(test_cli_user):
headers={"authorization": user.token}, headers={"authorization": user.token},
) )
assert resp.status_code == 204 assert resp.status_code == 204
async def test_channel_message_bulk_delete(test_cli_user):
guild = await test_cli_user.create_guild()
channel = await test_cli_user.create_guild_channel(guild_id=guild.id)
messages = []
for _ in range(10):
messages.append(
await test_cli_user.create_message(guild_id=guild.id, channel_id=channel.id)
)
resp = await test_cli_user.post(
f"/api/v6/channels/{channel.id}/messages/bulk-delete",
json={"messages": [message.id for message in messages]},
)
assert resp.status_code == 204
# assert everyone cant be refetched
for message in messages:
assert (await message.refetch()) is None