Commit e8587e51 authored by Leonardo Menezes's avatar Leonardo Menezes
Browse files

fixes alias removal

closes #54
parent d995c1b7
Loading
Loading
Loading
Loading
+9 −1
Original line number Diff line number Diff line
@@ -135,7 +135,15 @@ angular.module('cerebro').controller('AliasesController', ['$scope',
      var error = function(body) {
        AlertService.error('Error while updating aliases', body);
      };
      DataService.updateAliases($scope.changes, success, error);
      var changes = $scope.changes.map(function(a) {
        if (a.remove) {
          var alias = a.remove;
          return {remove: {index: alias.index, alias: alias.alias}};
        } else {
          return a;
        }
      });
      DataService.updateAliases(changes, success, error);
    };

    $scope.loadAliases = function() {
+9 −1
Original line number Diff line number Diff line
@@ -53,7 +53,15 @@ angular.module('cerebro').controller('AliasesController', ['$scope',
      var error = function(body) {
        AlertService.error('Error while updating aliases', body);
      };
      DataService.updateAliases($scope.changes, success, error);
      var changes = $scope.changes.map(function(a) {
        if (a.remove) {
          var alias = a.remove;
          return {remove: {index: alias.index, alias: alias.alias}};
        } else {
          return a;
        }
      });
      DataService.updateAliases(changes, success, error);
    };

    $scope.loadAliases = function() {
+25 −0
Original line number Diff line number Diff line
@@ -109,6 +109,31 @@ describe('AliasesController', function() {
      expect(this.scope.loadAliases).toHaveBeenCalled();
      expect(this.scope.changes).toEqual([]);
    });
    it('transforms remove operations to right format', function () {
      var response = 'all good!';
      this.DataService.updateAliases = function(changes, success, error) {
        success(response)
      };
      spyOn(this.DataService, 'updateAliases').andCallThrough(true);
      spyOn(this.scope, 'loadAliases').andReturn(true);
      spyOn(this.AlertService, 'success').andReturn(true);
      this.scope.changes = [
          {remove: {index: 'a', alias: 'b', other: 'ko'}},
          {add: {index: 'a2', alias: 'b2', other: 'ok'}}
        ];
      this.scope.saveChanges();
      expect(this.DataService.updateAliases).toHaveBeenCalledWith(
        [
          {remove: {index: 'a', alias: 'b'}},
          {add: {index: 'a2', alias: 'b2', other: 'ok'}},
        ],
        jasmine.any(Function),
        jasmine.any(Function)
      );
      expect(this.AlertService.success).toHaveBeenCalledWith('Aliases successfully updated', response);
      expect(this.scope.loadAliases).toHaveBeenCalled();
      expect(this.scope.changes).toEqual([]);
    });
    it('handles failure while saving changes', function () {
      var response = 'not good!';
      this.DataService.updateAliases = function(changes, success, error) {