Added test that was missing and fixed others
@@ -292,6 +292,19 @@ class TestStateRegistryImpl:
fabric_impl.state_registry.update_channel.assert_called_with(payload)
+ @pytest.mark.asyncio
+ async def test_handle_channel_delete_for_invalid_update_event_dispatches_nothing(
+ self, adapter_impl, gateway_impl, dispatch_impl, fabric_impl
+ ):
+ payload = {"guild_id": 123}
+ fabric_impl.state_registry.get_guild_by_id = mock.MagicMock(
+ return_value=None)
+ await adapter_impl.handle_channel_delete(gateway_impl, payload)
+
+ # Not called other than the raw from earlier.
+ dispatch_impl.assert_called_once()
+ dispatch_impl.assert_called_with(events.RAW_CHANNEL_DELETE, payload)
+
@pytest.mark.asyncio
async def test_handle_channel_delete_parses_channel(self, adapter_impl, gateway_impl, dispatch_impl, fabric_impl):
guild_obj = _helpers.mock_model(guilds.Guild, id=123)
@@ -379,12 +392,13 @@ class TestStateRegistryImpl:
self, adapter_impl, gateway_impl, dispatch_impl, fabric_impl
):
channel_obj = _helpers.mock_model(channels.DMChannel, is_dm=True)
+ timestamp = datetime.datetime.utcnow().replace(tzinfo=datetime.timezone.utc)
payload = {"channel_id": channel_obj.id, "type": channel_obj.is_dm,
- "last_pin_timestamp": None}
+ "last_pin_timestamp": timestamp.isoformat()}
fabric_impl.state_registry.get_channel_by_id = mock.MagicMock(return_value=channel_obj)
await adapter_impl.handle_channel_pins_update(gateway_impl, payload)
- dispatch_impl.assert_called_with(events.DM_CHANNEL_PIN_REMOVED)
+ dispatch_impl.assert_called_with(events.DM_CHANNEL_PIN_ADDED, timestamp)
@pytest.mark.asyncio
async def test_handle_channel_pins_update_for_removing_pin_from_guild_channel_invokes_GUILD_CHANNEL_PIN_REMOVED(
@@ -402,13 +416,13 @@ class TestStateRegistryImpl:
async def test_handle_channel_pins_update_for_removing_pin_from_dm_channel_invokes_DM_CHANNEL_PIN_REMOVED(
self, adapter_impl, gateway_impl, dispatch_impl, fabric_impl
):
- channel_obj = _helpers.mock_model(channels.GuildChannel, is_dm=False)
+ channel_obj = _helpers.mock_model(channels.DMChannel, is_dm=True)
payload = {"channel_id": channel_obj.id, "type": channel_obj.is_dm,
"last_pin_timestamp": None}
fabric_impl.state_registry.get_channel_by_id = mock.MagicMock(return_value=channel_obj)
await adapter_impl.handle_channel_pins_update(gateway_impl, payload)
- dispatch_impl.assert_called_with(events.GUILD_CHANNEL_PIN_REMOVED)
+ dispatch_impl.assert_called_with(events.DM_CHANNEL_PIN_REMOVED)
@pytest.mark.asyncio
@pytest.mark.skip(reason="Not implemented")
