Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MNOE-1187] Updated json response to add tenant company for Tenant #747

Open
wants to merge 3 commits into
base: 4.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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) }
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 }} )
Expand Down
2 changes: 1 addition & 1 deletion api/spec/requests/mnoe/jpi/v1/admin/tenants_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion core/app/models/mno_enterprise/tenant.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def self.type
end

def self.show
self.find.first
self.includes(:tenant_company).find.first
end

# == Instance Methods =====================================================
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
6 changes: 3 additions & 3 deletions core/spec/models/mno_enterprise/tenant_config_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 }} ) }

Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions core/spec/models/mno_enterprise/tenant_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 }
Expand Down