2019-07-30 21:29:24 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2018-03-25 16:15:39 +00:00
|
|
|
# License: AGPL-3.0-or-later WITH Web-Template-Output-Additional-Permission-3.0-or-later
|
2018-03-25 17:30:42 +00:00
|
|
|
require 'rails_helper'
|
|
|
|
require 'controllers/support/shared_user_context'
|
|
|
|
|
2019-07-30 21:29:24 +00:00
|
|
|
describe CampaignsController, type: :controller do
|
2018-03-25 17:30:42 +00:00
|
|
|
describe 'authorization' do
|
|
|
|
include_context :shared_user_context
|
|
|
|
describe 'rejects unauthorized users' do
|
|
|
|
describe 'create' do
|
|
|
|
include_context :open_to_confirmed_users, :post, :create, nonprofit_id: :__our_np
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'name_and_id' do
|
|
|
|
include_context :open_to_confirmed_users, :get, :name_and_id, nonprofit_id: :__our_np
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'duplicate' do
|
2018-11-09 00:29:00 +00:00
|
|
|
include_context :open_to_confirmed_users, :post, :duplicate, nonprofit_id: :__our_np, id: :__our_campaign
|
2018-03-25 17:30:42 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
describe 'update' do
|
2019-07-30 21:29:24 +00:00
|
|
|
include_context :open_to_campaign_editor, :put, :update, nonprofit_id: :__our_np, id: :__our_campaign
|
2018-03-25 17:30:42 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
describe 'soft_delete' do
|
2019-07-30 21:29:24 +00:00
|
|
|
include_context :open_to_campaign_editor, :delete, :soft_delete, nonprofit_id: :__our_np, id: :__our_campaign
|
2018-03-25 17:30:42 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
describe 'open to all' do
|
|
|
|
describe 'index' do
|
2019-08-02 16:20:33 +00:00
|
|
|
include_context :open_to_all, :get, :index, nonprofit_id: :__our_np, without_json_view: true
|
2018-03-25 17:30:42 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
describe 'show' do
|
2019-08-02 16:20:33 +00:00
|
|
|
include_context :open_to_all, :get, :show, nonprofit_id: :__our_np, id: :__our_campaign, without_json_view: true
|
2018-03-25 17:30:42 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
describe 'activities' do
|
2019-07-30 21:29:24 +00:00
|
|
|
include_context :open_to_all, :get, :activities, nonprofit_id: :__our_np, id: :__our_campaign
|
2018-03-25 17:30:42 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
describe 'metrics' do
|
2019-07-30 21:29:24 +00:00
|
|
|
include_context :open_to_all, :get, :metrics, nonprofit_id: :__our_np, id: :__our_campaign
|
2018-03-25 17:30:42 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
describe 'timeline' do
|
2019-07-30 21:29:24 +00:00
|
|
|
include_context :open_to_all, :get, :timeline, nonprofit_id: :__our_np, id: :__our_campaign
|
2018-03-25 17:30:42 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
describe 'totals' do
|
2019-07-30 21:29:24 +00:00
|
|
|
include_context :open_to_all, :get, :totals, nonprofit_id: :__our_np, id: :__our_campaign
|
2018-03-25 17:30:42 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
describe 'peer_to_peer' do
|
2019-08-02 16:20:33 +00:00
|
|
|
include_context :open_to_all, :get, :peer_to_peer, nonprofit_id: :__our_np, without_json_view: true
|
2018-03-25 17:30:42 +00:00
|
|
|
end
|
2018-11-09 00:29:00 +00:00
|
|
|
end
|
|
|
|
end
|
2018-03-25 17:30:42 +00:00
|
|
|
|
2018-11-09 00:29:00 +00:00
|
|
|
describe 'routes' do
|
2019-07-30 21:29:24 +00:00
|
|
|
it 'routes campaigns#index' do
|
|
|
|
expect(get: '/nonprofits/5/campaigns/4').to(route_to(controller: 'campaigns', action: 'show', nonprofit_id: '5', id: '4'))
|
2018-03-25 17:30:42 +00:00
|
|
|
end
|
|
|
|
end
|
2020-04-01 22:01:15 +00:00
|
|
|
|
|
|
|
describe 'index' do
|
|
|
|
render_views
|
2020-04-16 20:50:03 +00:00
|
|
|
let(:nonprofit) { force_create(:nm_justice, published: true)}
|
2020-04-01 22:01:15 +00:00
|
|
|
let(:campaign) { force_create(:campaign, nonprofit: nonprofit, name: "simplename", goal_amount: 444)}
|
|
|
|
before(:each) do
|
|
|
|
|
|
|
|
campaign
|
|
|
|
get(:index, params: {nonprofit_id: nonprofit.id, format: :json})
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'has ok status' do
|
|
|
|
expect(response).to have_http_status(:ok)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'has correct items' do
|
|
|
|
body = JSON::parse(response.body)
|
|
|
|
expect(body).to eq({data: [{id: campaign.id,
|
|
|
|
name: 'simplename',
|
|
|
|
total_raised: 0,
|
|
|
|
goal_amount: 444,
|
2020-05-21 22:22:22 +00:00
|
|
|
url: "http://test.host/nm/albuquerque/new-mexico-equality/campaigns/slug_#{campaign.id}"
|
2020-04-01 22:01:15 +00:00
|
|
|
}]}.with_indifferent_access)
|
|
|
|
end
|
|
|
|
end
|
2019-07-13 09:18:45 +00:00
|
|
|
end
|