@@ -739,4 +739,64 @@ def init_dialog
739739 expect ( response ) . to have_http_status ( :bad_request )
740740 end
741741 end
742+
743+ context 'Create servide dialog from orchestration template' do
744+ let ( :ot ) do
745+ FactoryBot . create ( :orchestration_template_amazon_in_json ) . tap do |template |
746+ allow ( template ) . to receive ( :parameter_groups ) . and_return ( param_groups )
747+ allow ( template ) . to receive ( :tabs ) . and_return ( tabs ) if tabs . count > 0
748+ end
749+ end
750+
751+ let ( :param_groups ) { [ ] }
752+ let ( :tabs ) do
753+ [
754+ {
755+ :title => 'Tab 1' ,
756+ :stack_group => [
757+ OrchestrationTemplate ::OrchestrationParameter . new ( :label => 'Param 1' , :name => SecureRandom . hex , :data_type => 'string' ) ,
758+ OrchestrationTemplate ::OrchestrationParameter . new ( :label => 'Param 2' , :name => SecureRandom . hex , :data_type => 'string' )
759+ ]
760+ }
761+ ]
762+ end
763+
764+ it 'should create service dialog' do
765+ api_basic_authorize collection_action_identifier ( :service_dialogs , :create )
766+
767+ orchestration_template_dialog_request = {
768+ :action => 'orchestration_template_service_dialog' ,
769+ :resource => { :label => 'Foo' , :ot_id => ot . id }
770+ }
771+
772+ post ( api_service_dialogs_url , :params => orchestration_template_dialog_request )
773+ expect ( response ) . to have_http_status ( :ok )
774+ expect ( response . parsed_body [ 'results' ] [ 0 ] [ 'label' ] ) . to eq ( 'Foo' )
775+ expect ( response . parsed_body [ 'results' ] [ 0 ] [ 'buttons' ] ) . to eq ( 'submit,cancel' )
776+ end
777+
778+ it 'should fail whet ot_id is undefined' do
779+ api_basic_authorize collection_action_identifier ( :service_dialogs , :create )
780+
781+ orchestration_template_dialog_request = {
782+ :action => 'orchestration_template_service_dialog' ,
783+ :resource => { :label => 'Foo' }
784+ }
785+
786+ post ( api_service_dialogs_url , :params => orchestration_template_dialog_request )
787+ expect ( response ) . to have_http_status ( :bad_request )
788+ end
789+
790+ it 'should fail whet label is undefined' do
791+ api_basic_authorize collection_action_identifier ( :service_dialogs , :create )
792+
793+ orchestration_template_dialog_request = {
794+ :action => 'orchestration_template_service_dialog' ,
795+ :resource => { :ot_id => ot . id }
796+ }
797+
798+ post ( api_service_dialogs_url , :params => orchestration_template_dialog_request )
799+ expect ( response ) . to have_http_status ( :bad_request )
800+ end
801+ end
742802end
0 commit comments