import * as State from 'src/api/state';
import * as RPC from 'src/lib/rpc';

describe('src/api/state', () => {
  beforeEach(() => {
    spyOn(RPC, 'callMethod').and.resolveTo('ok');
  });

  describe('get', () => {
    it('calls and RPC method to get frontend state', async () => {
      // When
      const result = await State.get();

      // Then
      expect(result).toEqual('ok');
      expect(RPC.callMethod).toHaveBeenCalledWith('state.get_frontend');
    });
  });

  describe('save', () => {
    it('calls and RPC method to save frontend state', async () => {
      // When
      const result = await State.save('spam');

      // Then
      expect(result).toEqual('ok');
      expect(RPC.callMethod).toHaveBeenCalledWith(
        'state.save_frontend', ['spam']
      );
    });
  });
});
