{"size": 3261, "ext": "js", "max_stars_repo_path": "app/scripts/modules/amazon/serverGroup/details/scalingProcesses/autoScalingProcess.service.spec.js", "max_stars_repo_name": "l1kw1d/deck", "max_stars_repo_stars_event_min_datetime": "2015-11-30T21:47:46.000Z", "max_stars_repo_stars_event_max_datetime": "2018-07-30T22:10:44.000Z", "max_issues_repo_path": "app/scripts/modules/amazon/serverGroup/details/scalingProcesses/autoScalingProcess.service.spec.js", "max_issues_repo_name": "l1kw1d/deck", "max_issues_repo_issues_event_min_datetime": "2016-02-11T14:45:14.000Z", "max_issues_repo_issues_event_max_datetime": "2016-10-11T13:44:10.000Z", "max_forks_repo_path": "app/scripts/modules/amazon/serverGroup/details/scalingProcesses/autoScalingProcess.service.spec.js", "max_forks_repo_name": "l1kw1d/deck", "max_forks_repo_forks_event_min_datetime": "2019-11-02T23:05:41.000Z", "max_forks_repo_forks_event_max_datetime": "2021-11-10T10:05:33.000Z"}
{"max_stars_count": 10, "max_issues_count": 13, "max_forks_count": 5, "avg_line_length": 35.8351648352, "max_line_length": 143, "alphanum_fraction": 0.634774609}
'use strict';

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

  var service;

  beforeEach(
    window.module(
      require('./autoScalingProcess.service')
    )
  );

  beforeEach(window.inject(function(autoScalingProcessService) {
    service = autoScalingProcessService;
  }));

  describe('normalizeScalingProcesses', function() {

    it ('returns an empty list if no asg or suspendedProcesses present on server group', function () {
      expect(service.normalizeScalingProcesses({})).toEqual([]);
      expect(service.normalizeScalingProcesses({ asg: {} })).toEqual([]);
    });

    it ('returns all processes normalized if suspendedProcesses is empty', function () {
      let asg = {
        suspendedProcesses: []
      };
      let normalized = service.normalizeScalingProcesses({ asg: asg });
      expect(normalized.length).toBe(8);
      expect(normalized.filter((process) => process.enabled).length).toBe(8);
      expect(normalized.map((process) => process.name)).toEqual(
        ['Launch', 'Terminate', 'AddToLoadBalancer', 'AlarmNotification', 'AZRebalance', 'HealthCheck', 'ReplaceUnhealthy', 'ScheduledActions']
      );
      expect(normalized.filter((process) => process.suspensionDate)).toEqual([]);
    });

    it ('builds suspension date for suspended processes', function () {
      let asg = {
        suspendedProcesses: [
          {
            processName: 'Launch',
            suspensionReason: 'User suspended at 2016-01-12T22:59:46Z'
          }
        ]
      };
      let normalized = service.normalizeScalingProcesses({ asg: asg });
      expect(normalized.length).toBe(8);
      expect(normalized.filter((process) => process.enabled).length).toBe(7);
      expect(normalized.map((process) => process.name)).toEqual(
        ['Launch', 'Terminate', 'AddToLoadBalancer', 'AlarmNotification', 'AZRebalance', 'HealthCheck', 'ReplaceUnhealthy', 'ScheduledActions']
      );
      expect(normalized.filter((process) => process.suspensionDate).length).toBe(1);
      expect(normalized.filter((p) => p.suspensionDate).map((p) => p.suspensionDate)).toEqual([1452639586000]);
    });
  });

  describe('getDisabledDate', function() {
    it ('returns null when server group is not disabled, regardless of suspended processes', function () {
      let asg = {
        suspendedProcesses: [
          {
            processName: 'AddToLoadBalancer',
            suspensionReason: 'User suspended at 2016-01-12T22:59:46Z'
          }
        ]
      };
      expect(service.getDisabledDate({asg:asg})).toBeNull();
    });

    it ('returns null when server group is disabled but suspended process for AddToLoadBalancer not present', function () {
      let asg = {
        suspendedProcesses: []
      };
      expect(service.getDisabledDate({isDisabled: true, asg:asg})).toBeNull();
    });

    it ('returns suspension date when server group is disabled and AddToLoadBalancer suspended', function () {
      let asg = {
        suspendedProcesses: [
          {
            processName: 'AddToLoadBalancer',
            suspensionReason: 'User suspended at 2016-01-12T22:59:46Z'
          }
        ]
      };
      expect(service.getDisabledDate({isDisabled: true, asg:asg})).toEqual(1452639586000);
    });
  });

});
