mirror of
https://github.com/jkingsman/Remote-Terminal-for-MeshCore.git
synced 2026-08-08 09:43:03 +02:00
Add testing harness and fix up a few niggling bugs
This commit is contained in:
@@ -1022,6 +1022,54 @@ class TestReadStateEndpoints:
|
||||
)
|
||||
assert result["first_unread_ids"][f"contact-{contact_key}"] == first_dm.id
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_first_unread_id_breaks_same_second_ties_by_id(self, test_db):
|
||||
"""Sender timestamps are whole seconds, so the oldest unread second is
|
||||
routinely shared. The boundary must be the first of those messages, not
|
||||
an arbitrary one."""
|
||||
chan_key = "BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB2"
|
||||
await ChannelRepository.upsert(key=chan_key, name="Busy")
|
||||
await ChannelRepository.update_last_read_at(chan_key, 1000)
|
||||
|
||||
# Three unread messages all landing in the same second.
|
||||
ids = []
|
||||
for text in ("Bob: first", "Bob: second", "Bob: third"):
|
||||
ids.append(
|
||||
await MessageRepository.create(
|
||||
msg_type="CHAN",
|
||||
text=text,
|
||||
received_at=1001,
|
||||
conversation_key=chan_key,
|
||||
sender_timestamp=1001,
|
||||
)
|
||||
)
|
||||
|
||||
result = await MessageRepository.get_unread_counts(None)
|
||||
|
||||
assert result["counts"][f"channel-{chan_key}"] == 3
|
||||
assert result["first_unread_ids"][f"channel-{chan_key}"] == min(ids)
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_first_unread_id_ignores_muted_and_outgoing(self, test_db):
|
||||
"""Muted channels are excluded from unread counts, so they must not
|
||||
report a boundary either."""
|
||||
chan_key = "CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC3"
|
||||
await ChannelRepository.upsert(key=chan_key, name="Muted")
|
||||
await ChannelRepository.update_last_read_at(chan_key, 1000)
|
||||
await ChannelRepository.set_muted(chan_key, True)
|
||||
await MessageRepository.create(
|
||||
msg_type="CHAN",
|
||||
text="Bob: unread but muted",
|
||||
received_at=1001,
|
||||
conversation_key=chan_key,
|
||||
sender_timestamp=1001,
|
||||
)
|
||||
|
||||
result = await MessageRepository.get_unread_counts(None)
|
||||
|
||||
assert f"channel-{chan_key}" not in result["counts"]
|
||||
assert result["first_unread_ids"].get(f"channel-{chan_key}") is None
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_get_unreads_no_name_skips_mentions(self, test_db):
|
||||
"""Unreads without a radio name returns counts but no mention flags."""
|
||||
|
||||
Reference in New Issue
Block a user