Skip to content

Commit

Permalink
add profile_image and refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
vasconsaurus committed Jul 26, 2024
1 parent a2cfd1c commit e662689
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
12 changes: 11 additions & 1 deletion app/graph/types/user_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,16 @@ def source
end

def name
object.is_admin && !object.is_member_of?(Team.current) ? 'Meedan' : object.name
meedan_user ? 'Meedan' : object.name
end

def profile_image
meedan_user ? 'http://localhost:3000/images/checklogo.png' : object.profile_image
end

private

def meedan_user
object.is_admin && !object.is_member_of?(Team.current)
end
end
16 changes: 10 additions & 6 deletions test/controllers/graphql_controller_12_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -522,7 +522,7 @@ def teardown
assert_equal 'false', pm2.reload.last_status
end

test "should return super-admin user name as 'meedan' if user IS NOT a part of the team" do
test "should return super-admin user as 'meedan' if user IS NOT a part of the team" do
u1 = create_user name: 'Mei'
u2 = create_user name: 'Satsuki', is_admin: true

Expand All @@ -534,20 +534,22 @@ def teardown

authenticate_with_user(u1)

query1 = "query { user (id: #{ u1.id }) { name } }"
query1 = "query { user (id: #{ u1.id }) { name, profile_image } }"
post :create, params: { query: query1 }
assert_response :success
assert_equal false, u1.is_admin?
assert_equal 'Mei', JSON.parse(@response.body)['data']['user']['name']
assert_equal 'http://localhost:3000/images/user.png', JSON.parse(@response.body)['data']['user']['profile_image']

query2 = "query { user (id: #{ u2.id }) { name } }"
query2 = "query { user (id: #{ u2.id }) { name, profile_image } }"
post :create, params: { query: query2 }
assert_response :success
assert_equal true, u2.is_admin?
assert_equal 'Meedan', JSON.parse(@response.body)['data']['user']['name']
assert_equal 'http://localhost:3000/images/checklogo.png', JSON.parse(@response.body)['data']['user']['profile_image']
end

test "should return super-admin user name as their name if user IS a part of the team" do
test "should return super-admin user themself if user IS a part of the team" do
u1 = create_user name: 'Mei'
u2 = create_user name: 'Satsuki', is_admin: true

Expand All @@ -558,16 +560,18 @@ def teardown

authenticate_with_user(u1)

query1 = "query { user (id: #{ u1.id }) { name } }"
query1 = "query { user (id: #{ u1.id }) { name, profile_image } }"
post :create, params: { query: query1 }
assert_response :success
assert_equal false, u1.is_admin?
assert_equal 'Mei', JSON.parse(@response.body)['data']['user']['name']
assert_equal 'http://localhost:3000/images/user.png', JSON.parse(@response.body)['data']['user']['profile_image']

query2 = "query { user (id: #{ u2.id }) { name } }"
query2 = "query { user (id: #{ u2.id }) { name, profile_image } }"
post :create, params: { query: query2 }
assert_response :success
assert_equal true, u2.is_admin?
assert_equal 'Satsuki', JSON.parse(@response.body)['data']['user']['name']
assert_equal 'http://localhost:3000/images/user.png', JSON.parse(@response.body)['data']['user']['profile_image']
end
end

0 comments on commit e662689

Please sign in to comment.