Chore: Remove duplication of user JBuilder (#911)

* Chore: Reduce duplication of user JBuilder
This commit is contained in:
Sojan Jose 2020-05-31 23:10:20 +05:30 committed by GitHub
parent d4783db6fd
commit 8c52a3a953
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 39 additions and 53 deletions

View file

@ -17,11 +17,11 @@ class Api::V1::Accounts::AgentsController < Api::BaseController
def update
@agent.update!(agent_params.except(:role))
@agent.current_account_user.update!(role: agent_params[:role]) if agent_params[:role]
render 'api/v1/models/user.json', locals: { resource: @agent }
render partial: 'api/v1/models/agent.json.jbuilder', locals: { resource: @agent }
end
def create
render 'api/v1/models/user.json', locals: { resource: @user }
render partial: 'api/v1/models/agent.json.jbuilder', locals: { resource: @user }
end
private

View file

@ -2,7 +2,7 @@ class Api::V1::ProfilesController < Api::BaseController
before_action :set_user
def show
render json: @user
render partial: 'api/v1/models/user.json.jbuilder', locals: { resource: @user }
end
def update

View file

@ -1,10 +1,3 @@
json.array! @agents do |agent|
json.account_id agent.account.id
json.availability_status agent.availability_status
json.confirmed agent.confirmed?
json.email agent.email
json.id agent.id
json.name agent.name
json.role agent.role
json.thumbnail agent.avatar_url
json.partial! 'api/v1/models/agent.json.jbuilder', resource: agent
end

View file

@ -0,0 +1,8 @@
json.account_id resource.account.id
json.availability_status resource.availability_status
json.confirmed resource.confirmed?
json.email resource.email
json.id resource.id
json.name resource.name
json.role resource.role
json.thumbnail resource.avatar_url

View file

@ -0,0 +1,21 @@
json.id resource.id
json.provider resource.provider
json.uid resource.uid
json.name resource.name
json.nickname resource.nickname
json.email resource.email
json.account_id resource.active_account_user.account_id
json.pubsub_token resource.pubsub_token
json.role resource.active_account_user.role
json.inviter_id resource.active_account_user.inviter_id
json.confirmed resource.confirmed?
json.avatar_url resource.avatar_url
json.access_token resource.access_token.token
json.accounts do
json.array! resource.account_users do |account_user|
json.id account_user.account_id
json.name account_user.account.name
json.active_at account_user.active_at
json.role account_user.role
end
end

View file

@ -1,12 +0,0 @@
json.id resource.id
json.provider resource.provider
json.uid resource.uid
json.name resource.name
json.nickname resource.nickname
json.email resource.email
json.account_id resource.current_account_user.account_id
json.pubsub_token resource.pubsub_token
json.role resource.current_account_user.role
json.inviter_id resource.current_account_user.inviter_id
json.confirmed resource.confirmed?
json.avatar_url resource.avatar_url

View file

@ -1,9 +1 @@
json.id @user.id
json.provider @user.provider
json.uid @user.uid
json.name @user.name
json.nickname @user.nickname
json.email @user.email
json.pubsub_token @user.pubsub_token
json.confirmed @user.confirmed?
json.avatar_url @user.avatar_url
json.partial! 'api/v1/models/user.json.jbuilder', resource: @user

View file

@ -1,22 +1,3 @@
json.data do
json.id resource.id
json.provider resource.provider
json.uid resource.uid
json.name resource.name
json.nickname resource.nickname
json.email resource.email
json.account_id resource.active_account_user.account_id
json.pubsub_token resource.pubsub_token
json.role resource.active_account_user.role
json.inviter_id resource.active_account_user.inviter_id
json.confirmed resource.confirmed?
json.avatar_url resource.avatar_url
json.accounts do
json.array! resource.account_users do |account_user|
json.id account_user.account_id
json.name account_user.account.name
json.active_at account_user.active_at
json.role account_user.role
end
end
json.partial! 'api/v1/models/user.json.jbuilder', resource: resource
end

View file

@ -70,8 +70,10 @@ RSpec.describe 'Accounts API', type: :request do
headers: { api_access_token: super_admin.access_token.token },
as: :json
expect(User.find_by(email: email).confirmed?).to eq(true)
created_user = User.find_by(email: email)
expect(created_user.confirmed?).to eq(true)
expect(response.headers.keys).to include('access-token', 'token-type', 'client', 'expiry', 'uid')
expect(response.body).to include(created_user.access_token.token)
end
end

View file

@ -24,6 +24,7 @@ RSpec.describe 'Profile API', type: :request do
json_response = JSON.parse(response.body)
expect(json_response['id']).to eq(agent.id)
expect(json_response['email']).to eq(agent.email)
expect(json_response['access_token']).to eq(agent.access_token.token)
end
end
end