Conversation
Current Code Coverage Percent of this PR:89.22 %Files having coverage below 100%
|
rohitjoshixyz
left a comment
There was a problem hiding this comment.
Some changes needed
| send_request( | ||
| :post, user_invitation_path, params: { | ||
| user: { | ||
| first_name: "firstName", | ||
| last_name: "lastName", | ||
| email: "[email protected]", | ||
| roles: "employee" | ||
| } | ||
| }) |
There was a problem hiding this comment.
Create the user using factory instead of making a POST request
| send_request( | ||
| :post, user_invitation_path, params: { | ||
| user: { | ||
| first_name: "firstName", | ||
| last_name: "lastName", | ||
| email: "[email protected]", | ||
| roles: "employee" | ||
| } | ||
| }) |
There was a problem hiding this comment.
Create the user needed using factory
| actual_members_data = json_response["team"].map do |member| | ||
| member.slice("name", "email", "role", "status") | ||
| end | ||
| expected_members_data = | ||
| [{ | ||
| "name" => user.full_name, "email" => user.email, "role" => "admin", "status" => nil | ||
| }, | ||
| { | ||
| "name" => "firstName lastName", "email" => "[email protected]", "role" => "employee", "status" => nil | ||
| }, | ||
| { | ||
| "name" => user2.full_name, "email" => user2.email, "role" => "employee", "status" => nil | ||
| } | ||
| ] | ||
| expect(actual_members_data).to eq(expected_members_data) |
There was a problem hiding this comment.
We can simplify this spec, there is a lot of repetition of keys.
| end | ||
|
|
||
| context "when unauthenticated" do | ||
| it "is not permitted to view teamt" do |
There was a problem hiding this comment.
Typo
| it "is not permitted to view teamt" do | |
| it "is not permitted to view team members" do |
| end | ||
|
|
||
| it "checks if profile picture is there with each team member" do | ||
| expect(json_response["team"].pluck("profilePicture")).not_to include(nil) |
There was a problem hiding this comment.
Assert with actual value instead of asserting not nil. You can create one user with an explicitly set avatar, and another with no avatar which will render the default avatar.png
| def status(member) | ||
| if current_user.has_owner_or_admin_role?(current_company) | ||
| if member.unconfirmed_email? | ||
| "reconfirmation" | ||
| elsif member.created_by_invite? && !member.invitation_accepted? && !member.has_role?(:owner, current_company) | ||
| "pending_invitation" | ||
| end | ||
| end | ||
| end |
There was a problem hiding this comment.
Use I18n. Check for t('team.reconfirmation') and reuse it for statuses
| def status(member) | ||
| if current_user.has_owner_or_admin_role?(current_company) | ||
| if member.unconfirmed_email? | ||
| "reconfirmation" | ||
| elsif member.created_by_invite? && !member.invitation_accepted? && !member.has_role?(:owner, current_company) | ||
| "pending_invitation" | ||
| end | ||
| end | ||
| end |
There was a problem hiding this comment.
Ideally, this method should go in a presenter class. cc @keshavbiswa
We have not added any presenters so we could keep this in the user model to keep this JBuilder file clean
There was a problem hiding this comment.
Ideally, yes. Also never liked jbuilder files, I feel it's much simpler to write Serializer classes which makes it more readable and clean in my opinion.
keshavbiswa
left a comment
There was a problem hiding this comment.
Added some comments.
| # frozen_string_literal: true | ||
|
|
||
| class InternalApi::V1::TeamController < InternalApi::V1::ApplicationController | ||
| helper :all |
There was a problem hiding this comment.
Why do we need to include all helpers?
There was a problem hiding this comment.
because we need access touser_avatar helper method in jbuilder
There was a problem hiding this comment.
Could you try helper :application_helper as helper :all will include All helpers.
app/policies/team_policy.rb
Outdated
|
|
||
| class TeamPolicy < ApplicationPolicy | ||
| def index? | ||
| true |
There was a problem hiding this comment.
Is this correct or should there be some kind of constraints (such as: current_user should be part of the company where the teams are?)
There was a problem hiding this comment.
to current user we show members of his team. We want to show it to employee type of users also. That's how this is done at other places too.
| def status(member) | ||
| if current_user.has_owner_or_admin_role?(current_company) | ||
| if member.unconfirmed_email? | ||
| "reconfirmation" | ||
| elsif member.created_by_invite? && !member.invitation_accepted? && !member.has_role?(:owner, current_company) | ||
| "pending_invitation" | ||
| end | ||
| end | ||
| end |
There was a problem hiding this comment.
Ideally, yes. Also never liked jbuilder files, I feel it's much simpler to write Serializer classes which makes it more readable and clean in my opinion.
keshavbiswa
left a comment
There was a problem hiding this comment.
LGTM! Thanks for making the changes.
|
@rohitjoshixyz Please review this PR. |
| trait :with_pending_invitation do | ||
| invitation_token { Faker::String.random(length: 10) } | ||
| invitation_created_at { Time.current } | ||
| end |
|
@ajinkyaa @shalapatil The same is applicable for this PR too. Please do not merge this on develop branch. |
|
@supriya3105 we can merge this PR on the develop, UI we are not merging. |
* Add API to get team members * Add suggested changes * Fix robocop errors * Use Application helper instead of including all helpers * Use has_role method
Notion card
Summary
https://www.notion.so/API-to-fetch-team-members-details-on-team-page-2104bddb4caa447bb2f91c1268493102
Preview
Type of change
Please delete options that are not relevant.
not work as expected)
How Has This Been Tested?
Checklist: