Skip to content

Commit

Permalink
Merge pull request #446 from frontside-folio/ww/test-fix-auth
Browse files Browse the repository at this point in the history
Fix currentUser error in tests
  • Loading branch information
wwilsman authored Oct 3, 2018
2 parents 7516813 + f36a343 commit b5e678c
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 4 deletions.
14 changes: 11 additions & 3 deletions src/App.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React, { Component } from 'react';
import PropTypes from 'prop-types';
import { okapi as okapiConfig, config } from 'stripes-config';
import merge from 'lodash/merge';

import connectErrorEpic from './connectErrorEpic';
import configureEpics from './configureEpics';
Expand All @@ -13,7 +14,8 @@ import Root from './components/Root';

export default class StripesCore extends Component {
static propTypes = {
history: PropTypes.object
history: PropTypes.object,
initialState: PropTypes.object
};

constructor(props) {
Expand All @@ -22,17 +24,23 @@ export default class StripesCore extends Component {
const okapi = (typeof okapiConfig === 'object' && Object.keys(okapiConfig).length > 0)
? okapiConfig : { withoutOkapi: true };

const initialState = merge({}, { okapi }, props.initialState);

this.logger = configureLogger(config);
this.logger.log('core', 'Starting Stripes ...');

this.epics = configureEpics(connectErrorEpic);
this.store = configureStore({ okapi }, this.logger, this.epics);
this.store = configureStore(initialState, this.logger, this.epics);
if (!okapi.withoutOkapi) discoverServices(this.store);

this.actionNames = gatherActions();
}

render() {
// no need to pass along `initialState`
// eslint-disable-next-line no-unused-vars
const { initialState, ...props } = this.props;

return (
<Root
store={this.store}
Expand All @@ -41,7 +49,7 @@ export default class StripesCore extends Component {
config={config}
actionNames={this.actionNames}
disableAuth={(config && config.disableAuth) || false}
{...this.props}
{...props}
/>
);
}
Expand Down
23 changes: 22 additions & 1 deletion test/bigtest/helpers/setup-application.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,37 @@ export default function setupApplication({
disableAuth = true,
modules = [],
translations = {},
permissions = {},
stripesConfig,
mirageOptions,
scenarios
} = {}) {
beforeEach(async function () {
const initialState = {};

// when auth is disabled, add a fake user to the store
if (disableAuth) {
initialState.okapi = {
token: 'test',
currentUser: {
id: 'test',
username: 'testuser',
firstName: 'Test',
lastName: 'User',
email: '[email protected]',
addresses: [],
servicePoints: []
},
currentPerms: permissions
};
}

// mount the app
this.app = await setupAppForTesting(App, {
mountId: 'testing-root',

props: {
disableAuth
initialState
},

setup: () => {
Expand Down

0 comments on commit b5e678c

Please sign in to comment.