From 5b30dad6e700fb77bd32c58f023b5eb19b3d8308 Mon Sep 17 00:00:00 2001 From: Zeeshan Gulzar Date: Tue, 26 Jun 2018 19:25:23 +0500 Subject: [PATCH 1/3] [MNO-1187] Added tenant_company_id into json response --- .../mno_enterprise/jpi/v1/admin/tenants/show.json.jbuilder | 1 + core/app/models/mno_enterprise/tenant.rb | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/api/app/views/mno_enterprise/jpi/v1/admin/tenants/show.json.jbuilder b/api/app/views/mno_enterprise/jpi/v1/admin/tenants/show.json.jbuilder index f9f8ba14c..ceee5d793 100644 --- a/api/app/views/mno_enterprise/jpi/v1/admin/tenants/show.json.jbuilder +++ b/api/app/views/mno_enterprise/jpi/v1/admin/tenants/show.json.jbuilder @@ -7,4 +7,5 @@ json.tenant do json.plugins_config_schema Hash(MnoEnterprise::PLUGINS_CONFIG_JSON_SCHEMA) json.app_management @tenant.metadata[:app_management] || "marketplace" json.organization_credit_management @tenant.metadata[:can_manage_organization_credit] + json.tenant_organization_id @tenant.tenant_company.id end diff --git a/core/app/models/mno_enterprise/tenant.rb b/core/app/models/mno_enterprise/tenant.rb index 2dff9ab37..48595ec2c 100644 --- a/core/app/models/mno_enterprise/tenant.rb +++ b/core/app/models/mno_enterprise/tenant.rb @@ -35,7 +35,7 @@ def self.type end def self.show - self.find.first + self.includes(:tenant_company).find.first end # == Instance Methods ===================================================== From 3f522f517a6a89fac92bf4119b5e1b32021e5017 Mon Sep 17 00:00:00 2001 From: Zeeshan Gulzar Date: Thu, 28 Jun 2018 18:57:26 +0500 Subject: [PATCH 2/3] [MNOE-1187] Fixed failed test cases --- .../jpi/v1/admin/account_transactions_controller_spec.rb | 4 ++-- .../mno_enterprise/jpi/v1/admin/tenants_controller_spec.rb | 5 +++-- .../mno_enterprise/jpi/v1/marketplace_controller_spec.rb | 2 +- api/spec/requests/mnoe/jpi/v1/admin/tenants_spec.rb | 2 +- core/lib/mno_enterprise/testing_support/factories/tenant.rb | 1 + core/spec/models/mno_enterprise/tenant_config_spec.rb | 6 +++--- 6 files changed, 11 insertions(+), 9 deletions(-) diff --git a/api/spec/controllers/mno_enterprise/jpi/v1/admin/account_transactions_controller_spec.rb b/api/spec/controllers/mno_enterprise/jpi/v1/admin/account_transactions_controller_spec.rb index 5ca7c11e2..b1be21e8f 100644 --- a/api/spec/controllers/mno_enterprise/jpi/v1/admin/account_transactions_controller_spec.rb +++ b/api/spec/controllers/mno_enterprise/jpi/v1/admin/account_transactions_controller_spec.rb @@ -34,7 +34,7 @@ module MnoEnterprise describe 'creation' do context 'success' do - before { stub_api_v2(:get, '/tenant', tenant) } + before { stub_api_v2(:get, '/tenant', tenant, ['tenant_company']) } before { subject } let(:data) { JSON.parse(response.body) } @@ -46,7 +46,7 @@ module MnoEnterprise context 'Tenant feature flag not active' do before { tenant.metadata[:can_manage_organization_credit] = false } - before { stub_api_v2(:get, '/tenant', tenant) } + before { stub_api_v2(:get, '/tenant', tenant, ['tenant_company']) } before { subject } it "does not create the account_transaction" do diff --git a/api/spec/controllers/mno_enterprise/jpi/v1/admin/tenants_controller_spec.rb b/api/spec/controllers/mno_enterprise/jpi/v1/admin/tenants_controller_spec.rb index b473f8f9b..f3bb946d7 100644 --- a/api/spec/controllers/mno_enterprise/jpi/v1/admin/tenants_controller_spec.rb +++ b/api/spec/controllers/mno_enterprise/jpi/v1/admin/tenants_controller_spec.rb @@ -16,7 +16,7 @@ module MnoEnterprise stub_user(user) sign_in user - stub_api_v2(:get, '/tenant', tenant) + stub_api_v2(:get, '/tenant', tenant, ['tenant_company']) stub_api_v2(:patch, '/tenant', tenant) end @@ -38,7 +38,8 @@ module MnoEnterprise payment_gateways: [] }, app_management: "marketplace", - organization_credit_management: true + organization_credit_management: true, + tenant_organization_id: tenant.tenant_company.id } # TODO: using JSON parse for better error diff --git a/api/spec/controllers/mno_enterprise/jpi/v1/marketplace_controller_spec.rb b/api/spec/controllers/mno_enterprise/jpi/v1/marketplace_controller_spec.rb index d1d9b845a..adc001ff8 100644 --- a/api/spec/controllers/mno_enterprise/jpi/v1/marketplace_controller_spec.rb +++ b/api/spec/controllers/mno_enterprise/jpi/v1/marketplace_controller_spec.rb @@ -101,7 +101,7 @@ def index_hash(apps, products) subject { get :index } before do - stub_api_v2(:get, '/tenant', tenant) + stub_api_v2(:get, '/tenant', tenant, ['tenant_company']) stub_api_v2(:get, '/apps', [app], DEPENDENCIES, { filter: { active: true } }) stub_api_v2(:get, '/apps', [app], [], { fields: { apps: 'updated_at' }, page: { number: 1, size: 1 }, sort: '-updated_at' }) stub_api_v2(:get, '/products', [product], PRODUCT_DEPENDENCIES, { filter: { active: true }} ) diff --git a/api/spec/requests/mnoe/jpi/v1/admin/tenants_spec.rb b/api/spec/requests/mnoe/jpi/v1/admin/tenants_spec.rb index 0278fccaf..4150466d4 100644 --- a/api/spec/requests/mnoe/jpi/v1/admin/tenants_spec.rb +++ b/api/spec/requests/mnoe/jpi/v1/admin/tenants_spec.rb @@ -15,7 +15,7 @@ module MnoEnterprise before do sign_in(user) - stub_api_v2(:get, '/tenant', tenant) + stub_api_v2(:get, '/tenant', tenant, ['tenant_company']) stub_api_v2(:patch, '/tenant', tenant) end diff --git a/core/lib/mno_enterprise/testing_support/factories/tenant.rb b/core/lib/mno_enterprise/testing_support/factories/tenant.rb index 20ace3e99..e1997d8ff 100644 --- a/core/lib/mno_enterprise/testing_support/factories/tenant.rb +++ b/core/lib/mno_enterprise/testing_support/factories/tenant.rb @@ -5,5 +5,6 @@ domain 'tenant.domain.test' frontend_config { {} } metadata { {app_management: "marketplace", can_manage_organization_credit: true} } + tenant_company { build(:organization) } end end diff --git a/core/spec/models/mno_enterprise/tenant_config_spec.rb b/core/spec/models/mno_enterprise/tenant_config_spec.rb index 6f103ee96..7a4df4aa2 100644 --- a/core/spec/models/mno_enterprise/tenant_config_spec.rb +++ b/core/spec/models/mno_enterprise/tenant_config_spec.rb @@ -7,7 +7,7 @@ let(:tenant) { build(:tenant, frontend_config: {'foo' => 'bar'})} describe '.load_config!' do - before { stub_api_v2(:get, '/tenant', tenant) } + before { stub_api_v2(:get, '/tenant', tenant, ['tenant_company']) } before { stub_api_v2(:get, '/apps', []) } before { stub_api_v2(:get, '/products', [], [], { filter: { active: true, local: true }} ) } @@ -33,12 +33,12 @@ subject { described_class.fetch_tenant_config } it 'get the tenant config from MnoHub' do - stub_api_v2(:get, '/tenant', tenant) + stub_api_v2(:get, '/tenant', tenant, ['tenant_company']) expect(subject).to eq(tenant.frontend_config) end it 'does not fail on connection error' do - stub_api_v2(:get, '/tenant').to_timeout + stub_api_v2(:get, '/tenant', nil, ['tenant_company']).to_timeout expect(subject).to be_nil end end From 209b3f513e012a53be2f71d0b63946603b48b12f Mon Sep 17 00:00:00 2001 From: MAhsenArif Date: Sun, 8 Jul 2018 17:53:57 +0500 Subject: [PATCH 3/3] [MNOE-1187] Fixed failed test cases --- .../mno_enterprise/jpi/v1/admin/tenants_controller.rb | 6 ++++++ core/spec/models/mno_enterprise/tenant_spec.rb | 4 ++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/api/app/controllers/mno_enterprise/jpi/v1/admin/tenants_controller.rb b/api/app/controllers/mno_enterprise/jpi/v1/admin/tenants_controller.rb index aafa7f96e..a4cfb63c7 100644 --- a/api/app/controllers/mno_enterprise/jpi/v1/admin/tenants_controller.rb +++ b/api/app/controllers/mno_enterprise/jpi/v1/admin/tenants_controller.rb @@ -15,6 +15,9 @@ def update @tenant = MnoEnterprise::Tenant.show @tenant.update_attributes!(tenant_params) + # Need to re-retrieve the tenant with tenant company after + # update_attributes! call + @tenant = MnoEnterprise::Tenant.show MnoEnterprise::SystemManager.restart(timestamp) render :show @@ -30,6 +33,9 @@ def restart_status def update_domain @tenant = MnoEnterprise::Tenant.show @tenant.update_attributes!(tenant_params) + # Need to re-retrieve the tenant with tenant company after + # update_attributes! call + @tenant = MnoEnterprise::Tenant.show domain = MnoEnterprise::SystemManager.update_domain(tenant_params[:domain]) if domain # Need to restart to reconfigure the app diff --git a/core/spec/models/mno_enterprise/tenant_spec.rb b/core/spec/models/mno_enterprise/tenant_spec.rb index bfea0d9a1..1cf347c3e 100644 --- a/core/spec/models/mno_enterprise/tenant_spec.rb +++ b/core/spec/models/mno_enterprise/tenant_spec.rb @@ -5,7 +5,7 @@ module MnoEnterprise # Test singular resource describe '.show' do - let!(:stub) { stub_api_v2(:get, '/tenant', tenant) } + let!(:stub) { stub_api_v2(:get, '/tenant', tenant, [:tenant_company]) } before { described_class.show } it { expect(stub).to have_been_requested } end @@ -22,7 +22,7 @@ module MnoEnterprise }.merge(params) } }} - let(:params) { {frontend_config: {}, metadata: {app_management: "marketplace", can_manage_organization_credit: true} } } + let(:params) { {frontend_config: {}, metadata: {app_management: "marketplace", can_manage_organization_credit: true}, tenant_company: nil } } let!(:stub) { stub_api_v2(:patch, '/tenant', tenant).with(body: body.to_json) } before { tenant.update_attributes(params) } it { expect(stub).to have_been_requested }