# -*- coding: utf-8 -*-
from unittest import mock


async def test_get_frontend_state(homehub_app, homehub_client):
    # Given
    fake_state = {
        'backend': {
            'spam': True,
        },
        'frontend': {
            'eggs': True,
        },
    }

    with mock.patch.object(homehub_app['STATE'], 'get') as mock_state_get:
        mock_state_get.return_value = fake_state

        # When
        response = await homehub_client.post('/backend/rpc', json={
            'jsonrpc': '2.0',
            'id': 'testing',
            'method': 'state.get_frontend',
            'params': [],
        })

        # Then
        assert response.status == 200

        data = await response.json()
        assert data['result'] == fake_state['frontend']
        assert 'error' not in data
