Skip to content

Commit

Permalink
refactor(tests): remove reliance on seeded db (system 3) (#4349)
Browse files Browse the repository at this point in the history
* refactor(tests): remove reliance on seeded db (system 1)

* refactor: remove extra partner being generate

* fix: incorrect count
  • Loading branch information
elasticspoon authored May 12, 2024
1 parent d103c7e commit ce7d144
Show file tree
Hide file tree
Showing 14 changed files with 226 additions and 163 deletions.
7 changes: 5 additions & 2 deletions spec/system/account_request_system_spec.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
RSpec.describe 'Account request flow', type: :system, js: true do
RSpec.describe 'Account request flow', type: :system, js: true, skip_seed: true do
let(:organization) { create(:organization, skip_items: true) }
let(:super_admin) { create(:super_admin, organization: organization) }

context 'when in staging' do
before do
allow(Rails.env).to receive(:staging?).and_return(true)
Expand Down Expand Up @@ -53,7 +56,7 @@
expect(page).to have_content('We will be processing your request now.')

# Access link within email sent to admin user to process the request.
sign_in(@super_admin)
sign_in(super_admin)
visit new_admin_organization_path(token: created_account_request.identity_token)

fill_in 'Short name', with: 'fakeshortname'
Expand Down
6 changes: 4 additions & 2 deletions spec/system/admin/account_requests_system_spec.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
RSpec.describe "Account Requests Admin", type: :system do
RSpec.describe "Account Requests Admin", type: :system, skip_seed: true do
let(:super_admin) { create(:super_admin) }

context "while signed in as a super admin" do
let!(:request1) { create(:account_request, confirmed_at: Time.zone.today, status: 'admin_approved') }
let!(:request2) {
Expand All @@ -11,7 +13,7 @@
let!(:request6) { create(:account_request, created_at: Time.zone.today - 2.days, status: 'started') }

before do
sign_in(@super_admin)
sign_in(super_admin)
end

around do |ex|
Expand Down
24 changes: 9 additions & 15 deletions spec/system/admin/barcode_items_system_spec.rb
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
RSpec.describe "Barcode Items Admin", type: :system do
RSpec.describe "Barcode Items Admin", type: :system, skip_seed: true do
let(:organization) { create(:organization, skip_items: true) }
let(:super_admin) { create(:super_admin, organization: organization) }

let!(:base_item) { create(:base_item) }
let!(:item) { create(:item, base_item: base_item) }
let!(:barcode_item) { create(:global_barcode_item, base_item: base_item) }

context "while signed in as a super admin" do
before do
sign_in(@super_admin)
sign_in(super_admin)
end

context "user visits the index page" do
let!(:item) { create(:item) }
let!(:base_item) { create(:base_item) }
let!(:barcode_item) { create(:global_barcode_item) }

before do
visit admin_barcode_items_path
end
Expand Down Expand Up @@ -38,9 +41,6 @@
end

context "user visits the new page" do
let!(:item) { create(:item) }
let!(:base_item) { create(:base_item) }

before do
visit new_admin_barcode_item_path
end
Expand All @@ -58,10 +58,6 @@
end

context "user visits the edit page" do
let!(:item) { create(:item) }
let!(:base_item) { create(:base_item) }
let!(:barcode_item) { create(:global_barcode_item) }

before do
visit edit_admin_barcode_item_path(barcode_item)
end
Expand All @@ -79,8 +75,6 @@
end

context "user visits the show page" do
let!(:barcode_item) { create(:global_barcode_item) }

before do
visit admin_barcode_item_path(barcode_item)
end
Expand Down
28 changes: 15 additions & 13 deletions spec/system/admin/base_items_system_spec.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
RSpec.describe "Base Item Admin", type: :system, js: true do
RSpec.describe "Base Item Admin", type: :system, js: true, skip_seed: true do
let(:organization) { create(:organization, skip_items: true) }
let(:user) { create(:user, organization: organization) }
let(:super_admin) { create(:super_admin, organization: organization) }
let(:super_admin_no_org) { create(:super_admin, organization: nil) }
let(:base_item) { create(:base_item) }

context "While signed in as an Administrative User (super admin)" do
before do
sign_in(@super_admin)
sign_in(super_admin)
end

let!(:url_prefix) {}
Expand Down Expand Up @@ -30,7 +36,6 @@
before do
visit edit_admin_base_item_path(base_item)
end
let(:base_item) { BaseItem.first }

it "should succeed when changing the name" do
fill_in "Name", with: base_item.name + " new"
Expand All @@ -46,8 +51,7 @@
end

it "can view a listing of all Base Items that shows a summary of its sub-items" do
base_item = BaseItem.first
create_list(:item, 2, base_item: base_item)
create_list(:item, 2, base_item: base_item, organization: organization)
count = base_item.item_count
visit admin_base_items_path
expect(page).to have_content(base_item.name)
Expand All @@ -57,15 +61,14 @@
end

it "can view a single Base Item" do
base_item = BaseItem.first
visit admin_base_item_path(base_item)
expect(page).to have_content(base_item.name)
end
end

context "While signed in as an Administrative User with no organization (super admin no org)" do
before do
sign_in(@super_admin_no_org)
sign_in(super_admin_no_org)
end

let!(:url_prefix) {}
Expand Down Expand Up @@ -94,7 +97,6 @@
before do
visit edit_admin_base_item_path(base_item)
end
let(:base_item) { BaseItem.first }

it "should succeed when changing the name" do
fill_in "Name", with: base_item.name + " new"
Expand All @@ -110,8 +112,7 @@
end

it "can view a listing of all Base Items that shows a summary of its sub-items" do
base_item = BaseItem.first
create_list(:item, 2, base_item: base_item)
create_list(:item, 2, base_item: base_item, organization: organization)
count = base_item.item_count
visit admin_base_items_path
expect(page).to have_content(base_item.name)
Expand All @@ -121,24 +122,25 @@
end

it "can view a single Base Item" do
base_item = BaseItem.first
visit admin_base_item_path(base_item)
expect(page).to have_content(base_item.name)
end
end

context "While signed in as a normal user" do
before do
sign_in(@user)
sign_in(user)
end
it "should have a normal user not see anything" do
visit new_admin_base_item_path
expect(page).to have_content("Access Denied")

visit admin_base_items_path
expect(page).to have_content("Access Denied")
base_item = create(:base_item)

visit admin_base_item_path(base_item)
expect(page).to have_content("Access Denied")

visit edit_admin_base_item_path(base_item)
expect(page).to have_content("Access Denied")
end
Expand Down
16 changes: 10 additions & 6 deletions spec/system/admin/organizations_system_spec.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
RSpec.describe "Admin Organization Management", type: :system, js: true do
let!(:foo_org) { create(:organization, name: 'foo') }
let!(:bar_org) { create(:organization, name: 'bar') }
let!(:baz_org) { create(:organization, name: 'baz') }
RSpec.describe "Admin Organization Management", type: :system, js: true, skip_seed: true do
let(:organization) { create(:organization, skip_items: true) }
let(:super_admin) { create(:super_admin, organization: organization) }
let(:super_admin_no_org) { create(:super_admin, organization: nil) }

let!(:foo_org) { create(:organization, name: 'foo', skip_items: true) }
let!(:bar_org) { create(:organization, name: 'bar', skip_items: true) }
let!(:baz_org) { create(:organization, name: 'baz', skip_items: true) }

context "While signed in as an Administrative User (super admin)" do
before :each do
sign_in(@super_admin)
sign_in(super_admin)
end

it "filters by organizations by name in organizations index page" do
Expand Down Expand Up @@ -91,7 +95,7 @@
end
context "While signed in as an Administrative User with no organization (super admin no org)" do
before :each do
sign_in(@super_admin_no_org)
sign_in(super_admin_no_org)
end

it "creates a new organization" do
Expand Down
37 changes: 28 additions & 9 deletions spec/system/admin/users_system_spec.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
RSpec.describe "Admin Users Management", type: :system, js: true do
RSpec.describe "Admin Users Management", type: :system, js: true, skip_seed: true do
let(:organization) { create(:organization, skip_items: true) }
let(:user) { create(:user, organization: organization) }
let(:organization_admin) { create(:organization_admin, organization: organization) }
let(:super_admin) { create(:super_admin, organization: organization) }

context "While signed in as an Administrative User (super admin)" do
before do
sign_in(@super_admin)
sign_in(super_admin)
end

it "creates an user" do
Expand All @@ -16,24 +21,28 @@
end

it "edits an existing user" do
create(:user, organization: organization, name: "AAlphabetically First User")

visit admin_users_path
click_link "Edit", match: :first
expect(page).to have_content("Update #{@organization_admin.name}")
expect(page).to have_content("Update AAlphabetically First User")

fill_in "user_name", with: "TestUser"
select(@organization.name, from: 'user_organization_id')
select(organization.name, from: 'user_organization_id')
click_on "Save"

expect(page.find(".alert")).to have_content "TestUser updated"

# Check if the organization role has been updated
tbody = find('#filterrific_results table tbody')
first_row = tbody.find('tr', text: 'TestUser')
expect(first_row).to have_text(@organization.name)
expect(first_row).to have_text(organization.name)
end

it 'adds a role' do
user = FactoryBot.create(:user, name: 'User 123')
FactoryBot.create(:partner, name: 'Partner ABC')
user = create(:user, name: 'User 123', organization: organization)
create(:partner, name: 'Partner ABC', organization: organization)

visit edit_admin_user_path(user)
expect(page).to have_content('User 123')
select "Partner", from: "resource_type"
Expand All @@ -48,7 +57,10 @@
end

it "deletes an existing user" do
create(:user, organization: organization, name: "AAlphabetically First User")

visit admin_users_path

page.accept_confirm do
click_link "Delete", match: :first
end
Expand All @@ -57,22 +69,29 @@
end

it "filters users by name" do
user_names = User.all.pluck(:name)
create(:user, name: "UserA", organization: organization)
create(:user, name: "UserB", organization: organization)
create(:user, name: "UserC", organization: organization)

user_names = ["UserA", "UserB", "UserC"]

visit admin_users_path

user_names.each do |name|
expect(page.find("table")).to have_content(name)
end

fill_in "filterrific_search_name", with: user_names.first

user_names[1..].each do |name|
expect(page.find("table")).not_to have_content(name)
end

expect(page.find("table")).to have_content(user_names.first)
end

it "filters users by email" do
user_email = @organization_admin.email
user_email = organization_admin.email

visit admin_users_path
fill_in "filterrific_search_email", with: user_email
Expand Down
11 changes: 7 additions & 4 deletions spec/system/annual_reports_system_spec.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
RSpec.describe "Annual Reports", type: :system, js: true do
let(:url_prefix) { "/#{@organization.short_name}" }
RSpec.describe "Annual Reports", type: :system, js: true, skip_seed: true do
let(:organization) { create(:organization, skip_items: true) }
let(:organization_admin) { create(:organization_admin, organization: organization) }

let(:url_prefix) { "/#{organization.short_name}" }

context "while signed in as an organization admin" do
subject { url_prefix + "/reports/annual_reports" }
let!(:purchase) { create(:purchase, :with_items, item_quantity: 10, issued_at: 1.year.ago) }
let!(:purchase) { create(:purchase, :with_items, item_quantity: 10, issued_at: 1.year.ago, organization: organization) }

before do
sign_in @organization_admin
sign_in organization_admin
visit subject.to_s
end

Expand Down
Loading

0 comments on commit ce7d144

Please sign in to comment.