"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");

var _mock = _interopRequireDefault(require("@polkadot/rpc-provider/mock"));

var _util = require("@polkadot/util");

var _ = _interopRequireDefault(require("."));

// Copyright 2017-2019 @polkadot/rpc-core authors & contributors
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.
describe('Api', () => {
  it('requires a provider with a send method', () => {
    expect(() => new _.default({})).toThrow(/Expected Provider/);
  });
  it('creates an instance with all sections', () => {
    const rpc = new _.default(new _mock.default());
    expect(Object.keys(rpc).filter(key => !key.startsWith('_'))).toEqual(['provider', 'mapping', 'sections', 'account', 'author', 'chain', 'contracts', 'rpc', 'state', 'system']);
  });
  it('allows for the definition of user RPCs', () => {
    const rpc = new _.default(new _mock.default(), {
      testing: [{
        name: 'foo',
        params: [{
          name: 'bar',
          type: 'u32'
        }],
        type: 'Balance'
      }]
    });
    expect((0, _util.isFunction)(rpc.testing.foo)).toBe(true);
    expect(rpc.sections.includes('testing')).toBe(true);
    expect(rpc.mapping.get('testing_foo')).toEqual({
      description: 'User defined',
      isDeprecated: false,
      isHidden: false,
      isOptional: false,
      isSigned: false,
      isSubscription: false,
      method: 'foo',
      params: [{
        isOptional: false,
        name: 'bar',
        type: 'u32'
      }],
      pubsub: ['', '', ''],
      section: 'testing',
      type: 'Balance'
    });
  });
});