Skip to content

Commit

Permalink
Add portfolio_item specs
Browse files Browse the repository at this point in the history
  • Loading branch information
syncrou committed Jan 4, 2019
1 parent aba1ac8 commit a454542
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 4 deletions.
27 changes: 23 additions & 4 deletions spec/requests/portfolio_items_spec.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
describe 'PortfolioItems API' do
include RequestSpecHelper
include ServiceSpecHelper

let!(:portfolio_item) { create(:portfolio_item) }
let(:portfolio_item_id) { portfolio_item.id }
Expand All @@ -13,7 +14,7 @@
%w(admin user).each do |tag|
describe "GET #{tag} tagged /portfolio_items" do
before do
get "/portfolio_items", headers: send("#{tag}_encode_key_with_tenant")
get "#{api}/portfolio_items", headers: send("#{tag}_encode_key_with_tenant")
end

context 'when portfolios exist' do
Expand All @@ -32,15 +33,33 @@
let(:valid_attributes) { { name: 'rspec 1', description: 'rspec 1 description' } }
context 'with wrong header' do
it 'returns a 404' do
expect(:post => "/portfolio_items").not_to be_routable
pending("Will work again when headers are checked")
expect(:post => "#{api}/portfolio_items").not_to be_routable
end
end
end

describe 'DELETE admin tagged /portfolio_items/:portfolio_item_id' do
let(:valid_attributes) { { :name => 'PatchPortfolio', :description => 'description for patched portfolio' } }

context 'when :portfolio_item_id is valid' do
before do
delete "#{api}/portfolio_items/#{portfolio_item_id}", :headers => admin_headers, :params => valid_attributes
end

it 'deletes the record' do
expect(response).to have_http_status(204)
end
end
end

describe 'POST admin tagged /portfolio_items' do
let(:valid_attributes) { { name: 'rspec 1', description: 'rspec 1 description', service_offering_ref: '10' } }
let(:valid_attributes) { { name: 'rh-mediawiki-apb', description: 'Mediawiki apb implementation', service_offering_ref: '21' } }
context 'when portfolio attributes are valid' do
before { post "/portfolio_items", params: valid_attributes, headers: admin_encode_key_with_tenant }
before do
#ServiceCatalog::ServiceOffering
post "#{api}/portfolio_items", params: valid_attributes, headers: admin_encode_key_with_tenant
end

it 'returns status code 200' do
expect(response).to have_http_status(200)
Expand Down
1 change: 1 addition & 0 deletions spec/support/service_catalog/service_offering.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[{"id":"21","name":"rh-mediawiki-apb","description":"Mediawiki apb implementation"},{"id":"153","name":"s2i-fuse71-karaf-camel-rest-sql","description":"Camel example using Rest DSL with SQL Database in Karaf container. This example demonstrates how to use SQL via JDBC along with Camel's REST DSL to expose a RESTful API. The OpenShift MySQL container image should already be installed and running on your OpenShift installation, one simple way to run a MySQL service is following the documentation of the OpenShift MySQL container image related to the mysql-ephemeral template.."}]
27 changes: 27 additions & 0 deletions spec/support/service_catalog/service_offering.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
module MockApi
module ServiceCatalog
class ServiceOffering
def initialize(options)
@mock = JSON.parse(File.read("#{Rails.root}/spec/support/service_catalog/service_offering.json"))
self
end

def self.find(id)
new({}).show(id)
end

def show(id)
vcr = instance_variable_get(:@mock)
resp = vcr.select { |x| x['id'] == id }
raise ActiveRecord::RecordNotFound if resp.empty?
@normalized = resp.first
self
end

def to_normalized_params()
@normalized["service_offering_ref"] = @normalized["id"]
@normalized
end
end
end
end

0 comments on commit a454542

Please sign in to comment.