Commit 260638f2 authored by Leonardo Menezes's avatar Leonardo Menezes
Browse files

append host param when connecting to a host

parent 1be49ccf
Loading
Loading
Loading
Loading
+8 −18
Original line number Diff line number Diff line
@@ -258,18 +258,8 @@ angular.module('cerebro').controller('ConnectController', [
    $scope.connect = function(host, username, password) {
      if (host) {
        $scope.connecting = true;
        DataService.setHost(
          host,
          username,
          password,
          function(response) {
        DataService.setHost(host, username, password);
        $location.path('/overview');
          },
          function(response) {
            $scope.connecting = false;
            AlertService.error('Error connecting to ' + host, response);
          }
        );
      }
    };

@@ -1424,14 +1414,18 @@ angular.module('cerebro').factory('DataService', ['$rootScope', '$timeout',
      return host;
    };

    this.setHost = function(newHost, newUsername, newPassword, success, error) {
    this.setHost = function(newHost, newUsername, newPassword) {
      host = newHost;
      username = newUsername;
      password = newPassword;
      $location.search('host', newHost);
      RefreshService.refresh();
      success();
    };

    if ($location.search().host) {
      this.setHost($location.search().host);
    }

    // Navbar
    this.getNavbarData = function(success, error) {
      request('/navbar', {}, success, error);
@@ -1568,10 +1562,6 @@ angular.module('cerebro').factory('DataService', ['$rootScope', '$timeout',
      $http(config).success(success).error(error);
    };

    if ($location.search().location) {
      this.setHost($location.search().location);
    }

    return this;

  }
+2 −12
Original line number Diff line number Diff line
@@ -20,18 +20,8 @@ angular.module('cerebro').controller('ConnectController', [
    $scope.connect = function(host, username, password) {
      if (host) {
        $scope.connecting = true;
        DataService.setHost(
          host,
          username,
          password,
          function(response) {
        DataService.setHost(host, username, password);
        $location.path('/overview');
          },
          function(response) {
            $scope.connecting = false;
            AlertService.error('Error connecting to ' + host, response);
          }
        );
      }
    };

+6 −6
Original line number Diff line number Diff line
@@ -22,14 +22,18 @@ angular.module('cerebro').factory('DataService', ['$rootScope', '$timeout',
      return host;
    };

    this.setHost = function(newHost, newUsername, newPassword, success, error) {
    this.setHost = function(newHost, newUsername, newPassword) {
      host = newHost;
      username = newUsername;
      password = newPassword;
      $location.search('host', newHost);
      RefreshService.refresh();
      success();
    };

    if ($location.search().host) {
      this.setHost($location.search().host);
    }

    // Navbar
    this.getNavbarData = function(success, error) {
      request('/navbar', {}, success, error);
@@ -166,10 +170,6 @@ angular.module('cerebro').factory('DataService', ['$rootScope', '$timeout',
      $http(config).success(success).error(error);
    };

    if ($location.search().location) {
      this.setHost($location.search().location);
    }

    return this;

  }
+4 −35
Original line number Diff line number Diff line
@@ -46,58 +46,27 @@ describe('ConnectController', function() {

  describe('connect', function() {
    it('connects to valid host', function() {
      this.DataService.setHost = function(host, username, password, success, error) {
        success();
      };
      spyOn(this.DataService, "setHost").andCallThrough();
      spyOn(this.DataService, "setHost").andReturn();
      spyOn(this.$location, 'path').andReturn(true);
      this.scope.connect('http://localhost:9200');
      expect(this.DataService.setHost).toHaveBeenCalledWith(
        'http://localhost:9200',
        undefined,
        undefined,
        jasmine.any(Function),
        jasmine.any(Function)
        'http://localhost:9200', undefined, undefined
      );
      expect(this.$location.path).toHaveBeenCalledWith('/overview');
      expect(this.scope.connecting).toEqual(true);
    });

    it('connects to valid host passing username/password', function() {
      this.DataService.setHost = function(host, username, password, success, error) {
        success();
      };
      spyOn(this.DataService, "setHost").andCallThrough();
      spyOn(this.DataService, "setHost").andReturn();
      spyOn(this.$location, 'path').andReturn(true);
      this.scope.connect('http://localhost:9200', 'admin', '1234');
      expect(this.DataService.setHost).toHaveBeenCalledWith(
        'http://localhost:9200',
        'admin',
        '1234',
        jasmine.any(Function),
        jasmine.any(Function)
        '1234'
      );
      expect(this.$location.path).toHaveBeenCalledWith('/overview');
    });

    it('fails attempting to connect', function() {
      this.DataService.setHost = function(host, username, password, success, error) {
        error();
      };
      spyOn(this.DataService, "setHost").andCallThrough();
      spyOn(this.AlertService, "error").andReturn();
      this.scope.connect('http://localhost:9200', 'admin', '1234');
      expect(this.DataService.setHost).toHaveBeenCalledWith(
        'http://localhost:9200',
        'admin',
        '1234',
        jasmine.any(Function),
        jasmine.any(Function)
      );
      expect(this.scope.connecting).toEqual(false);
      expect(this.AlertService.error).toHaveBeenCalledWith('Error connecting to http://localhost:9200', undefined);
    });

  })

});