"use strict";

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

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

var _token = require("./token");

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

/* eslint-disable no-undef */
const getStore = () => {
  global.document = {
    cookie: ''
  };
  global.location = {
    hostname: 'xchart.com',
    hash: ''
  };
  const store = (0, _reduxBundler.composeBundlesRaw)((0, _token.createTokenBundle)({
    name: 'token',
    domain: 'something.com'
  }), {
    name: 'stubs'
  })();
  return store;
};

(0, _tape.default)('createTokenBundle with token in URL', t => {
  global.document = {
    cookie: ''
  };
  global.location = {
    hostname: 'xchart.com',
    hash: '#token=something'
  };
  const store = (0, _reduxBundler.composeBundlesRaw)((0, _token.createTokenBundle)({
    name: 'token',
    domain: 'something.com'
  }), {
    name: 'stubs'
  })();
  t.equal(store.selectAuthToken(), 'something');
  t.end();
});
(0, _tape.default)('createTokenBundle', async t => {
  const store = getStore();
  t.equal(store.selectAuthToken(), null, 'should be null');
  store.doReceiveToken(null);
  t.equal(store.selectAuthToken(), null, 'should still be null');
  t.equal(store.selectHasAuthToken(), false, 'does not have auth token');
  store.doReceiveToken('null');
  t.equal(store.selectAuthToken(), null, 'should still be null if we get null string for some reason');
  t.equal(store.selectHasAuthToken(), false, 'does not have auth token');
  store.doReceiveToken('blahblah');
  t.equal(store.selectAuthToken(), 'blahblah', 'should now have blahblah string');
  t.equal(store.selectHasAuthToken(), true, 'has auth token');
  t.equal(global.document.cookie, 'token=blahblah;domain=something.com;path=/;secure;max-age=15552000');
  store.doClearToken();
  t.equal(global.document.cookie, 'token=;domain=something.com;path=/;expires=Thu, 01 Jan 1970 00:00:00 GMT');
  t.equal(store.selectHasAuthToken(), false, 'does not have auth token');
  store.doReceiveToken('blahagain');
  t.equal(store.selectHasAuthToken(), true, 'has auth token');
  t.equal(global.document.cookie, 'token=blahagain;domain=something.com;path=/;secure;max-age=15552000');
  t.end();
});