Chore: Added tests for conversations messages controller (#575)

This commit is contained in:
Tim Lange 2020-03-01 00:26:30 +01:00 committed by GitHub
parent 7f26b34b15
commit bbf01037c6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -0,0 +1,34 @@
require 'rails_helper'
RSpec.describe 'Conversation Messages API', type: :request do
let(:account) { create(:account) }
describe 'POST /api/v1/conversations/<id>/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