From 3465ebefd17167c209fda8879db9401d1669a0d5 Mon Sep 17 00:00:00 2001 From: Tim Lange Date: Sat, 8 Feb 2020 19:18:00 +0100 Subject: [PATCH] Chore: Added tests for assignments_controller (#482) --- .../assignments_controller_spec.rb | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 spec/controllers/api/v1/conversations/assignments_controller_spec.rb diff --git a/spec/controllers/api/v1/conversations/assignments_controller_spec.rb b/spec/controllers/api/v1/conversations/assignments_controller_spec.rb new file mode 100644 index 000000000..822bf9d39 --- /dev/null +++ b/spec/controllers/api/v1/conversations/assignments_controller_spec.rb @@ -0,0 +1,33 @@ +require 'rails_helper' + +RSpec.describe 'Conversation Assignment API', type: :request do + let(:account) { create(:account) } + + describe 'POST /api/v1/conversations//assignments' do + let(:conversation) { create(:conversation, account: account) } + + context 'when it is an unauthenticated user' do + it 'returns unauthorized' do + post api_v1_conversation_assignments_url(conversation.display_id) + + expect(response).to have_http_status(:unauthorized) + end + end + + context 'when it is an authenticated user' do + let(:agent) { create(:user, account: account, role: :agent) } + + it 'assigns a user to the conversation' do + params = { assignee_id: agent.id } + + post api_v1_conversation_assignments_url(conversation.display_id), + params: params, + headers: agent.create_new_auth_token, + as: :json + + expect(response).to have_http_status(:success) + expect(conversation.reload.assignee).to eq(agent) + end + end + end +end