"use strict";

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

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

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

function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; if (desc.get || desc.set) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj["default"] = obj; return newObj; } }

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

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