diff --git a/plugin/adapter.py b/plugin/adapter.py index 2c335a7..3cefacb 100644 --- a/plugin/adapter.py +++ b/plugin/adapter.py @@ -544,8 +544,8 @@ class DDPClient: def set_status(self, status: str) -> bool: if not self.connected: return False - method = f"UserPresence:{status}" - self._send_json({"msg": "method", "method": method, "params": [], "id": f"st{int(time.time()*1000)}"}) + method = "UserPresence:setDefaultStatus" + self._send_json({"msg": "method", "method": method, "params": [status], "id": f"st{int(time.time()*1000)}"}) return True def disconnect(self): diff --git a/plugin/archivar/tests/test_ddp_room_events.py b/plugin/archivar/tests/test_ddp_room_events.py index 134cc0e..97dc22c 100644 --- a/plugin/archivar/tests/test_ddp_room_events.py +++ b/plugin/archivar/tests/test_ddp_room_events.py @@ -129,3 +129,74 @@ class TestDDPRoomEvents: client._handle_ddp_message(event_data) assert len(received_events) == 0 + + +class TestDDPSetStatus: + """Tests für DDPClient.set_status — P0 Fix: UserPresence:setDefaultStatus.""" + + def test_set_status_online_sends_correct_json(self): + """set_status('online') sendet UserPresence:setDefaultStatus mit params=['online'].""" + from adapter import DDPClient + + client = DDPClient("test.example.com") + client.connected = True + client.sock = MagicMock() + + with patch.object(client, "_send_json") as mock_send: + result = client.set_status("online") + + assert result is True + mock_send.assert_called_once() + call_args = mock_send.call_args[0][0] + assert call_args["msg"] == "method" + assert call_args["method"] == "UserPresence:setDefaultStatus" + assert call_args["params"] == ["online"] + assert call_args["id"].startswith("st") + + def test_set_status_away_sends_correct_json(self): + """set_status('away') sendet UserPresence:setDefaultStatus mit params=['away'].""" + from adapter import DDPClient + + client = DDPClient("test.example.com") + client.connected = True + client.sock = MagicMock() + + with patch.object(client, "_send_json") as mock_send: + result = client.set_status("away") + + assert result is True + mock_send.assert_called_once() + call_args = mock_send.call_args[0][0] + assert call_args["msg"] == "method" + assert call_args["method"] == "UserPresence:setDefaultStatus" + assert call_args["params"] == ["away"] + assert call_args["id"].startswith("st") + + def test_set_status_busy_sends_correct_json(self): + """set_status('busy') sendet UserPresence:setDefaultStatus mit params=['busy'].""" + from adapter import DDPClient + + client = DDPClient("test.example.com") + client.connected = True + client.sock = MagicMock() + + with patch.object(client, "_send_json") as mock_send: + result = client.set_status("busy") + + assert result is True + mock_send.assert_called_once() + call_args = mock_send.call_args[0][0] + assert call_args["msg"] == "method" + assert call_args["method"] == "UserPresence:setDefaultStatus" + assert call_args["params"] == ["busy"] + assert call_args["id"].startswith("st") + + def test_set_status_disconnected_returns_false(self): + """set_status gibt False zurück wenn nicht connected.""" + from adapter import DDPClient + + client = DDPClient("test.example.com") + client.connected = False + + result = client.set_status("online") + assert result is False