mirror of
				https://github.com/elyby/accounts-frontend.git
				synced 2025-05-31 14:11:58 +05:30 
			
		
		
		
	Decouple auth states from routing redux state
This commit is contained in:
		@@ -27,12 +27,11 @@ describe('ActivationState', () => {
 | 
			
		||||
            context.getState.returns({
 | 
			
		||||
                user: {
 | 
			
		||||
                    isActive: false
 | 
			
		||||
                },
 | 
			
		||||
                routing: {
 | 
			
		||||
                    location: {pathname: expectedPath}
 | 
			
		||||
                }
 | 
			
		||||
            });
 | 
			
		||||
 | 
			
		||||
            context.getCurrentPath.returns(expectedPath);
 | 
			
		||||
 | 
			
		||||
            expectNavigate(mock, '/activation');
 | 
			
		||||
 | 
			
		||||
            state.enter(context);
 | 
			
		||||
@@ -43,12 +42,11 @@ describe('ActivationState', () => {
 | 
			
		||||
            context.getState.returns({
 | 
			
		||||
                user: {
 | 
			
		||||
                    isActive: false
 | 
			
		||||
                },
 | 
			
		||||
                routing: {
 | 
			
		||||
                    location: {pathname: expectedPath}
 | 
			
		||||
                }
 | 
			
		||||
            });
 | 
			
		||||
 | 
			
		||||
            context.getCurrentPath.returns(expectedPath);
 | 
			
		||||
 | 
			
		||||
            expectNavigate(mock, expectedPath);
 | 
			
		||||
 | 
			
		||||
            state.enter(context);
 | 
			
		||||
 
 | 
			
		||||
@@ -30,10 +30,6 @@ describe('AuthFlow.functional', () => {
 | 
			
		||||
        flow.setStore(store);
 | 
			
		||||
 | 
			
		||||
        navigate = function navigate(url) { // emulates router behaviour
 | 
			
		||||
            state.routing = state.routing || {};
 | 
			
		||||
            state.routing.location = state.routing.location || {};
 | 
			
		||||
            state.routing.location.pathname = url;
 | 
			
		||||
 | 
			
		||||
            if (navigate.lastUrl !== url) {
 | 
			
		||||
                navigate.lastUrl = url;
 | 
			
		||||
                flow.handleRequest(url, navigate);
 | 
			
		||||
 
 | 
			
		||||
@@ -30,9 +30,7 @@ describe('OAuthState', () => {
 | 
			
		||||
                state: 'state'
 | 
			
		||||
            };
 | 
			
		||||
 | 
			
		||||
            context.getState.returns({
 | 
			
		||||
                routing: {location: {query}}
 | 
			
		||||
            });
 | 
			
		||||
            context.getQuery.returns(query);
 | 
			
		||||
 | 
			
		||||
            expectRun(
 | 
			
		||||
                mock,
 | 
			
		||||
@@ -52,9 +50,7 @@ describe('OAuthState', () => {
 | 
			
		||||
        it('should transition to complete state on success', () => {
 | 
			
		||||
            const promise = Promise.resolve();
 | 
			
		||||
 | 
			
		||||
            context.getState.returns({
 | 
			
		||||
                routing: {location: {query: {}}}
 | 
			
		||||
            });
 | 
			
		||||
            context.getQuery.returns({});
 | 
			
		||||
 | 
			
		||||
            mock.expects('run').returns(promise);
 | 
			
		||||
            expectState(mock, CompleteState);
 | 
			
		||||
 
 | 
			
		||||
@@ -25,12 +25,11 @@ describe('RecoverPasswordState', () => {
 | 
			
		||||
        it('should navigate to /recover-password', () => {
 | 
			
		||||
            const expectedPath = '/recover-password';
 | 
			
		||||
            context.getState.returns({
 | 
			
		||||
                user: {isGuest: true},
 | 
			
		||||
                routing: {
 | 
			
		||||
                    location: {pathname: expectedPath}
 | 
			
		||||
                }
 | 
			
		||||
                user: {isGuest: true}
 | 
			
		||||
            });
 | 
			
		||||
 | 
			
		||||
            context.getCurrentPath.returns(expectedPath);
 | 
			
		||||
 | 
			
		||||
            expectNavigate(mock, expectedPath);
 | 
			
		||||
 | 
			
		||||
            state.enter(context);
 | 
			
		||||
@@ -39,12 +38,11 @@ describe('RecoverPasswordState', () => {
 | 
			
		||||
        it('should navigate to /recover-password/key', () => {
 | 
			
		||||
            const expectedPath = '/recover-password/sasx5AS4d61';
 | 
			
		||||
            context.getState.returns({
 | 
			
		||||
                user: {isGuest: true},
 | 
			
		||||
                routing: {
 | 
			
		||||
                    location: {pathname: expectedPath}
 | 
			
		||||
                }
 | 
			
		||||
                user: {isGuest: true}
 | 
			
		||||
            });
 | 
			
		||||
 | 
			
		||||
            context.getCurrentPath.returns(expectedPath);
 | 
			
		||||
 | 
			
		||||
            expectNavigate(mock, expectedPath);
 | 
			
		||||
 | 
			
		||||
            state.enter(context);
 | 
			
		||||
 
 | 
			
		||||
@@ -7,6 +7,8 @@ export function bootstrap() {
 | 
			
		||||
        getState: sinon.stub(),
 | 
			
		||||
        run() {},
 | 
			
		||||
        setState() {},
 | 
			
		||||
        getCurrentPath: sinon.stub(),
 | 
			
		||||
        getQuery: sinon.stub(),
 | 
			
		||||
        navigate() {}
 | 
			
		||||
    };
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user