Feature: API to list the agents for the inbox (#438)

Co-authored-by: Sojan Jose <sojan@pepalo.com>
This commit is contained in:
Pranav Raj S 2020-01-21 19:56:58 +05:45 committed by Sojan Jose
parent a2b025b548
commit 95fb6893b4
4 changed files with 54 additions and 0 deletions

View file

@ -0,0 +1,13 @@
class Api::V1::Widget::InboxMembersController < Api::V1::Widget::BaseController
before_action :set_web_widget
def index
@inbox_members = @web_widget.inbox.inbox_members.includes(:user)
end
private
def permitted_params
params.permit(:website_token)
end
end

View file

@ -0,0 +1,6 @@
json.payload do
json.array! @inbox_members do |inbox_member|
json.name inbox_member.user.name
json.avatar_url inbox_member.user.avatar_url
end
end

View file

@ -27,6 +27,7 @@ Rails.application.routes.draw do
namespace :widget do
resources :messages, only: [:index, :create, :update]
resources :inboxes, only: [:create, :update]
resources :inbox_members, only: [:index]
end
namespace :actions do

View file

@ -0,0 +1,34 @@
require 'rails_helper'
RSpec.describe '/api/v1/widget/inbox_members', type: :request do
let(:account) { create(:account) }
let(:web_widget) { create(:channel_widget, account: account) }
let(:agent_1) { create(:user, account: account) }
let(:agent_2) { create(:user, account: account) }
before do
create(:inbox_member, user: agent_1, inbox: web_widget.inbox)
create(:inbox_member, user: agent_2, inbox: web_widget.inbox)
end
describe 'POST /api/v1/widget/inbox_members' do
let(:params) { { website_token: web_widget.website_token } }
context 'with correct website token' do
it 'returns the list of agents' do
get '/api/v1/widget/inbox_members', params: params
expect(response).to have_http_status(:success)
json_response = JSON.parse(response.body)
expect(json_response['payload'].length).to eq 2
end
end
context 'with invalid website token' do
it 'returns the list of agents' do
get '/api/v1/widget/inbox_members', params: { website_token: '' }
expect(response).to have_http_status(:not_found)
end
end
end
end