Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4951 from ZitaNemeckova/fix_error_message_god_button
Catch 400 error and display it in flash message in GOD
- Loading branch information
Showing
2 changed files
with
110 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 70 additions & 0 deletions
70
spec/javascripts/components/generic_object_definition/main-custom-button-form_spec.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
describe('main-custom-button-form-component', function() { | ||
var $componentController, vm, miqService, API, $scope; | ||
beforeEach(module('ManageIQ')); | ||
beforeEach(inject(function (_$componentController_, _API_, _$httpBackend_, _miqService_, $rootScope, $q) { | ||
$componentController = _$componentController_; | ||
API = _API_; | ||
miqService = _miqService_; | ||
$scope = $rootScope.$new(); | ||
$httpBackend = _$httpBackend_; | ||
|
||
var bindings = {genericObjectDefinitionRecordId: '1', customButtonGroupRecordId: '2', customButtonRecordId: '3', redirectUrl: '/redirect/url'}; | ||
vm = $componentController("mainCustomButtonFormComponent", null, bindings); | ||
var deferred = $q.defer(); | ||
spyOn(API, 'get').and.callFake(function() {return deferred.promise;}); | ||
var domainsResponse = { | ||
data:{ | ||
distinct_instances_across_domains: ["Automation", "Event", "GenericObject", "MiqEvent", "Request", "parse_automation_request", "parse_event_stream", "parse_provider_category"] | ||
} | ||
}; | ||
$httpBackend.whenGET('/generic_object_definition/retrieve_distinct_instances_across_domains').respond(domainsResponse); | ||
vm.$onInit(); | ||
$httpBackend.flush(); | ||
})); | ||
|
||
describe('#saveClick', function() { | ||
beforeEach(function(){ | ||
spyOn(window, 'add_flash'); | ||
}); | ||
|
||
it('catch 400 and call add_flash if error is name/description taken', function(done) { | ||
var rejectionData = {status: 400, data: {error: {message: "Name has already been taken, Description has already been taken"}}}; | ||
spyOn(API, 'put').and.returnValue(Promise.reject(rejectionData)); | ||
vm.saveClicked() | ||
.then( function() { | ||
expect(add_flash).toHaveBeenCalledWith("Name has already been taken", "error"); | ||
expect(add_flash).toHaveBeenCalledWith("Description has already been taken", "error"); | ||
done(); | ||
}) | ||
.catch(function() { | ||
expect(add_flash).toHaveBeenCalledWith("Name has already been taken", "error"); | ||
expect(add_flash).toHaveBeenCalledWith("Description has already been taken", "error"); | ||
|
||
done(); | ||
}); | ||
}); | ||
}); | ||
|
||
describe('#addClick', function() { | ||
beforeEach(function(){ | ||
spyOn(window, 'add_flash'); | ||
spyOn(miqService, 'handleFailure').and.callFake(function() {debugger;return Promise.reject()}); | ||
}); | ||
|
||
it('catch 400 and call add_flash', function(done) { | ||
var rejectionData = {status: 400, data: {error: {message: "Name has already been taken, Description has already been taken"}}}; | ||
spyOn(API, 'post').and.returnValue(Promise.reject(rejectionData)); | ||
vm.addClicked() | ||
.then( function() { | ||
expect(add_flash).toHaveBeenCalledWith("Name has already been taken", "error"); | ||
expect(add_flash).toHaveBeenCalledWith("Description has already been taken", "error"); | ||
done(); | ||
}) | ||
.catch(function () { | ||
expect(add_flash).toHaveBeenCalledWith("Name has already been taken", "error"); | ||
expect(add_flash).toHaveBeenCalledWith("Description has already been taken", "error"); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
}); |