Skip to content

Commit

Permalink
Fix spec for generic object custom button endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
lgalis committed Jan 2, 2018
1 parent 432fb64 commit c4fa865
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ describe('dialogUserController', function() {

spyOn(dialogFieldRefreshService, 'refreshField');
spyOn(miqService, 'miqAjaxButton');
spyOn(miqService, 'redirectBack');
spyOn(miqService, 'sparkleOn');
spyOn(miqService, 'sparkleOff');

Expand Down Expand Up @@ -90,15 +91,18 @@ describe('dialogUserController', function() {

context('when the submit endpoint deals with generic objects', function() {
beforeEach(inject(function(_$controller_) {
$controller = _$controller_('dialogUserController', {
$controller = _$controller_('dialogUserController', {
API: API,
dialogFieldRefreshService: dialogFieldRefreshService,
miqService: miqService,
dialogId: '1234',
apiSubmitEndpoint: 'generic_objects',
apiSubmitEndpoint: 'service/explorer',
apiAction: 'custom_action',
cancelEndpoint: 'cancel endpoint',
finishSubmitEndpoint: 'finish submit endpoint',
resourceActionId: '789',
targetId: '987',
targetType: 'targettype',
});

$controller.setDialogData({data: {field1: 'field1'}});
Expand All @@ -110,17 +114,15 @@ describe('dialogUserController', function() {
$controller.submitButtonClicked();

setTimeout(function() {
expect(API.post).toHaveBeenCalledWith('generic_objects', {
action: 'custom_action', parameters: {field1: 'field1'}
});
expect(API.post).toHaveBeenCalledWith('service/explorer', {
field1: 'field1', action: 'custom_action'}, {skipErrors: [400]});
done();
});
});
});

context('when the API call succeeds', function() {
beforeEach(function() {
spyOn(miqService, 'redirectBack');
spyOn(API, 'post').and.returnValue(Promise.resolve('awesome'));
});

Expand Down Expand Up @@ -159,7 +161,6 @@ describe('dialogUserController', function() {
context('when the API call fails', function() {
beforeEach(function() {
var rejectionData = {data: {error: {message: "Failed! -One,Two"}}};
spyOn(miqService, 'redirectBack');
spyOn(API, 'post').and.returnValue(Promise.reject(rejectionData));
spyOn(window, 'clearFlash');
spyOn(window, 'add_flash');
Expand Down
4 changes: 2 additions & 2 deletions spec/services/dialog_local_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,8 @@
:force_old_dialog_use => false,
:api_submit_endpoint => "/api/generic_objects/123",
:api_action => "custom-button-name",
:finish_submit_endpoint => "/generic_object/show_list",
:cancel_endpoint => "/generic_object/show_list"
:finish_submit_endpoint => "/service/explorer",
:cancel_endpoint => "/service/explorer"
)
end
end
Expand Down

0 comments on commit c4fa865

Please sign in to comment.