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

Forgot to commit specs :s #180

Merged
merged 1 commit into from
Jan 2, 2017
Merged
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
@@ -0,0 +1,75 @@
require 'rails_helper'

module MnoEnterprise
describe Jpi::V1::AppReviewsController, type: :controller do
include MnoEnterprise::TestingSupport::JpiV1TestHelper
render_views
routes { MnoEnterprise::Engine.routes }
before { request.env["HTTP_ACCEPT"] = 'application/json' }


#===============================================
# Assignments
#===============================================
let(:user) { build(:user) }
before { api_stub_for(get: "/users/#{user.id}", response: from_api(user)) }
before { sign_in user }

let(:app) { build(:app) }
let(:app_review) { build(:app_review) }
let(:expected_hash_for_review) do
attrs = %w(id rating description status user_id user_name organization_id organization_name app_id app_name)
app_review.attributes.slice(*attrs).merge({'created_at' => app_review.created_at.as_json, 'updated_at' => app_review.updated_at.as_json})
end
let(:expected_hash_for_reviews) do
{
'app_reviews' => [expected_hash_for_review],
# 'metadata' => {'pagination' => {'count' => 1}}
}
end

before do
api_stub_for(get: "/apps/#{app.id}", response: from_api(app))
end

describe 'GET #index' do

before do
api_stub_for(get: "/app_reviews?filter[reviewable_id]=#{app.id}", response: from_api([app_review]))
end

subject { get :index, id: app.id }

it_behaves_like "jpi v1 protected action"

it_behaves_like "a paginated action"

it 'renders the list of reviews' do
subject
expect(JSON.parse(response.body)).to eq(expected_hash_for_reviews)
end
end

describe 'POST #create', focus: true do
let(:params) { {organization_id: 1, description: 'A Review', rating: 5, foo: 'bar'} }
let(:app_review) { build(:app_review) }

before do
api_stub_for(post: "/app_reviews", response: from_api(app_review))
api_stub_for(get: "/app_reviews/#{app_review.id}", response: from_api(app_review))
end

subject { post :create, id: app.id, app_review: params }

it_behaves_like "jpi v1 protected action"

it 'renders the new review' do
expect(JSON.parse(subject.body)).to include('app_review' => expected_hash_for_review)
end

it 'renders the new average rating' do
expect(JSON.parse(subject.body)).to include('average_rating' => app.average_rating)
end
end
end
end