Chore: API Improvements (#3469)
This commit is contained in:
parent
55843c5bad
commit
add004a56e
13 changed files with 55 additions and 13 deletions
|
@ -57,7 +57,7 @@ Metrics/BlockLength:
|
|||
- db/schema.rb
|
||||
Metrics/ModuleLength:
|
||||
Exclude:
|
||||
- lib/woot_message_seeder.rb
|
||||
- lib/seeders/message_seeder.rb
|
||||
Rails/ApplicationController:
|
||||
Exclude:
|
||||
- 'app/controllers/api/v1/widget/messages_controller.rb'
|
||||
|
|
|
@ -33,7 +33,7 @@ class Api::V1::Accounts::CannedResponsesController < Api::V1::Accounts::BaseCont
|
|||
|
||||
def canned_responses
|
||||
if params[:search]
|
||||
Current.account.canned_responses.where('short_code ILIKE ?', "#{params[:search]}%")
|
||||
Current.account.canned_responses.where('short_code ILIKE :search OR content ILIKE :search', search: "%#{params[:search]}%")
|
||||
else
|
||||
Current.account.canned_responses
|
||||
end
|
||||
|
|
7
app/presenters/agent_bot_presenter.rb
Normal file
7
app/presenters/agent_bot_presenter.rb
Normal file
|
@ -0,0 +1,7 @@
|
|||
class AgentBotPresenter < SimpleDelegator
|
||||
def access_token
|
||||
return if account_id.blank?
|
||||
|
||||
Current.account.id == account_id ? super&.token : nil
|
||||
end
|
||||
end
|
|
@ -1 +1 @@
|
|||
json.partial! 'api/v1/models/agent_bot.json.jbuilder', resource: @agent_bot
|
||||
json.partial! 'api/v1/models/agent_bot.json.jbuilder', resource: AgentBotPresenter.new(@agent_bot)
|
||||
|
|
|
@ -1,3 +1,3 @@
|
|||
json.array! @agent_bots do |agent_bot|
|
||||
json.partial! 'api/v1/models/agent_bot.json.jbuilder', resource: agent_bot
|
||||
json.partial! 'api/v1/models/agent_bot.json.jbuilder', resource: AgentBotPresenter.new(agent_bot)
|
||||
end
|
||||
|
|
|
@ -1 +1 @@
|
|||
json.partial! 'api/v1/models/agent_bot.json.jbuilder', resource: @agent_bot
|
||||
json.partial! 'api/v1/models/agent_bot.json.jbuilder', resource: AgentBotPresenter.new(@agent_bot)
|
||||
|
|
|
@ -1 +1 @@
|
|||
json.partial! 'api/v1/models/agent_bot.json.jbuilder', resource: @agent_bot
|
||||
json.partial! 'api/v1/models/agent_bot.json.jbuilder', resource: AgentBotPresenter.new(@agent_bot)
|
||||
|
|
|
@ -3,3 +3,4 @@ json.name resource.name
|
|||
json.description resource.description
|
||||
json.outgoing_url resource.outgoing_url
|
||||
json.account_id resource.account_id
|
||||
json.access_token resource.access_token if resource.access_token.present?
|
||||
|
|
|
@ -3,3 +3,4 @@ json.name resource.name
|
|||
json.description resource.description
|
||||
json.outgoing_url resource.name
|
||||
json.account_id resource.account_id
|
||||
json.access_token resource.access_token.token
|
||||
|
|
12
db/seeds.rb
12
db/seeds.rb
|
@ -60,20 +60,20 @@ unless Rails.env.production?
|
|||
)
|
||||
|
||||
# sample email collect
|
||||
WootMessageSeeder.create_sample_email_collect_message conversation
|
||||
Seeders::MessageSeeder.create_sample_email_collect_message conversation
|
||||
|
||||
Message.create!(content: 'Hello', account: account, inbox: inbox, conversation: conversation, message_type: :incoming)
|
||||
|
||||
# sample card
|
||||
WootMessageSeeder.create_sample_cards_message conversation
|
||||
Seeders::MessageSeeder.create_sample_cards_message conversation
|
||||
# input select
|
||||
WootMessageSeeder.create_sample_input_select_message conversation
|
||||
Seeders::MessageSeeder.create_sample_input_select_message conversation
|
||||
# form
|
||||
WootMessageSeeder.create_sample_form_message conversation
|
||||
Seeders::MessageSeeder.create_sample_form_message conversation
|
||||
# articles
|
||||
WootMessageSeeder.create_sample_articles_message conversation
|
||||
Seeders::MessageSeeder.create_sample_articles_message conversation
|
||||
# csat
|
||||
WootMessageSeeder.create_sample_csat_collect_message conversation
|
||||
Seeders::MessageSeeder.create_sample_csat_collect_message conversation
|
||||
|
||||
CannedResponse.create!(account: account, short_code: 'start', content: 'Hello welcome to chatwoot.')
|
||||
end
|
||||
|
|
27
lib/seeders/account_seeder.rb
Normal file
27
lib/seeders/account_seeder.rb
Normal file
|
@ -0,0 +1,27 @@
|
|||
## Class to generate sample data for a chatwoot test Account.
|
||||
############################################################
|
||||
### Usage #####
|
||||
#
|
||||
# # Seed an account with all data types in this class
|
||||
# Seeders::AccountSeeder.new(account: account).seed!
|
||||
#
|
||||
# # When you want to seed only a specific type of data
|
||||
# Seeders::AccountSeeder.new(account: account).seed_canned_responses
|
||||
# # Seed specific number of objects
|
||||
# Seeders::AccountSeeder.new(account: account).seed_canned_responses(count: 10)
|
||||
#
|
||||
############################################################
|
||||
|
||||
class Seeders::AccountSeeder
|
||||
pattr_initialize [:account!]
|
||||
|
||||
def seed!
|
||||
seed_canned_responses
|
||||
end
|
||||
|
||||
def seed_canned_responses(count: 50)
|
||||
count.times do
|
||||
account.canned_responses.create(content: Faker::Quote.fortune_cookie, short_code: Faker::Alphanumeric.alpha(number: 10))
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,4 +1,4 @@
|
|||
module WootMessageSeeder
|
||||
module Seeders::MessageSeeder
|
||||
def self.create_sample_email_collect_message(conversation)
|
||||
Message.create!(
|
||||
account: conversation.account,
|
|
@ -25,6 +25,8 @@ RSpec.describe 'Agent Bot API', type: :request do
|
|||
expect(response).to have_http_status(:success)
|
||||
expect(response.body).to include(agent_bot.name)
|
||||
expect(response.body).to include(global_bot.name)
|
||||
expect(response.body).to include(agent_bot.access_token.token)
|
||||
expect(response.body).not_to include(global_bot.access_token.token)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -46,6 +48,7 @@ RSpec.describe 'Agent Bot API', type: :request do
|
|||
|
||||
expect(response).to have_http_status(:success)
|
||||
expect(response.body).to include(agent_bot.name)
|
||||
expect(response.body).to include(agent_bot.access_token.token)
|
||||
end
|
||||
|
||||
it 'will show a global agent bot' do
|
||||
|
@ -56,6 +59,7 @@ RSpec.describe 'Agent Bot API', type: :request do
|
|||
|
||||
expect(response).to have_http_status(:success)
|
||||
expect(response.body).to include(global_bot.name)
|
||||
expect(response.body).not_to include(global_bot.access_token.token)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -113,6 +117,7 @@ RSpec.describe 'Agent Bot API', type: :request do
|
|||
|
||||
expect(response).to have_http_status(:success)
|
||||
expect(agent_bot.reload.name).to eq('test_updated')
|
||||
expect(response.body).to include(agent_bot.access_token.token)
|
||||
end
|
||||
|
||||
it 'would not update the agent bot when agent' do
|
||||
|
@ -134,6 +139,7 @@ RSpec.describe 'Agent Bot API', type: :request do
|
|||
|
||||
expect(response).to have_http_status(:not_found)
|
||||
expect(agent_bot.reload.name).not_to eq('test_updated')
|
||||
expect(response.body).not_to include(global_bot.access_token.token)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue