Skip to content

Commit

Permalink
Ignore deleted team members on project's page (#320)
Browse files Browse the repository at this point in the history
* Ignore deleted team members on project's page

* Ignore deleted team members on project's page

* Use pluck instead of map
  • Loading branch information
shalapatil authored Apr 25, 2022
1 parent 4c413ac commit 52ee20b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
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"].pluck("id")).not_to include user4.id
end

it "does not return the users of company2" do
expect(json_response["users"].pluck("id")).not_to include user3.id
end
end

context "when user is employee" do
Expand Down

0 comments on commit 52ee20b

Please sign in to comment.