/*global availity, it, spyOn, inject, module, beforeEach, expect, describe */
describe('avExceptionAnalyticsProvider', function() {

  'use strict';

  var provider;
  var service;
  var $exceptionHandler;
  var $q;

  availity.mock.providerSpecHelper();

  beforeEach(module('availity'));

  beforeEach(module(function(avExceptionAnalyticsProvider, $exceptionHandlerProvider) {
    provider = avExceptionAnalyticsProvider;
    $exceptionHandlerProvider.mode('log');
  }));

  beforeEach(inject(function(avExceptionAnalytics, _$exceptionHandler_, _$q_) {
    service = avExceptionAnalytics;
    $exceptionHandler = _$exceptionHandler_;
    $q = _$q_;

    spyOn(service, 'trackEvent').and.callThrough();
    spyOn(service, 'onError').and.callThrough();
    spyOn(service, 'log').and.callFake(function(message) {
      return $q.when(message);
    });
  }));

  it('should be defined', function() {
    expect(provider.$get).toBeDefined();
    expect(provider.enabled).toBeDefined();
    expect(provider.setAppId).toBeDefined();
  });

  describe('avExceptionAnalytics', function() {

    var exception;

    beforeEach(function() {

      try {
        throw new Error('mock error');
      }catch(e) {
        exception = e;
      }

    });

    it('should track exception event', function() {

      $exceptionHandler(exception);
      expect(service.trackEvent).toHaveBeenCalled();
      expect(service.onError).toHaveBeenCalled();
      expect(service.log).toHaveBeenCalled();

      var message = service.log.calls.mostRecent().args[0];

      expect(message.errorName).toBe('Error');
      expect(message.errorMessage).toBe('mock error');
    });

  });

});

@@ -1647,16 +1647,336 @@
    %7D);%0A%0A
+    it('should not track rapid exceptions more than once', function() %7B%0A      $exceptionHandler(exception);%0A      $exceptionHandler(exception);%0A      expect(service.trackEvent.calls.count()).toEqual(2);%0A      expect(service.onError.calls.count()).toEqual(1);%0A      expect(service.log.calls.count()).toEqual(1);%0A    %7D);%0A%0A
   %7D);%0A%0A%7D

Add unit test