|
1 | 1 | RSpec.describe ServiceTemplateTerraformEnterprise do |
2 | | - let(:terraform_enterprise) { FactoryBot.create(:ems_terraform_enterprise) } |
3 | | - let(:configuration_script) { FactoryBot.create(:configuration_script_terraform_enterprise, :manager => terraform_enterprise) } |
4 | | - let(:service_dialog) { FactoryBot.create(:dialog) } |
5 | | - let(:provision_resource_action) { FactoryBot.create(:resource_action, :action => 'Provision') } |
| 2 | + let(:user) { FactoryBot.create(:user_with_email_and_group) } |
| 3 | + let(:terraform_enterprise) { FactoryBot.create(:ems_terraform_enterprise) } |
| 4 | + let(:configuration_script) { FactoryBot.create(:configuration_script_terraform_enterprise, :manager => terraform_enterprise) } |
| 5 | + let(:service_dialog) { FactoryBot.create(:dialog) } |
| 6 | + let(:provision_resource_action) { FactoryBot.create(:resource_action, :action => 'Provision') } |
6 | 7 | let(:catalog_item_options) do |
7 | 8 | { |
8 | 9 | :name => "Terraform Enterprise", |
|
11 | 12 | :display => "false", |
12 | 13 | :description => "a description", |
13 | 14 | :config_info => { |
14 | | - :configuration_script_id => configuration_script.id, |
15 | | - :provision => { |
| 15 | + :owner_email => user.email, |
| 16 | + :source_id => configuration_script.id, |
| 17 | + :provision => { |
16 | 18 | :fqname => provision_resource_action.fqname, |
17 | 19 | :dialog_id => service_dialog.id |
18 | 20 | } |
19 | 21 | } |
20 | 22 | } |
21 | 23 | end |
22 | 24 |
|
| 25 | + before { MiqDialog.seed } |
| 26 | + |
23 | 27 | describe ".create_catalog_item" do |
24 | 28 | it "creates and returns a terraform enterprise catalog item" do |
25 | | - service_template = described_class.create_catalog_item(catalog_item_options) |
| 29 | + service_template = described_class.create_catalog_item(catalog_item_options, user) |
26 | 30 |
|
27 | 31 | expect(service_template.name).to eq("Terraform Enterprise") |
28 | 32 | expect(service_template.service_resources.count).to eq(1) |
29 | 33 | expect(service_template.dialogs.first).to eq(service_dialog) |
30 | 34 | expect(service_template.resource_actions.pluck(:action)).to match_array(%w[Provision]) |
31 | | - expect(service_template.configuration_script).to eq(configuration_script) |
32 | 35 | expect(service_template.config_info).to eq(catalog_item_options[:config_info]) |
33 | 36 | end |
34 | 37 |
|
35 | 38 | it "raises an exception if configuration_script_id is missing" do |
36 | | - catalog_item_options[:config_info].delete(:configuration_script_id) |
| 39 | + catalog_item_options[:config_info].delete(:source_id) |
37 | 40 |
|
38 | | - expect { described_class.create_catalog_item(catalog_item_options) } |
39 | | - .to raise_error(StandardError, "Must provide a configuration_script_id") |
| 41 | + expect { described_class.create_catalog_item(catalog_item_options, user) } |
| 42 | + .to raise_error(StandardError, "Must provide a source_id") |
40 | 43 | end |
41 | 44 | end |
42 | 45 |
|
43 | 46 | describe "#update_catalog_item" do |
44 | | - let(:service_template) { ServiceTemplateTerraformEnterprise.create_catalog_item(catalog_item_options) } |
| 47 | + let(:service_template) { ServiceTemplateTerraformEnterprise.create_catalog_item(catalog_item_options, user) } |
45 | 48 | let(:new_configuration_script) { FactoryBot.create(:configuration_script_terraform_enterprise, :manager => terraform_enterprise) } |
46 | 49 |
|
47 | 50 | it "updates the service_template" do |
|
53 | 56 | :display => "false", |
54 | 57 | :description => "a description", |
55 | 58 | :config_info => { |
56 | | - :configuration_script_id => new_configuration_script.id, |
| 59 | + :source_id => new_configuration_script.id, |
57 | 60 | :provision => { |
58 | 61 | :fqname => provision_resource_action.fqname, |
59 | 62 | :dialog_id => service_dialog.id |
|
63 | 66 | ) |
64 | 67 |
|
65 | 68 | expect(service_template.reload).to have_attributes( |
66 | | - :name => "Updated Terraform Enterprise", |
67 | | - :configuration_script => new_configuration_script |
| 69 | + :name => "Updated Terraform Enterprise", |
| 70 | + :config_info => hash_including(:source_id => new_configuration_script.id) |
68 | 71 | ) |
69 | 72 | end |
70 | 73 | end |
|
0 commit comments