Skip to content

Commit

Permalink
Move most organization system specs to request spec [#4396]
Browse files Browse the repository at this point in the history
  • Loading branch information
awwaiid committed Jul 14, 2024
1 parent a79d052 commit b5d12cd
Show file tree
Hide file tree
Showing 2 changed files with 196 additions and 163 deletions.
208 changes: 196 additions & 12 deletions spec/requests/organization_requests_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@

RSpec.describe "Organizations", type: :request do
let(:organization) { create(:organization) }
let(:user) { create(:user, organization: organization) }
let(:organization_admin) { create(:organization_admin, organization: organization) }
let!(:user) { create(:user, organization: organization) }
let!(:organization_admin) { create(:organization_admin, organization: organization) }
let!(:admin_user) { create(:organization_admin, organization: organization, name: "ADMIN USER") }
let!(:unit) { create(:unit, name: "WolfPack", organization: organization) }
let!(:store) { create(:storage_location, organization: organization) }
let!(:ndbn_member) { create(:ndbn_member, ndbn_member_id: "50000", account_name: "Best Place") }

context "While signed in as a normal user" do
before do
Expand All @@ -24,21 +27,46 @@
)
end

it "can view organization details", :aggregate_failures do
html = Nokogiri::HTML(response.body)
expect(html.text).to include(organization.name)
expect(html.css("a").text).to include("Home")
expect(html.css("a").to_s).to include(dashboard_path)
expect(html.text).to include("Organization Info")
expect(html.text).to include("Contact Info")
expect(html.text).to include("Default email text")
expect(html.text).to include("Users")
expect(html.text).to include("Short Name")
expect(html.text).to include("URL")
expect(html.text).to include("Partner Profile Sections")
expect(html.text).to include("Custom Partner Invitation Message")
expect(html.text).to include("Child Based Requests?")
expect(html.text).to include("Individual Requests?")
expect(html.text).to include("Quantity Based Requests?")
expect(html.text).to include("Show Year-to-date values on distribution printout?")
expect(html.text).to include("Logo")
expect(html.text).to include("Use One step Partner invite and approve process?")
end

context "when enable_packs flipper is on" do
it "displays organization's custom units" do
Flipper.enable(:enable_packs)
get organization_path
expect(response.body).to include unit.name.titlecase
expect(response.body).to include "Wolf Pack"
end
end

context "when enable_packs flipper is off" do
it "does not display organization's custom units" do
Flipper.disable(:enable_packs)
get organization_path
expect(response.body).to_not include unit.name.titlecase
expect(response.body).to_not include "Wolf Pack"
end
end

it "cannot see 'Demote to User' button for admins" do
expect(response.body).to_not include "Demote to User"
end
end

describe "GET #edit" do
Expand All @@ -62,6 +90,59 @@
sign_in(organization_admin)
end

describe "GET #show" do
before { get organization_path }

it "can view organization details", :aggregate_failures do
html = Nokogiri::HTML(response.body)
expect(html.text).to include(organization.name)
expect(html.css("a").text).to include("Home")
expect(html.css("a").to_s).to include(dashboard_path)
expect(html.text).to include("Organization Info")
expect(html.text).to include("Contact Info")
expect(html.text).to include("Default email text")
expect(html.text).to include("Users")
expect(html.text).to include("Short Name")
expect(html.text).to include("URL")
expect(html.text).to include("Partner Profile Sections")
expect(html.text).to include("Custom Partner Invitation Message")
expect(html.text).to include("Child Based Requests?")
expect(html.text).to include("Individual Requests?")
expect(html.text).to include("Quantity Based Requests?")
expect(html.text).to include("Show Year-to-date values on distribution printout?")
expect(html.text).to include("Logo")
expect(html.text).to include("Use One step Partner invite and approve process?")
end

context "when enable_packs flipper is on" do
it "displays organization's custom units" do
Flipper.enable(:enable_packs)
get organization_path
expect(response.body).to include "Wolf Pack"
end
end

context "when enable_packs flipper is off" do
it "does not display organization's custom units" do
Flipper.disable(:enable_packs)
get organization_path
expect(response.body).to_not include "Wolf Pack"
end
end

it "can see 'Demote to User' button for admins" do
create(:organization_admin, organization: organization, name: "ADMIN USER")
get organization_path
expect(response.body).to include "Demote to User"
end

it "can re-invite a user to an organization after 7 days" do
create(:user, name: "Ye Olde Invited User", invitation_sent_at: Time.current - 7.days)
get organization_path
expect(response.body).to include("Re-send invitation")
end
end

describe "GET #edit" do
before { get edit_organization_path }

Expand Down Expand Up @@ -109,16 +190,122 @@
end

context "when organization can not be updated" do
let(:invalid_organization) { create(:organization, name: "Original Name") }
let(:invalid_params) { { organization: { name: nil } } }

subject { patch "/manage", params: invalid_params }
let(:update_param) { { organization: { name: nil } } }

it "renders edit template with an error message" do
expect(subject).to render_template("edit")
expect(subject).to render_template(:edit)
expect(flash[:error]).to be_present
end
end

context "when the organization URL is updated" do
let(:update_param) { { organization: { url: "http://www.diaperbase.com" } } }
it "updates the organization's URL" do
subject
expect(response).to redirect_to(organization_path)
follow_redirect!
expect(response.body).to include("pdated")
end
end

context "updates reminder and deadline days" do
let(:update_param) { { organization: { reminder_day: 12, deadline_day: 16 } } }
it "works" do
subject
expect(response).to redirect_to(organization_path)
follow_redirect!
expect(response.body).to include("Updated")
end
end

context "updates repackage essentials setting" do
let(:update_param) { { organization: { repackage_essentials: true } } }
it "works" do
subject
expect(response).to redirect_to(organization_path)
follow_redirect!
expect(response.body).to include("Yes")
end
end

context "can select if the org distributes essentials monthly" do
let(:update_param) { { organization: { distribute_monthly: true } } }
it "works" do
subject
expect(response).to redirect_to(organization_path)
follow_redirect!
expect(response.body).to include("Yes")
end
end

context 'can select if the org shows year-to-date values on the distribution printout' do
let(:update_param) { { organization: { ytd_on_distribution_printout: false } } }
it "works" do
subject
expect(response).to redirect_to(organization_path)
follow_redirect!
expect(response.body).to include("No")
end
end

context 'can set a default storage location on the organization' do
let(:update_param) { { organization: { default_storage_location: store.id } } }
it "works" do
subject
expect(response).to redirect_to(organization_path)
follow_redirect!
expect(response.body).to include(store.name)
end
end

context 'can set the NDBN Member ID' do
let(:update_param) { { organization: { ndbn_member_id: ndbn_member.id } } }
it "works" do
subject
expect(response).to redirect_to(organization_path)
follow_redirect!
expect(response.body).to include(ndbn_member.full_name)
end
end

context 'can select and deselect Required Partner Fields' do
let(:update_param) { { organization: { partner_form_fields: ['media_information'] } } }
it "works" do
subject
expect(response).to redirect_to(organization_path)
follow_redirect!
expect(response.body).to include('Media Information')
expect(organization.reload.partner_form_fields).to eq(['media_information'])

patch "/manage", params: { organization: { partner_form_fields: [] } }
expect(response).to redirect_to(organization_path)
follow_redirect!
expect(response.body).to_not include('Media Information')
expect(organization.reload.partner_form_fields).to eq([])
end
end

context "can disable if the org does NOT use single step invite and approve partner process" do
let(:update_param) { { organization: { one_step_partner_invite: false } } }
it "works" do
subject
expect(response).to redirect_to(organization_path)
follow_redirect!
expect(response.body).to include("No")
end
end

context "can enable if the org uses single step invite and approve partner process" do
let(:update_param) { { organization: { one_step_partner_invite: true } } }
it "works" do
subject
expect(response).to redirect_to(organization_path)
follow_redirect!
expect(response.body).to include("Yes")
end
end


end

describe "POST #promote_to_org_admin" do
Expand All @@ -132,9 +319,6 @@
end

describe "POST #demote_to_user" do
let(:admin_user) do
create(:organization_admin, organization: organization, name: "ADMIN USER")
end
subject { post demote_to_user_organization_path(user_id: admin_user.id) }

it "runs correctly" do
Expand Down
Loading

0 comments on commit b5d12cd

Please sign in to comment.