mirror of https://gitlab.com/litecord/litecord.git
tests: more invite tests
This commit is contained in:
parent
2283030fc3
commit
d2c0b9ac61
|
|
@ -18,27 +18,30 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||
"""
|
||||
|
||||
import pytest
|
||||
from litecord.enums import MessageType
|
||||
|
||||
pytestmark = pytest.mark.asyncio
|
||||
|
||||
# todo: maybe add more tests lol
|
||||
# :)
|
||||
|
||||
|
||||
async def test_invite_join(test_cli_user):
|
||||
async def test_invite_create(test_cli_user):
|
||||
""" "Test the creation of an invite."""
|
||||
guild = await test_cli_user.create_guild()
|
||||
channel = guild.channels[0]
|
||||
|
||||
resp = await test_cli_user.patch(
|
||||
f"/api/v9/guilds/{guild.id}",
|
||||
json={
|
||||
"system_channel_id": channel["id"],
|
||||
},
|
||||
resp = await test_cli_user.post(
|
||||
f'/api/v9/channels/{channel["id"]}/invites', json={}
|
||||
)
|
||||
|
||||
assert resp.status_code == 200
|
||||
rjson = await resp.json
|
||||
assert rjson["system_channel_id"] == channel["id"]
|
||||
assert rjson["channel"]["id"] == channel["id"]
|
||||
assert rjson["guild"]["id"] == str(guild.id)
|
||||
|
||||
|
||||
async def test_invite_join(test_cli_user):
|
||||
""" "Test the ability to create & join an invite."""
|
||||
guild = await test_cli_user.create_guild()
|
||||
channel = guild.channels[0]
|
||||
|
||||
resp = await test_cli_user.post(
|
||||
f'/api/v9/channels/{channel["id"]}/invites', json={}
|
||||
|
|
@ -56,3 +59,50 @@ async def test_invite_join(test_cli_user):
|
|||
f"/api/v9/invites/{invite_code}", headers={"Authorization": user.token}
|
||||
)
|
||||
assert resp.status_code == 200
|
||||
|
||||
|
||||
async def test_invite_system_message(test_cli_user):
|
||||
"""Test creating & joining an invite, and
|
||||
the welcome message that appears when joining
|
||||
a guild."""
|
||||
guild = await test_cli_user.create_guild()
|
||||
channel = guild.channels[0]
|
||||
channel_id = channel["id"]
|
||||
|
||||
# set the system message channel
|
||||
resp = await test_cli_user.patch(
|
||||
f"/api/v9/guilds/{guild.id}",
|
||||
json={
|
||||
"system_channel_id": channel_id,
|
||||
},
|
||||
)
|
||||
assert resp.status_code == 200
|
||||
rjson = await resp.json
|
||||
|
||||
assert rjson["system_channel_id"] == channel_id
|
||||
|
||||
resp = await test_cli_user.post(f"/api/v9/channels/{channel_id}/invites", json={})
|
||||
assert resp.status_code == 200
|
||||
rjson = await resp.json
|
||||
|
||||
invite_code = rjson["code"]
|
||||
assert rjson["channel"]["id"] == channel_id
|
||||
assert rjson["guild"]["id"] == str(guild.id)
|
||||
|
||||
user = await test_cli_user.create_user()
|
||||
|
||||
resp = await test_cli_user.post(
|
||||
f"/api/v9/invites/{invite_code}", headers={"Authorization": user.token}
|
||||
)
|
||||
assert resp.status_code == 200
|
||||
|
||||
resp = await test_cli_user.get(f"/api/v9/channels/{channel_id}/messages")
|
||||
assert resp.status_code == 200
|
||||
rjson = await resp.json
|
||||
|
||||
system_message = rjson[0]
|
||||
assert system_message["channel_id"] == channel_id
|
||||
assert system_message["guild_id"] == str(guild.id)
|
||||
assert system_message["type"] == MessageType.GUILD_MEMBER_JOIN.value
|
||||
assert system_message["content"] == ""
|
||||
assert system_message["author"]["id"] == str(user.id)
|
||||
|
|
|
|||
Loading…
Reference in New Issue