<commit_before><commit_msg>LoginStore tests<commit_after>jest.autoMockOff();

jest.mock('../../js/dispatchers/AppDispatcher');

const AppDispatcher = require('../../js/dispatchers/AppDispatcher');
const LoginStore = require('../../js/stores/LoginStore');

let callback;

let loggedInState = {
  token: 'token',
  user: 'admin',
  serviceCatalog: 'service catalog',
  metadata: 'some metadata'
};

// mock actions
let loginUserAction = {
  actionType:'LOGIN_USER',
  keystoneAccess: loggedInState
};

let logoutUserAction = {
  actionType: 'LOGOUT_USER'
};

describe('LoginStore', () => {
  beforeEach(() => {
    callback = AppDispatcher.register.mock.calls[0][0];
  });

  it('registers a callback with the dispatcher', function() {
    expect(AppDispatcher.register.mock.calls.length).toBe(1);
  });

  it('sets state to keystoneAccess data when user logs in', () => {
    LoginStore.emitChange = jest.genMockFunction();
    callback(loginUserAction);
    expect(LoginStore.state).toEqual({
      token: 'token',
      user: 'admin',
      serviceCatalog: 'service catalog',
      metadata: 'some metadata'
    });
    expect(LoginStore.emitChange).toBeCalled();
  });

  it('cleans the state when user logs out', () => {
    LoginStore.emitChange = jest.genMockFunction();
    callback(logoutUserAction);
    expect(LoginStore.state).toEqual({});
    expect(LoginStore.emitChange).toBeCalled();
  });

  it('returns state with getState', () => {
    LoginStore.state = loggedInState;
    expect(LoginStore.getState()).toEqual(loggedInState);
  });

  it('provides function to determine if user is logged in', () => {
    LoginStore.state = loggedInState;
    expect(LoginStore.isLoggedIn()).toEqual(true);
  });
});

{'fraction_non_alphanumeric': 0.16114019778941244, 'fraction_numerical': 0.0017452006980802793, 'mean_word_length': 4.165165165165165, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '810522', 'n_tokens_mistral': 527, 'n_tokens_neox': 523, 'n_words': 101}