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

Ignore deleted team members on project's page #320

Merged
merged 4 commits into from
Apr 25, 2022
Merged
Show file tree
Hide file tree
Changes from 3 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
Expand Up @@ -3,6 +3,6 @@
class InternalApi::V1::CompanyUsersController < InternalApi::V1::ApplicationController
def index
authorize CompanyUser
render :index, locals: { users: current_company.users }, status: :ok
render :index, locals: { users: current_company.users.kept }, status: :ok
end
end
16 changes: 15 additions & 1 deletion spec/requests/internal_api/v1/company_users/index_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,39 @@
let(:user1) { create(:user, current_workspace_id: company1.id) }
let(:user2) { create(:user) }
let(:user3) { create(:user) }
let(:user4) { create(:user) }

before do
create(:company_user, company_id: company1.id, user_id: user1.id)
create(:company_user, company_id: company1.id, user_id: user2.id)
create(:company_user, company_id: company2.id, user_id: user3.id)
create(:company_user, company_id: company1.id, user_id: user4.id)
end

context "when user is admin" do
before do
user1.add_role :admin, company1
sign_in user1
user4.discard
send_request :get, internal_api_v1_company_users_path
end

it "returns the list of users of company" do
it "returns the success" do
expect(response).to have_http_status(:ok)
end

it "returns the users of company1" do
result = [ { id: user1.id, name: user1.full_name }, { id: user2.id, name: user2.full_name }]
expect(json_response["users"]).to match_array(JSON.parse(result.to_json))
end

it "does not return the discarded users of company1" do
expect(json_response["users"].map { |user| user["id"] }).not_to include user4.id
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
expect(json_response["users"].map { |user| user["id"] }).not_to include user4.id
expect(json_response["users"].pluck("id").not_to include user4.id

end

it "does not return the users of company2" do
expect(json_response["users"].map { |user| user["id"] }).not_to include user3.id
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
expect(json_response["users"].map { |user| user["id"] }).not_to include user3.id
expect(json_response["users"].pluck("id")).not_to include user3.id

end
end

context "when user is employee" do
Expand Down