|
|
@ -341,24 +341,33 @@ RSpec.describe UsersController, type: :request do |
|
|
|
describe "#index" do |
|
|
|
describe "#index" do |
|
|
|
before do |
|
|
|
before do |
|
|
|
sign_in user |
|
|
|
sign_in user |
|
|
|
get "/users", headers:, params: {} |
|
|
|
|
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
it "redirects to the organisation user path" do |
|
|
|
context "when there are no url params" do |
|
|
|
follow_redirect! |
|
|
|
before do |
|
|
|
expect(path).to match("/organisations/#{user.organisation.id}/users") |
|
|
|
get "/users", headers:, params: {} |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
it "does not show the download csv link" do |
|
|
|
it "redirects to the organisation user path" do |
|
|
|
expect(page).not_to have_link("Download (CSV)", href: "/users.csv") |
|
|
|
follow_redirect! |
|
|
|
end |
|
|
|
expect(path).to match("/organisations/#{user.organisation.id}/users") |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
it "shows a search bar" do |
|
|
|
it "does not show the download csv link" do |
|
|
|
follow_redirect! |
|
|
|
expect(page).not_to have_link("Download (CSV)", href: "/users.csv") |
|
|
|
expect(page).to have_field("user-search-field", type: "search") |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
it "shows a search bar" do |
|
|
|
|
|
|
|
follow_redirect! |
|
|
|
|
|
|
|
expect(page).to have_field("user-search-field", type: "search") |
|
|
|
|
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
context "when a search parameter is passed" do |
|
|
|
context "when a search parameter is passed" do |
|
|
|
|
|
|
|
let!(:other_user_2) { FactoryBot.create(:user, name: "Stock name", organisation: user.organisation, name: "joe", email: "other@example.com") } |
|
|
|
|
|
|
|
let!(:other_user_3) { FactoryBot.create(:user, name: "User 5", organisation: user.organisation, email: "joe@example.com") } |
|
|
|
|
|
|
|
let!(:other_org_user) { FactoryBot.create(:user, name: "User 4", email: "joe@other_example.com") } |
|
|
|
|
|
|
|
|
|
|
|
before do |
|
|
|
before do |
|
|
|
get "/organisations/#{user.organisation.id}/users?user-search-field=#{search_param}" |
|
|
|
get "/organisations/#{user.organisation.id}/users?user-search-field=#{search_param}" |
|
|
|
end |
|
|
|
end |
|
|
@ -380,6 +389,30 @@ RSpec.describe UsersController, type: :request do |
|
|
|
expect(page).to have_content(other_user.name) |
|
|
|
expect(page).to have_content(other_user.name) |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
context "when our search term matches an email" do |
|
|
|
|
|
|
|
let(:search_param) { "other@example.com" } |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
it "returns only matching result within the same organisation" do |
|
|
|
|
|
|
|
expect(page).not_to have_content(user.name) |
|
|
|
|
|
|
|
expect(page).to have_content(other_user_2.name) |
|
|
|
|
|
|
|
expect(page).not_to have_content(other_user.name) |
|
|
|
|
|
|
|
expect(page).not_to have_content(other_user_3.name) |
|
|
|
|
|
|
|
expect(page).not_to have_content(other_org_user.name) |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
context "when our search term matches an email and a name" do |
|
|
|
|
|
|
|
let(:search_param) { "joe" } |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
it "returns any results including joe within the same organisation" do |
|
|
|
|
|
|
|
expect(page).to have_content(other_user_2.name) |
|
|
|
|
|
|
|
expect(page).to have_content(other_user_3.name) |
|
|
|
|
|
|
|
expect(page).not_to have_content(other_user.name) |
|
|
|
|
|
|
|
expect(page).not_to have_content(other_org_user.name) |
|
|
|
|
|
|
|
expect(page).not_to have_content(user.name) |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|