This commit is contained in:
64
tests/test_reactions.py
Normal file
64
tests/test_reactions.py
Normal file
@@ -0,0 +1,64 @@
|
||||
import pytest
|
||||
from orm.reaction import Reaction, ReactionKind
|
||||
from orm.shout import Shout
|
||||
from orm.author import Author
|
||||
from datetime import datetime
|
||||
|
||||
@pytest.fixture
|
||||
def test_setup(db_session):
|
||||
"""Set up test data."""
|
||||
now = int(datetime.now().timestamp())
|
||||
author = Author(name="Test Author", slug="test-author", user="test-user-id")
|
||||
db_session.add(author)
|
||||
db_session.flush()
|
||||
|
||||
shout = Shout(
|
||||
title="Test Shout",
|
||||
slug="test-shout",
|
||||
created_by=author.id,
|
||||
body="This is a test shout",
|
||||
layout="article",
|
||||
lang="ru",
|
||||
community=1,
|
||||
created_at=now,
|
||||
updated_at=now
|
||||
)
|
||||
db_session.add_all([author, shout])
|
||||
db_session.commit()
|
||||
return {"author": author, "shout": shout}
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_create_reaction(test_client, db_session, test_setup):
|
||||
"""Test creating a reaction on a shout."""
|
||||
response = test_client.post(
|
||||
"/",
|
||||
json={
|
||||
"query": """
|
||||
mutation CreateReaction($reaction: ReactionInput!) {
|
||||
create_reaction(reaction: $reaction) {
|
||||
error
|
||||
reaction {
|
||||
id
|
||||
kind
|
||||
body
|
||||
created_by {
|
||||
name
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
""",
|
||||
"variables": {
|
||||
"reaction": {
|
||||
"shout": test_setup["shout"].id,
|
||||
"kind": ReactionKind.LIKE.value,
|
||||
"body": "Great post!"
|
||||
}
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
assert response.status_code == 200
|
||||
data = response.json()
|
||||
assert "error" not in data
|
||||
assert data["data"]["create_reaction"]["reaction"]["kind"] == ReactionKind.LIKE.value
|
Reference in New Issue
Block a user