'use strict';

define('dummy/tests/acceptance/kyc-application-test', ['qunit', 'ember-qunit', '@ember/test-helpers', 'dummy/tests/helpers/form-helpers', 'dummy/tests/helpers/fixtures', 'ember-cli-mirage/test-support/setup-mirage'], function (_qunit, _emberQunit, _testHelpers, _formHelpers, _fixtures, _setupMirage) {
  'use strict';

  function _asyncToGenerator(fn) {
    return function () {
      var gen = fn.apply(this, arguments);
      return new Promise(function (resolve, reject) {
        function step(key, arg) {
          try {
            var info = gen[key](arg);
            var value = info.value;
          } catch (error) {
            reject(error);
            return;
          }

          if (info.done) {
            resolve(value);
          } else {
            return Promise.resolve(value).then(function (value) {
              step("next", value);
            }, function (err) {
              step("throw", err);
            });
          }
        }

        return step("next");
      });
    };
  }

  (0, _qunit.module)('Acceptance | KYC Application', function (hooks) {
    (0, _emberQunit.setupApplicationTest)(hooks);
    (0, _setupMirage.default)(hooks);

    (0, _qunit.test)('validates the form fields', function () {
      var _ref = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee(assert) {
        return regeneratorRuntime.wrap(function _callee$(_context) {
          while (1) {
            switch (_context.prev = _context.next) {
              case 0:
                _context.next = 2;
                return (0, _testHelpers.visit)('/kyc');

              case 2:
                assert.equal((0, _testHelpers.currentURL)(), '/kyc');

                _context.next = 5;
                return (0, _testHelpers.click)('button.submit');

              case 5:

                assert.dom('.field-error').exists({ count: 10 });

                _context.next = 8;
                return (0, _formHelpers.fillInKycField)('bfn');

              case 8:
                _context.next = 10;
                return (0, _formHelpers.fillInKycField)('bln');

              case 10:
                _context.next = 12;
                return (0, _formHelpers.fillInKycField)('tea');

              case 12:
                _context.next = 14;
                return (0, _formHelpers.fillInKycField)('bsn');

              case 14:
                _context.next = 16;
                return (0, _formHelpers.fillInKycField)('bz');

              case 16:
                _context.next = 18;
                return (0, _formHelpers.fillInKycField)('bc');

              case 18:
                _context.next = 20;
                return (0, _formHelpers.fillInKycField)('bs');

              case 20:
                _context.next = 22;
                return (0, _testHelpers.click)('button.submit');

              case 22:

                assert.dom('.field-error').exists({ count: 5 });

                (0, _formHelpers.uploadFile)('#kyc-field_scanData');
                (0, _formHelpers.uploadFile)('#kyc-field_faceImageData');

                _context.next = 27;
                return (0, _testHelpers.click)('button.submit');

              case 27:

                assert.dom('.field-error').exists({ count: 3 });

              case 28:
              case 'end':
                return _context.stop();
            }
          }
        }, _callee, this);
      }));

      return function (_x) {
        return _ref.apply(this, arguments);
      };
    }());

    (0, _qunit.test)('show a spinner while waiting for response', function () {
      var _ref2 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee2(assert) {
        var submitPromise;
        return regeneratorRuntime.wrap(function _callee2$(_context2) {
          while (1) {
            switch (_context2.prev = _context2.next) {
              case 0:
                server.post('/identitymind-verifications', function () {
                  return _fixtures.acceptedCreateResponse;
                });

                _context2.next = 3;
                return (0, _testHelpers.visit)('/kyc');

              case 3:
                assert.equal((0, _testHelpers.currentURL)(), '/kyc');

                _context2.next = 6;
                return (0, _formHelpers.fillInRequiredFields)();

              case 6:
                submitPromise = (0, _testHelpers.click)('button.submit');
                _context2.next = 9;
                return (0, _testHelpers.waitFor)('.kyc-processing');

              case 9:
                _context2.next = 11;
                return submitPromise;

              case 11:
                _context2.next = 13;
                return (0, _testHelpers.waitUntil)(function () {
                  return (0, _testHelpers.currentURL)() === '/';
                });

              case 13:
              case 'end':
                return _context2.stop();
            }
          }
        }, _callee2, this);
      }));

      return function (_x2) {
        return _ref2.apply(this, arguments);
      };
    }());
  });
});
define('dummy/tests/app.lint-test', [], function () {
  'use strict';

  QUnit.module('ESLint | app');

  QUnit.test('app.js', function (assert) {
    assert.expect(1);
    assert.ok(true, 'app.js should pass ESLint\n\n');
  });

  QUnit.test('controllers/kyc.js', function (assert) {
    assert.expect(1);
    assert.ok(true, 'controllers/kyc.js should pass ESLint\n\n');
  });

  QUnit.test('resolver.js', function (assert) {
    assert.expect(1);
    assert.ok(true, 'resolver.js should pass ESLint\n\n');
  });

  QUnit.test('router.js', function (assert) {
    assert.expect(1);
    assert.ok(true, 'router.js should pass ESLint\n\n');
  });
});
define('dummy/tests/helpers/ember-simple-auth', ['exports', 'ember-simple-auth/authenticators/test'], function (exports, _test) {
  'use strict';

  Object.defineProperty(exports, "__esModule", {
    value: true
  });
  exports.authenticateSession = authenticateSession;
  exports.currentSession = currentSession;
  exports.invalidateSession = invalidateSession;


  var TEST_CONTAINER_KEY = 'authenticator:test';

  function ensureAuthenticator(app, container) {
    var authenticator = container.lookup(TEST_CONTAINER_KEY);
    if (!authenticator) {
      app.register(TEST_CONTAINER_KEY, _test.default);
    }
  }

  function authenticateSession(app, sessionData) {
    var container = app.__container__;

    var session = container.lookup('service:session');
    ensureAuthenticator(app, container);
    session.authenticate(TEST_CONTAINER_KEY, sessionData);
    return app.testHelpers.wait();
  }

  function currentSession(app) {
    return app.__container__.lookup('service:session');
  }

  function invalidateSession(app) {
    var session = app.__container__.lookup('service:session');
    if (session.get('isAuthenticated')) {
      session.invalidate();
    }
    return app.testHelpers.wait();
  }
});
define("dummy/tests/helpers/fixtures", ["exports"], function (exports) {
  "use strict";

  Object.defineProperty(exports, "__esModule", {
    value: true
  });
  var acceptedCreateResponse = exports.acceptedCreateResponse = {
    "data": {
      "id": "89275686",
      "type": "identitymind-verifications",
      "attributes": {
        "man": "Bill Wagby",
        "bfn": "Bill",
        "bln": "Wagby",
        "bco": "DZ",
        "sco": "DZ",
        "tea": "a@c.d",
        "dob": "2002-11-30",
        "bsn": "43",
        "bz": "",
        "bc": "a",
        "bs": "",
        "upr": "UNKNOWN",
        "frn": "Sandbox Rule",
        "frp": "ACCEPT",
        "frd": "[Fired] details",
        "mtid": "89275686",
        "state": "A",
        "erd": "Unknown User",
        "arpr": null,
        "res": "ACCEPT",
        "rcd": "131,101,50005,150,1000,202",
        "edna-score-card": null,
        "last-checked-at": null,
        "user": "UNKNOWN",
        "ednaScoreCard": {}
      }
    }
  };
});
define('dummy/tests/helpers/form-helpers', ['exports', '@ember/test-helpers'], function (exports, _testHelpers) {
  'use strict';

  Object.defineProperty(exports, "__esModule", {
    value: true
  });
  exports.fillInRequiredFields = exports.fillInKycField = undefined;
  exports.uploadFile = uploadFile;

  function _asyncToGenerator(fn) {
    return function () {
      var gen = fn.apply(this, arguments);
      return new Promise(function (resolve, reject) {
        function step(key, arg) {
          try {
            var info = gen[key](arg);
            var value = info.value;
          } catch (error) {
            reject(error);
            return;
          }

          if (info.done) {
            resolve(value);
          } else {
            return Promise.resolve(value).then(function (value) {
              step("next", value);
            }, function (err) {
              step("throw", err);
            });
          }
        }

        return step("next");
      });
    };
  }

  var validInputValues = {
    bfn: 'Bill',
    bln: 'Wagby',
    bco: 'GB',
    sco: 'SO',
    tea: 'bill@wagby.net',
    dob: '1999-01-01',
    bsn: '145 Penny Lane',
    bz: '10901',
    bc: 'Harpers Ferry',
    bs: 'NY',
    scanData: '',
    faceImageData: '',
    backsideImageData: ''
  };

  function uploadFile(selector) {
    var file = new Blob(['text-image'], { type: 'text/plain' });
    file.name = 'test.txt';

    (0, _testHelpers.find)(selector).dispatchEvent(new CustomEvent('change', { detail: { testingFiles: [file] } }));
  }

  var fillInKycField = exports.fillInKycField = function () {
    var _ref = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee(field) {
      return regeneratorRuntime.wrap(function _callee$(_context) {
        while (1) {
          switch (_context.prev = _context.next) {
            case 0:
              _context.next = 2;
              return (0, _testHelpers.fillIn)('#kyc-field_' + field, validInputValues[field]);

            case 2:
            case 'end':
              return _context.stop();
          }
        }
      }, _callee, this);
    }));

    return function fillInKycField(_x) {
      return _ref.apply(this, arguments);
    };
  }();

  var fillInRequiredFields = exports.fillInRequiredFields = function () {
    var _ref2 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee2() {
      return regeneratorRuntime.wrap(function _callee2$(_context2) {
        while (1) {
          switch (_context2.prev = _context2.next) {
            case 0:
              _context2.next = 2;
              return fillInKycField('bfn');

            case 2:
              _context2.next = 4;
              return fillInKycField('bln');

            case 4:
              _context2.next = 6;
              return fillInKycField('tea');

            case 6:
              _context2.next = 8;
              return fillInKycField('bsn');

            case 8:
              _context2.next = 10;
              return fillInKycField('bz');

            case 10:
              _context2.next = 12;
              return fillInKycField('bc');

            case 12:
              _context2.next = 14;
              return fillInKycField('bs');

            case 14:
              _context2.next = 16;
              return fillInKycField('bco');

            case 16:
              _context2.next = 18;
              return fillInKycField('sco');

            case 18:
              _context2.next = 20;
              return fillInKycField('dob');

            case 20:

              uploadFile('#kyc-field_scanData');
              uploadFile('#kyc-field_faceImageData');

            case 22:
            case 'end':
              return _context2.stop();
          }
        }
      }, _callee2, this);
    }));

    return function fillInRequiredFields() {
      return _ref2.apply(this, arguments);
    };
  }();
});
define('dummy/tests/integration/helpers/identitymind-pdf-url-test', ['qunit', 'ember-qunit', '@ember/test-helpers', '@cardstack/plugin-utils/environment'], function (_qunit, _emberQunit, _testHelpers, _environment) {
  'use strict';

  function _asyncToGenerator(fn) {
    return function () {
      var gen = fn.apply(this, arguments);
      return new Promise(function (resolve, reject) {
        function step(key, arg) {
          try {
            var info = gen[key](arg);
            var value = info.value;
          } catch (error) {
            reject(error);
            return;
          }

          if (info.done) {
            resolve(value);
          } else {
            return Promise.resolve(value).then(function (value) {
              step("next", value);
            }, function (err) {
              step("throw", err);
            });
          }
        }

        return step("next");
      });
    };
  }

  (0, _qunit.module)('Integration | Helper | identitymind-pdf-url', function (hooks) {
    (0, _emberQunit.setupRenderingTest)(hooks);

    (0, _qunit.test)('it renders pdf url', function () {
      var _ref2 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee(assert) {
        return regeneratorRuntime.wrap(function _callee$(_context) {
          while (1) {
            switch (_context.prev = _context.next) {
              case 0:
                this.set('inputValue', '1234');

                _context.next = 3;
                return (0, _testHelpers.render)(Ember.HTMLBars.template({
                  "id": "wjPU5khJ",
                  "block": "{\"symbols\":[],\"statements\":[[1,[25,\"identitymind-pdf-url\",null,[[\"name\",\"surname\",\"dob\",\"nationality\",\"country\",\"address\"],[\"first\",\"last\",\"date\",\"British\",\"UK\",\"123 Acacia Avenue\"]]],false]],\"hasEval\":false}",
                  "meta": {}
                }));

              case 3:

                assert.equal(this.element.textContent.trim(), _environment.hubURL + '/identitymind/bcs-pdf?name=first&surname=last&dob=date&nationality=British&country=UK&address=123%20Acacia%20Avenue');

              case 4:
              case 'end':
                return _context.stop();
            }
          }
        }, _callee, this);
      }));

      return function (_x) {
        return _ref2.apply(this, arguments);
      };
    }());
  });
});
define('dummy/tests/integration/kyc-form-test', ['qunit', 'ember-qunit', '@ember/test-helpers', 'dummy/tests/helpers/form-helpers', 'dummy/tests/helpers/fixtures', 'ember-cli-mirage/test-support/setup-mirage'], function (_qunit, _emberQunit, _testHelpers, _formHelpers, _fixtures, _setupMirage) {
  'use strict';

  function _asyncToGenerator(fn) {
    return function () {
      var gen = fn.apply(this, arguments);
      return new Promise(function (resolve, reject) {
        function step(key, arg) {
          try {
            var info = gen[key](arg);
            var value = info.value;
          } catch (error) {
            reject(error);
            return;
          }

          if (info.done) {
            resolve(value);
          } else {
            return Promise.resolve(value).then(function (value) {
              step("next", value);
            }, function (err) {
              step("throw", err);
            });
          }
        }

        return step("next");
      });
    };
  }

  (0, _qunit.module)('Integration | Component | KYC form hooks', function (hooks) {
    (0, _emberQunit.setupRenderingTest)(hooks);
    (0, _setupMirage.default)(hooks);

    (0, _qunit.test)('it renders', function () {
      var _ref2 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee(assert) {
        return regeneratorRuntime.wrap(function _callee$(_context) {
          while (1) {
            switch (_context.prev = _context.next) {
              case 0:
                _context.next = 2;
                return (0, _testHelpers.render)(Ember.HTMLBars.template({
                  "id": "zmuPGIzg",
                  "block": "{\"symbols\":[],\"statements\":[[1,[18,\"kyc-form\"],false]],\"hasEval\":false}",
                  "meta": {}
                }));

              case 2:

                assert.dom('legend').hasText('Submission Form');
                assert.dom('.kyc-field').exists({ count: 13 });

              case 4:
              case 'end':
                return _context.stop();
            }
          }
        }, _callee, this);
      }));

      return function (_x) {
        return _ref2.apply(this, arguments);
      };
    }());

    (0, _qunit.test)('hooks are fired', function () {
      var _ref3 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee2(assert) {
        return regeneratorRuntime.wrap(function _callee2$(_context2) {
          while (1) {
            switch (_context2.prev = _context2.next) {
              case 0:
                assert.expect(2);

                server.post('/identitymind-verifications', function () {
                  return _fixtures.acceptedCreateResponse;
                });

                this.set('doSomething', function () {
                  assert.ok(true, 'hook is called');
                });

                _context2.next = 5;
                return (0, _testHelpers.render)(Ember.HTMLBars.template({
                  "id": "fRCBJBph",
                  "block": "{\"symbols\":[],\"statements\":[[1,[25,\"kyc-form\",null,[[\"postSubmit\",\"willSaveModel\"],[[25,\"action\",[[19,0,[]],[20,[\"doSomething\"]]],null],[25,\"action\",[[19,0,[]],[20,[\"doSomething\"]]],null]]]],false]],\"hasEval\":false}",
                  "meta": {}
                }));

              case 5:
                _context2.next = 7;
                return (0, _formHelpers.fillInRequiredFields)();

              case 7:
                _context2.next = 9;
                return (0, _testHelpers.click)('button.submit');

              case 9:
              case 'end':
                return _context2.stop();
            }
          }
        }, _callee2, this);
      }));

      return function (_x2) {
        return _ref3.apply(this, arguments);
      };
    }());

    (0, _qunit.test)('hasErrors hook is fired', function () {
      var _ref4 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee3(assert) {
        return regeneratorRuntime.wrap(function _callee3$(_context3) {
          while (1) {
            switch (_context3.prev = _context3.next) {
              case 0:
                assert.expect(1);

                this.set('doSomething', function () {
                  assert.ok(true, 'hook is called');
                });

                _context3.next = 4;
                return (0, _testHelpers.render)(Ember.HTMLBars.template({
                  "id": "l+5qF65p",
                  "block": "{\"symbols\":[],\"statements\":[[1,[25,\"kyc-form\",null,[[\"hasErrors\"],[[25,\"action\",[[19,0,[]],[20,[\"doSomething\"]]],null]]]],false]],\"hasEval\":false}",
                  "meta": {}
                }));

              case 4:
                _context3.next = 6;
                return (0, _testHelpers.click)('button.submit');

              case 6:
              case 'end':
                return _context3.stop();
            }
          }
        }, _callee3, this);
      }));

      return function (_x3) {
        return _ref4.apply(this, arguments);
      };
    }());

    (0, _qunit.test)('pre-populate name and email fields if user is passed in', function () {
      var _ref5 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee4(assert) {
        return regeneratorRuntime.wrap(function _callee4$(_context4) {
          while (1) {
            switch (_context4.prev = _context4.next) {
              case 0:
                _context4.next = 2;
                return (0, _testHelpers.render)(Ember.HTMLBars.template({
                  "id": "ApPfEs18",
                  "block": "{\"symbols\":[],\"statements\":[[1,[25,\"kyc-form\",null,[[\"defaultFirstName\",\"defaultLastName\",\"defaultEmail\"],[\"Bill\",\"Wagby\",\"bill@wagby.net\"]]],false]],\"hasEval\":false}",
                  "meta": {}
                }));

              case 2:

                assert.dom('#kyc-field_bfn').hasValue('Bill', 'first name is correct');
                assert.dom('#kyc-field_bln').hasValue('Wagby', 'last name is correct');
                assert.dom('#kyc-field_tea').hasValue('bill@wagby.net', 'email is correct');

              case 5:
              case 'end':
                return _context4.stop();
            }
          }
        }, _callee4, this);
      }));

      return function (_x4) {
        return _ref5.apply(this, arguments);
      };
    }());
  });
});
define('dummy/tests/test-helper', ['dummy/app', 'dummy/config/environment', '@ember/test-helpers', 'ember-qunit'], function (_app, _environment, _testHelpers, _emberQunit) {
  'use strict';

  (0, _testHelpers.setApplication)(_app.default.create(_environment.default.APP));

  (0, _emberQunit.start)();
});
define('dummy/tests/tests.lint-test', [], function () {
  'use strict';

  QUnit.module('ESLint | tests');

  QUnit.test('acceptance/kyc-application-test.js', function (assert) {
    assert.expect(1);
    assert.ok(true, 'acceptance/kyc-application-test.js should pass ESLint\n\n');
  });

  QUnit.test('helpers/fixtures.js', function (assert) {
    assert.expect(1);
    assert.ok(true, 'helpers/fixtures.js should pass ESLint\n\n');
  });

  QUnit.test('helpers/form-helpers.js', function (assert) {
    assert.expect(1);
    assert.ok(true, 'helpers/form-helpers.js should pass ESLint\n\n');
  });

  QUnit.test('integration/helpers/identitymind-pdf-url-test.js', function (assert) {
    assert.expect(1);
    assert.ok(true, 'integration/helpers/identitymind-pdf-url-test.js should pass ESLint\n\n');
  });

  QUnit.test('integration/kyc-form-test.js', function (assert) {
    assert.expect(1);
    assert.ok(true, 'integration/kyc-form-test.js should pass ESLint\n\n');
  });

  QUnit.test('test-helper.js', function (assert) {
    assert.expect(1);
    assert.ok(true, 'test-helper.js should pass ESLint\n\n');
  });
});
define('dummy/config/environment', [], function() {
  var prefix = 'dummy';
try {
  var metaName = prefix + '/config/environment';
  var rawConfig = document.querySelector('meta[name="' + metaName + '"]').getAttribute('content');
  var config = JSON.parse(unescape(rawConfig));

  var exports = { 'default': config };

  Object.defineProperty(exports, '__esModule', { value: true });

  return exports;
}
catch(err) {
  throw new Error('Could not read config from meta tag with name "' + metaName + '".');
}

});

require('dummy/tests/test-helper');
EmberENV.TESTS_FILE_LOADED = true;
//# sourceMappingURL=tests.map
