import oAuthServerReducer, { initialState } from '../../../store/reducers/oAuthServer.reducer';
import {
    FETCH_OAUTH_SERVER_START,
    FETCH_OAUTH_SERVER_SUCCESS,
    FETCH_OAUTH_SERVER_SCHEMA_START,
    FETCH_OAUTH_SERVER_SCHEMA_SUCCESS,
    SAVE_OAUTH_SERVER_START,
    SAVE_OAUTH_SERVER_SUCCESS,
    UPDATE_OAUTH_SERVER_START,
    UPDATE_OAUTH_SERVER_SUCCESS,
    DELETE_OAUTH_SERVER_START,
    DELETE_OAUTH_SERVER_SUCCESS,
} from '../../../store/constants';

import touchedReducerProps from '../../../helpers/touchedReducerProperties';
import getRandomString from '../../../helpers/getRandomString';

describe('oAuthServerReducer', () => {
    describe('Default', () => {
        const result = oAuthServerReducer(initialState, {});

        it('returns the initial state by default', () => {
            expect(result).toEqual(initialState);
        });

        it('has only change exact amount of reducer properties', () => {
            expect(touchedReducerProps(result)).toBe(3);
        });
    });

    describe('FETCH_OAUTH_SERVER_SCHEMA_START', () => {
        const result = oAuthServerReducer({}, { type: FETCH_OAUTH_SERVER_SCHEMA_START });

        it('returns fetching oauth servers starts state', () => {
            expect(result.isFetching).toEqual(true);
        });

        it('has only change exact amount of reducer properties', () => {
            expect(touchedReducerProps(result)).toBe(1);
        });
    });

    describe('FETCH_OAUTH_SERVER_SCHEMA_SUCCESS', () => {
        const payload = getRandomString();
        const result = oAuthServerReducer({}, { type: FETCH_OAUTH_SERVER_SCHEMA_SUCCESS, payload });

        it('returns fetching oauth server final state with received info', () => {
            expect(result.isFetching).toEqual(false);
            expect(result.oAuthServerSchema).toEqual(payload);
        });

        it('has only change exact amount of reducer properties', () => {
            expect(touchedReducerProps(result)).toBe(2);
        });
    });

    describe('SAVE_OAUTH_SERVER_START', () => {
        const initialState = { isFetching: false };
        const result = oAuthServerReducer(initialState, { type: SAVE_OAUTH_SERVER_START });

        it('sets the isFetching state to true', () => {
            expect(result.isFetching).toEqual(true);
        });

        it('changes only the required reducer properties', () => {
            expect(touchedReducerProps(result)).toBe(1);
        });
    });

    describe('UPDATE_OAUTH_SERVER_START', () => {
        const initialState = { isFetching: false };
        const result = oAuthServerReducer(initialState, { type: UPDATE_OAUTH_SERVER_START });

        it('sets the isFetching state to true', () => {
            expect(result.isFetching).toEqual(true);
        });

        it('changes only the required reducer properties', () => {
            expect(touchedReducerProps(result)).toBe(1);
        });
    });

    describe('DELETE_OAUTH_SERVER_START', () => {
        const initialState = { isFetching: false };
        const result = oAuthServerReducer(initialState, { type: DELETE_OAUTH_SERVER_START });

        it('sets the isFetching state to true', () => {
            expect(result.isFetching).toEqual(true);
        });

        it('changes only the required reducer properties', () => {
            expect(touchedReducerProps(result)).toBe(1);
        });
    });

    describe('SAVE_OAUTH_SERVER_SUCCESS', () => {
        const initialState = { isFetching: true };
        const result = oAuthServerReducer(initialState, { type: SAVE_OAUTH_SERVER_SUCCESS });

        it('sets the isFetching state to true', () => {
            expect(result.isFetching).toEqual(false);
        });

        it('changes only the required reducer properties', () => {
            expect(touchedReducerProps(result)).toBe(1);
        });
    });

    describe('UPDATE_OAUTH_SERVER_SUCCESS', () => {
        const initialState = { isFetching: true };
        const result = oAuthServerReducer(initialState, { type: UPDATE_OAUTH_SERVER_SUCCESS });

        it('sets the isFetching state to true', () => {
            expect(result.isFetching).toEqual(false);
        });

        it('changes only the required reducer properties', () => {
            expect(touchedReducerProps(result)).toBe(1);
        });
    });

    describe('DELETE_OAUTH_SERVER_SUCCESS', () => {
        const initialState = { isFetching: true };
        const result = oAuthServerReducer(initialState, { type: DELETE_OAUTH_SERVER_SUCCESS });

        it('sets the isFetching state to true', () => {
            expect(result.isFetching).toEqual(false);
        });

        it('changes only the required reducer properties', () => {
            expect(touchedReducerProps(result)).toBe(1);
        });
    });

});

@@ -424,16 +424,40 @@
 UCCESS,%0A
+    CLEAR_OAUTH_SERVER,%0A
 %7D from '
@@ -4817,12 +4817,393 @@
    %7D);%0A%0A
+    describe('CLEAR_OAUTH_SERVER', () =%3E %7B%0A        const result = oAuthServerReducer(%7B%7D, %7B type: CLEAR_OAUTH_SERVER %7D);%0A%0A        it('clear the OAuthServer object', () =%3E %7B%0A            expect(result.oAuthServer).toEqual(%7B%7D);%0A        %7D);%0A%0A        it('changes only the required reducer properties', () =%3E %7B%0A            expect(touchedReducerProps(result)).toBe(1);%0A        %7D);%0A    %7D);%0A
 %7D);%0A

edit reducer unit test