'use strict';



describe('Service: DataSourceFilter', function() {

    beforeEach(angular.mock.module('DataManagement'));

    // load the service's module
    //beforeEach(angular.mock.module('brandDashboardApp'));

    // instantiate service
    var DataSourceFilter;
    beforeEach(inject(function($injector) {
        DataSourceFilter = $injector.get('DataSourceFilter');
    }));

    

    describe('getFilteringCallback()', function() {
        
        it('should return the correct filtering callback', function() {
            var enabledDataSources = ['call-center'];
            var filteringCallback = DataSourceFilter.getFilteringCallback(enabledDataSources);
            expect(filteringCallback.toString().replace(/\n|\t/gi, '')).to.be.eql('function (review){return review.review && review.review.channel && self.isCallCenterChannel(review.review.channel);}');
        });
    });

    describe('run()', function() {
        var reviews;

        beforeEach(function() {
            reviews = [{
                review: {
                    channel: 'amazon.com'
                }
            }, {
                review: {
                    channel: 'amazon.com'
                }
            }, {
                review: {
                    channel: 'companyName-call-center'
                }
            }];
        });
        it('should filter correctly reviews when enabled data source is only reviews', function(){
            var result;

            result=DataSourceFilter.run(reviews,['reviews']);
            expect(result.length).to.be.eql(2);
            expect(result).to.contain(reviews[0]);
            expect(result).to.contain(reviews[1]);
        });

        it('should filter correctly reviews when enabled data source is only call-center', function(){
            var result;

            result=DataSourceFilter.run(reviews,['call-center']);
            expect(result.length).to.be.eql(1);
            expect(result).to.contain(reviews[2]);
        });
        it('should filter correctly reviews when enabled data source are both call-center and reviews', function(){
            var result;

            result=DataSourceFilter.run(reviews,['call-center','reviews']);
            expect(result.length).to.be.eql(3);
            expect(result).to.contain(reviews[0]);
            expect(result).to.contain(reviews[1]);
            expect(result).to.contain(reviews[2]);
        });
    });



});