feat: allow adding custom attributes to conversations from the SDK (#6782)
* feat: add conversation attributes method to sdk and widget app * feat: add endpoints to update custom attributes * refactor: update SDK api * feat: add api and actions for conversation updates * fix: error message * test: custom attributes on conversations controller --------- Co-authored-by: Muhsin Keloth <muhsinkeramam@gmail.com>
This commit is contained in:
@@ -255,4 +255,59 @@ RSpec.describe '/api/v1/widget/conversations/toggle_typing', type: :request do
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe 'POST /api/v1/widget/conversations/set_custom_attributes' do
|
||||
let(:params) { { website_token: web_widget.website_token, custom_attributes: { 'product_name': 'Chatwoot' } } }
|
||||
|
||||
context 'with invalid website token' do
|
||||
it 'returns unauthorized' do
|
||||
post '/api/v1/widget/conversations/set_custom_attributes', params: { website_token: '' }
|
||||
expect(response).to have_http_status(:not_found)
|
||||
end
|
||||
end
|
||||
|
||||
context 'with correct website token' do
|
||||
it 'sets the values when provided' do
|
||||
post '/api/v1/widget/conversations/set_custom_attributes',
|
||||
headers: { 'X-Auth-Token' => token },
|
||||
params: params,
|
||||
as: :json
|
||||
|
||||
expect(response).to have_http_status(:success)
|
||||
conversation.reload
|
||||
# conversation custom attributes should have "product_name" key with value "Chatwoot"
|
||||
expect(conversation.custom_attributes).to include('product_name' => 'Chatwoot')
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe 'POST /api/v1/widget/conversations/destroy_custom_attributes' do
|
||||
let(:params) { { website_token: web_widget.website_token, custom_attribute: ['product_name'] } }
|
||||
|
||||
context 'with invalid website token' do
|
||||
it 'returns unauthorized' do
|
||||
post '/api/v1/widget/conversations/destroy_custom_attributes', params: { website_token: '' }
|
||||
expect(response).to have_http_status(:not_found)
|
||||
end
|
||||
end
|
||||
|
||||
context 'with correct website token' do
|
||||
it 'sets the values when provided' do
|
||||
# ensure conversation has the attribute
|
||||
conversation.custom_attributes = { 'product_name': 'Chatwoot' }
|
||||
conversation.save!
|
||||
expect(conversation.custom_attributes).to include('product_name' => 'Chatwoot')
|
||||
|
||||
post '/api/v1/widget/conversations/destroy_custom_attributes',
|
||||
headers: { 'X-Auth-Token' => token },
|
||||
params: params,
|
||||
as: :json
|
||||
|
||||
expect(response).to have_http_status(:success)
|
||||
conversation.reload
|
||||
# conversation custom attributes should not have "product_name" key with value "Chatwoot"
|
||||
expect(conversation.custom_attributes).not_to include('product_name' => 'Chatwoot')
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user