/*
 * Copyright © 2016-2018 European Support Limited
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
import deepFreeze from 'deep-freeze';

import { cloneAndSet } from '../../test-utils/Util.js';
import store from 'sdc-app/AppStore.js';
import errorResponseHandler from 'nfvo-utils/ErrorResponseHandler.js';
import { typeEnum as modalType } from 'nfvo-components/modal/GlobalModalConstants.js';

describe('Error Response Handler Util', () => {
    beforeEach(function() {
        deepFreeze(store.getState());
    });

    it('validating error in policyException', () => {
        let textStatus = '',
            errorThrown = '';
        let xhr = {
            data: {
                requestError: {
                    policyException: {
                        messageId: 'SVC4122',
                        text: 'Error: Invalid data.'
                    }
                }
            }
        };
        deepFreeze(xhr);

        const errorNotification = {
            title: 'Error: SVC4122',
            msg: 'Error: Invalid data.',
            type: modalType.ERROR
        };

        const expectedStore = cloneAndSet(
            store.getState(),
            'modal',
            errorNotification
        );

        errorResponseHandler(xhr, textStatus, errorThrown);

        expect(store.getState()).toEqual(expectedStore);
    });

    it('validating error in serviceException with variables', () => {
        let textStatus = '',
            errorThrown = '';
        let xhr = {
            data: {
                requestError: {
                    serviceException: {
                        messageId: 'SVC4122',
                        text: "Error: Invalid artifact type '%1'.",
                        variables: ['newType']
                    }
                }
            }
        };
        deepFreeze(xhr);

        const errorNotification = {
            title: 'Error: SVC4122',
            msg: 'Error: Invalid artifact type newType.',
            type: modalType.ERROR
        };

        const expectedStore = cloneAndSet(
            store.getState(),
            'modal',
            errorNotification
        );

        errorResponseHandler(xhr, textStatus, errorThrown);

        expect(store.getState()).toEqual(expectedStore);
    });

    it('validating error in response', () => {
        let textStatus = '',
            errorThrown = '';
        let xhr = {
            data: {
                status: 'AA',
                message: 'Error: Invalid data.'
            }
        };
        deepFreeze(xhr);

        const errorNotification = {
            title: 'AA',
            msg: 'Error: Invalid data.',
            type: modalType.ERROR
        };

        const expectedStore = cloneAndSet(
            store.getState(),
            'modal',
            errorNotification
        );

        errorResponseHandler(xhr, textStatus, errorThrown);

        expect(store.getState()).toEqual(expectedStore);
    });

    it('validating error in request', () => {
        let textStatus = '',
            errorThrown = '';
        let xhr = {
            statusText: '500',
            responseText: 'Internal server error.'
        };
        deepFreeze(xhr);

        const errorNotification = {
            title: '500',
            msg: 'Internal server error.',
            type: modalType.ERROR
        };

        const expectedStore = cloneAndSet(
            store.getState(),
            'modal',
            errorNotification
        );

        errorResponseHandler(xhr, textStatus, errorThrown);

        expect(store.getState()).toEqual(expectedStore);
    });
});
