forked from retoor/devplacepy
Add personal notes, DeepSearch history, backup offload, and gateway auth throttling
Also streamline the top navigation: drop the Tools dropdown, make Quizzes and Battles icon-only entries, and remove the Workspace, Containers and Editor entry points from the project detail page.
This commit is contained in:
@@ -4,7 +4,24 @@ from datetime import datetime, timezone
|
||||
|
||||
from devplacepy.database import get_table
|
||||
from devplacepy.utils import generate_uid
|
||||
from devplacepy.services.messaging.persist import stamp_content_revision
|
||||
from devplacepy.services.messaging.persist import persist_message, stamp_content_revision
|
||||
|
||||
|
||||
def _make_user(prefix):
|
||||
uid = generate_uid()
|
||||
get_table("users").insert(
|
||||
{
|
||||
"uid": uid,
|
||||
"username": f"{prefix}_{uid[:8]}",
|
||||
"email": f"{uid[:8]}@{prefix}.test",
|
||||
"terms_version": "1",
|
||||
}
|
||||
)
|
||||
return uid
|
||||
|
||||
|
||||
def _sender(uid):
|
||||
return {"uid": uid, "username": "sender", "role": "Member"}
|
||||
|
||||
|
||||
def test_stamp_content_revision_sets_updated_at(local_db):
|
||||
@@ -26,3 +43,84 @@ def test_stamp_content_revision_sets_updated_at(local_db):
|
||||
stored = get_table("messages").find_one(uid=uid)
|
||||
assert stored["updated_at"] == row["updated_at"]
|
||||
assert stored["content"] == "hello"
|
||||
|
||||
|
||||
def test_persist_message_dedupes_same_sender_and_client_id(local_db):
|
||||
sender_uid = _make_user("dedupe_sender")
|
||||
receiver_uid = _make_user("dedupe_receiver")
|
||||
sender = _sender(sender_uid)
|
||||
client_id = f"cid-{generate_uid()}"
|
||||
|
||||
first = persist_message(sender, receiver_uid, "hello once", client_id=client_id)
|
||||
assert first is not None
|
||||
|
||||
second = persist_message(sender, receiver_uid, "hello once", client_id=client_id)
|
||||
assert second is not None
|
||||
assert second["uid"] == first["uid"]
|
||||
|
||||
rows = list(
|
||||
get_table("messages").find(sender_uid=sender_uid, receiver_uid=receiver_uid)
|
||||
)
|
||||
assert len(rows) == 1
|
||||
|
||||
|
||||
def test_persist_message_does_not_dedupe_without_client_id(local_db):
|
||||
sender_uid = _make_user("nodedupe_sender")
|
||||
receiver_uid = _make_user("nodedupe_receiver")
|
||||
sender = _sender(sender_uid)
|
||||
|
||||
first = persist_message(sender, receiver_uid, "no client id here")
|
||||
second = persist_message(sender, receiver_uid, "no client id here")
|
||||
assert first["uid"] != second["uid"]
|
||||
|
||||
rows = list(
|
||||
get_table("messages").find(sender_uid=sender_uid, receiver_uid=receiver_uid)
|
||||
)
|
||||
assert len(rows) == 2
|
||||
|
||||
|
||||
def test_persist_message_does_not_dedupe_a_different_client_id(local_db):
|
||||
sender_uid = _make_user("diffid_sender")
|
||||
receiver_uid = _make_user("diffid_receiver")
|
||||
sender = _sender(sender_uid)
|
||||
|
||||
first = persist_message(sender, receiver_uid, "a", client_id="cid-a")
|
||||
second = persist_message(sender, receiver_uid, "b", client_id="cid-b")
|
||||
assert first["uid"] != second["uid"]
|
||||
|
||||
|
||||
def test_persist_message_suppresses_notification_when_receiver_is_actively_viewing(local_db):
|
||||
sender_uid = _make_user("active_sender")
|
||||
receiver_uid = _make_user("active_receiver")
|
||||
sender = _sender(sender_uid)
|
||||
|
||||
get_table("users").update(
|
||||
{
|
||||
"uid": receiver_uid,
|
||||
"active_conversation_uid": sender_uid,
|
||||
"active_conversation_at": datetime.now(timezone.utc).isoformat(),
|
||||
},
|
||||
["uid"],
|
||||
)
|
||||
|
||||
result = persist_message(sender, receiver_uid, "are you watching?", client_id="cid-watch")
|
||||
assert result is not None
|
||||
|
||||
notifications = list(
|
||||
get_table("notifications").find(user_uid=receiver_uid, type="message")
|
||||
)
|
||||
assert notifications == []
|
||||
|
||||
|
||||
def test_persist_message_notifies_when_receiver_is_not_actively_viewing(local_db):
|
||||
sender_uid = _make_user("inactive_sender")
|
||||
receiver_uid = _make_user("inactive_receiver")
|
||||
sender = _sender(sender_uid)
|
||||
|
||||
result = persist_message(sender, receiver_uid, "hello there", client_id="cid-plain")
|
||||
assert result is not None
|
||||
|
||||
notifications = list(
|
||||
get_table("notifications").find(user_uid=receiver_uid, type="message")
|
||||
)
|
||||
assert len(notifications) == 1
|
||||
|
||||
Reference in New Issue
Block a user