Loading public/js/app.js +9 −1 Original line number Diff line number Diff line Loading @@ -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() { Loading src/app/components/aliases/controller.js +9 −1 Original line number Diff line number Diff line Loading @@ -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() { Loading tests/controllers/aliases.tests.js +25 −0 Original line number Diff line number Diff line Loading @@ -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) { Loading Loading
public/js/app.js +9 −1 Original line number Diff line number Diff line Loading @@ -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() { Loading
src/app/components/aliases/controller.js +9 −1 Original line number Diff line number Diff line Loading @@ -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() { Loading
tests/controllers/aliases.tests.js +25 −0 Original line number Diff line number Diff line Loading @@ -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) { Loading