From bbf01037c68e6a45508659ae3ae554feb1e1c09b Mon Sep 17 00:00:00 2001 From: Tim Lange Date: Sun, 1 Mar 2020 00:26:30 +0100 Subject: [PATCH] Chore: Added tests for conversations messages controller (#575) --- .../conversations/messages_controller_spec.rb | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 spec/controllers/api/v1/conversations/messages_controller_spec.rb diff --git a/spec/controllers/api/v1/conversations/messages_controller_spec.rb b/spec/controllers/api/v1/conversations/messages_controller_spec.rb new file mode 100644 index 000000000..7febd1058 --- /dev/null +++ b/spec/controllers/api/v1/conversations/messages_controller_spec.rb @@ -0,0 +1,34 @@ +require 'rails_helper' + +RSpec.describe 'Conversation Messages API', type: :request do + let(:account) { create(:account) } + + describe 'POST /api/v1/conversations//messages' do + let(:conversation) { create(:conversation, account: account) } + + context 'when it is an unauthenticated user' do + it 'returns unauthorized' do + post api_v1_conversation_messages_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 'creates a new outgoing message' do + params = { message: 'test-message', private: true } + + post api_v1_conversation_messages_url(conversation.display_id), + params: params, + headers: agent.create_new_auth_token, + as: :json + + expect(response).to have_http_status(:success) + expect(conversation.messages.count).to eq(1) + expect(conversation.messages.first.content).to eq(params[:message]) + end + end + end +end