"use strict";

var _tape = _interopRequireDefault(require("tape"));

var _reduxBundler = require("redux-bundler");

var _getOrgsBundle = require("./get-orgs-bundle");

var _toGqlQuery = require("../utils/to-gql-query");

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

const orgResponseSnippet = (0, _toGqlQuery.toGqlQuery)(['id', 'fhirId', 'name', 'type', 'parentOrgs', 'featuresJSON']);

const getStore = () => (0, _reduxBundler.composeBundlesRaw)(_reduxBundler.appTimeBundle, (0, _reduxBundler.createReactorBundle)({
  idleTimeout: 100,
  cancelIdleWhenDone: false
}), (0, _getOrgsBundle.getOrgsBundle)({
  orgResponseSnippet,
  activeOrgSelectorName: 'selectActiveOrgId'
}), {
  name: 'overrides',
  selectActiveOrgId: () => 'hi',
  selectSessionOrgs: () => [{
    id: 'hi',
    memberId: '9d2542e6-b08e-44b1-9b99-81ab924b423d',
    roles: ['admin', 'provider'],
    status: null,
    type: null
  }],
  selectSessionOrgIds: () => ['hi'],
  selectIsXchartUberUser: () => false,
  selectIsSignedIn: () => true,
  getExtraArgs: () => ({
    gqlFetch: () => new Promise(resolve => {
      setTimeout(() => resolve({
        data: {
          org: {
            id: 'hi',
            features: null
          }
        }
      }), 1000);
    })
  })
})();

(0, _tape.default)('getOrgsBundle with feature override', t => {
  const store = getStore();
  t.deepEqual(store.selectOrgFeatures(), {}, 'no features yet');
  store.doOrgFeatureOverride({
    feature: 'foo',
    value: 'bar'
  });
  store.doOrgFeatureOverride({
    feature: 'other',
    value: 'value'
  });
  t.deepEqual(store.selectOrgFeatures(), {
    foo: 'bar',
    other: 'value'
  }, 'now has override features');
  store.doOrgFeatureOverride({
    feature: 'foo',
    value: null
  });
  t.deepEqual(store.selectOrgFeatures(), {
    other: 'value'
  }, 'now has override features');
  store.doOrgFeatureOverride({
    feature: 'other',
    value: null
  });
  t.deepEqual(store.selectOrgFeatures(), {}, 'back to empty features');
  store.destroy();
  t.end();
});