"use strict";

var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard");

var _demoConnector = require("./demo-connector");

var types = _interopRequireWildcard(require("../types"));

var _testUtils = require("../utils/test-utils");

/* eslint-disable max-nested-callbacks */
jest.setTimeout(20000);
describe(`The Demo Connector`, () => {
  const makeConnector = () => Promise.resolve(new _demoConnector.DemoConnector({}));

  test('Getting a category', () => {
    return makeConnector().then(connector => connector.getCategory('root')).then(data => expect((0, _testUtils.propTypeErrors)(types.Category, data)).toBeFalsy());
  });
  test('Getting a category, not found', () => {
    return makeConnector().then(connector => {
      expect(connector.getCategory('not-a-category')).rejects.toThrow();
    });
  });
  test('Getting a product', () => {
    return makeConnector().then(connector => connector.getProduct('1')).then(data => expect((0, _testUtils.propTypeErrors)(types.Product, data)).toBeFalsy());
  });
  test('Getting a product, not found', () => {
    return makeConnector().then(connector => {
      expect(connector.getProduct('not-a-product')).rejects.toThrow();
    });
  });
  test('Searching for products, no results', () => {
    return makeConnector().then(connector => connector.searchProducts({
      filters: {
        categoryId: 'tshirts'
      },
      query: ''
    })).then(data => expect((0, _testUtils.propTypeErrors)(types.ProductSearch, data)).toBeFalsy());
  });
  test('Searching for products, no results', () => {
    return makeConnector().then(connector => connector.searchProducts({
      filters: {
        categoryId: 'not-a-category'
      },
      query: ''
    })).then(data => {
      expect((0, _testUtils.propTypeErrors)(types.ProductSearch, data)).toBeFalsy();
      expect(data.results.length).toBe(0);
    });
  });
});