<commit_before>'use strict';

describe('filters', function () {

  var $filter;
  var settings;

  beforeEach(module('uchiwa'));
  beforeEach(inject(function (_$filter_, _settings_) {
    $filter = _$filter_;
    settings = _settings_;
  }));

  describe('arrayLength', function () {

    it('should return 0 if null', inject(function (arrayLengthFilter) {
      expect(arrayLengthFilter(null)).toEqual(0);
    }));

    it('should return 0 if not an array', inject(function (arrayLengthFilter) {
      expect(arrayLengthFilter('string')).toEqual(0);
    }));

    it('should return proper array length', inject(function (arrayLengthFilter) {
      expect(arrayLengthFilter([0, 1, 2])).toEqual(3);
    }));

  });

  describe('arrayToString', function () {

    it('should return 0 if null', inject(function (arrayToStringFilter) {
      expect(arrayToStringFilter(null)).toEqual('');
    }));

    it('should return 0 if not an array', inject(function (arrayToStringFilter) {
      expect(arrayToStringFilter('string')).toEqual('string');
    }));

    it('should return proper array length', inject(function (arrayToStringFilter) {
      expect(arrayToStringFilter([0, 1, 2])).toEqual('0 1 2');
    }));

  });

  describe('buildEvents', function () {

    it('should not accept anything else than an array', inject(function (buildEventsFilter) {
      expect(buildEventsFilter('string')).toEqual('string');
      expect(buildEventsFilter({})).toEqual({});
    }));

    it('handles missing check OR client objects', inject(function (buildEventsFilter) {
      var events = [
        { check: { source: 'foo' }},
        { client: {name: 'baz' }}
      ];
      var expectedEvents = [
        { check: { source: 'foo'}, sourceName: 'foo'},
        { check: {}, client: {name: 'baz'}, sourceName: 'baz'}
      ];
      expect(buildEventsFilter(events)).toEqual(expectedEvents);
    }));

    it('handles missing check AND client objects', inject(function (buildEventsFilter) {
      var events = [{}];
      var expectedEvents = [{sourceName: 'unknown'}];
      expect(buildEventsFilter(events)).toEqual(expectedEvents);
    }));

    it('should add sourceName properties', inject(function (buildEventsFilter) {
      var events = [
        { check: { source: 'foo'}, client: { name: 'bar'}},
        { check: { name: 'qux'}, client: {name: 'baz'}}
      ];
      var expectedEvents = [
        { check: { source: 'foo'}, client: { name: 'bar'}, sourceName: 'foo'},
        { check: { name: 'qux'}, client: {name: 'baz'}, sourceName: 'baz'}
      ];
      expect(buildEventsFilter(events)).toEqual(expectedEvents);
    }));

  });

  describe('buildStashes', function () {

    it('should not accept anything else than an array', inject(function (buildStashesFilter) {
      expect(buildStashesFilter('string')).toEqual('string');
      expect(buildStashesFilter({})).toEqual({});
    }));

    it('should add client & check properties', inject(function (buildStashesFilter) {
      var stashes = [
        {path: 'silence/foo/bar'},
        {path: 'silence/'},
        {path: 'silence/baz'}
      ];
      var expectedStashes = [
        {client: 'foo', check: 'bar', path: 'silence/foo/bar'},
        {client: null, check: null, path: 'silence/'},
        {client: 'baz', check: null, path: 'silence/baz'}
      ];
      expect(buildStashesFilter(stashes)).toEqual(expectedStashes);
    }));

  });

  describe('displayObject', function () {

    it('should display object', inject(function (displayObjectFilter) {
      expect(displayObjectFilter('test')).toBe('test');
      expect(displayObjectFilter(['test', 'test1', 'test2'])).toBe('test, test1, test2');
      expect(displayObjectFilter({key: 'value'})).toEqual({key: 'value'});
    }));

  });

  describe('getTimestamp', function () {

    it('should convert epoch to human readable date', inject(function (getTimestampFilter) {
      expect(getTimestampFilter('test')).toBe('test');
      expect(getTimestampFilter(1)).toBe(1);
      expect(getTimestampFilter(1410908218)).toBe(moment.utc('2014-09-16 22:56:58', 'YYYY-MM-DD HH:mm:ss').local().format('YYYY-MM-DD HH:mm:ss'));
    }));

  });

  describe('getExpireTimestamp', function () {

    it('should convert epoch to human readable date', inject(function (getExpireTimestampFilter) {
      expect(getExpireTimestampFilter('test')).toBe('Unknown');
      expect(getExpireTimestampFilter(900, 1410908218)).toBe(moment.utc('2014-09-16 23:11:58').local().format('YYYY-MM-DD HH:mm:ss'));
      expect(getExpireTimestampFilter(-1, 1410908218)).toBe('Never');
    }));

  });

  describe('encodeURIComponent', function () {

    it('should encode URI', inject(function (encodeURIComponentFilter) {<commit_msg>Fix tests with newer getExpireTimestamp function<commit_after>'use strict';

describe('filters', function () {

  var $filter;
  var settings;

  beforeEach(module('uchiwa'));
  beforeEach(inject(function (_$filter_, _settings_) {
    $filter = _$filter_;
    settings = _settings_;
  }));

  describe('arrayLength', function () {

    it('should return 0 if null', inject(function (arrayLengthFilter) {
      expect(arrayLengthFilter(null)).toEqual(0);
    }));

    it('should return 0 if not an array', inject(function (arrayLengthFilter) {
      expect(arrayLengthFilter('string')).toEqual(0);
    }));

    it('should return proper array length', inject(function (arrayLengthFilter) {
      expect(arrayLengthFilter([0, 1, 2])).toEqual(3);
    }));

  });

  describe('arrayToString', function () {

    it('should return 0 if null', inject(function (arrayToStringFilter) {
      expect(arrayToStringFilter(null)).toEqual('');
    }));

    it('should return 0 if not an array', inject(function (arrayToStringFilter) {
      expect(arrayToStringFilter('string')).toEqual('string');
    }));

    it('should return proper array length', inject(function (arrayToStringFilter) {
      expect(arrayToStringFilter([0, 1, 2])).toEqual('0 1 2');
    }));

  });

  describe('buildEvents', function () {

    it('should not accept anything else than an array', inject(function (buildEventsFilter) {
      expect(buildEventsFilter('string')).toEqual('string');
      expect(buildEventsFilter({})).toEqual({});
    }));

    it('handles missing check OR client objects', inject(function (buildEventsFilter) {
      var events = [
        { check: { source: 'foo' }},
        { client: {name: 'baz' }}
      ];
      var expectedEvents = [
        { check: { source: 'foo'}, sourceName: 'foo'},
        { check: {}, client: {name: 'baz'}, sourceName: 'baz'}
      ];
      expect(buildEventsFilter(events)).toEqual(expectedEvents);
    }));

    it('handles missing check AND client objects', inject(function (buildEventsFilter) {
      var events = [{}];
      var expectedEvents = [{sourceName: 'unknown'}];
      expect(buildEventsFilter(events)).toEqual(expectedEvents);
    }));

    it('should add sourceName properties', inject(function (buildEventsFilter) {
      var events = [
        { check: { source: 'foo'}, client: { name: 'bar'}},
        { check: { name: 'qux'}, client: {name: 'baz'}}
      ];
      var expectedEvents = [
        { check: { source: 'foo'}, client: { name: 'bar'}, sourceName: 'foo'},
        { check: { name: 'qux'}, client: {name: 'baz'}, sourceName: 'baz'}
      ];
      expect(buildEventsFilter(events)).toEqual(expectedEvents);
    }));

  });

  describe('buildStashes', function () {

    it('should not accept anything else than an array', inject(function (buildStashesFilter) {
      expect(buildStashesFilter('string')).toEqual('string');
      expect(buildStashesFilter({})).toEqual({});
    }));

    it('should add client & check properties', inject(function (buildStashesFilter) {
      var stashes = [
        {path: 'silence/foo/bar'},
        {path: 'silence/'},
        {path: 'silence/baz'}
      ];
      var expectedStashes = [
        {client: 'foo', check: 'bar', path: 'silence/foo/bar'},
        {client: null, check: null, path: 'silence/'},
        {client: 'baz', check: null, path: 'silence/baz'}
      ];
      expect(buildStashesFilter(stashes)).toEqual(expectedStashes);
    }));

  });

  describe('displayObject', function () {

    it('should display object', inject(function (displayObjectFilter) {
      expect(displayObjectFilter('test')).toBe('test');
      expect(displayObjectFilter(['test', 'test1', 'test2'])).toBe('test, test1, test2');
      expect(displayObjectFilter({key: 'value'})).toEqual({key: 'value'});
    }));

  });

  describe('getTimestamp', function () {

    it('should convert epoch to human readable date', inject(function (getTimestampFilter) {
      expect(getTimestampFilter('test')).toBe('test');
      expect(getTimestampFilter(1)).toBe(1);
      expect(getTimestampFilter(1410908218)).toBe(moment.utc('2014-09-16 22:56:58', 'YYYY-MM-DD HH:mm:ss').local().format('YYYY-MM-DD HH:mm:ss'));
    }));

  });

  describe('getExpireTimestamp', function () {

    it('should convert epoch to human readable date', inject(function (getExpireTimestampFilter) {
      expect(getExpireTimestampFilter('test')).toBe('Unknown');
      expect(getExpireTimestampFilter(900)).toMatch('\\d\\d\\d\\d-\\d\\d-');
      expect(getExpireTimestampFilter(-1)).toBe('Never');
    }));

  });

  describe('encodeURIComponent', function () {

    it('should encode URI', inject(function (encodeURIComponentFilter) {
{'fraction_non_alphanumeric': 0.17554492291334398, 'fraction_numerical': 0.014247740563530037, 'mean_word_length': 3.8112531969309464, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6688930', 'n_tokens_mistral': 2829, 'n_tokens_neox': 2742, 'n_words': 571}