diff --git a/app/controllers/api/v1/projects_controller.rb b/app/controllers/api/v1/projects_controller.rb
index 44685ba..78d3064 100644
--- a/app/controllers/api/v1/projects_controller.rb
+++ b/app/controllers/api/v1/projects_controller.rb
@@ -2,7 +2,7 @@ module Api
module V1
class ProjectsController < ApiController
def index
- response = Faraday.get('http://localhost:3000/api/v1/projects')
+ response = ProjectsService::ColaBoraApiGetProjects.send
if response.status == 200
projects = JSON.parse(response.body)
render status: :ok, json: projects.as_json
@@ -13,9 +13,9 @@ def index
end
def request_invitation
- data = proposal_params.as_json
- connection = Faraday.new(url: 'http://localhost:3000', params: data)
- response = connection.post('api/v1/proposals')
+ invitation_request_id = proposal_params.fetch('invitation_request_id').to_i
+ invitation_request = InvitationRequest.find(invitation_request_id)
+ response = InvitationRequestService::ColaBoraInvitationRequestPost.send(invitation_request)
if response.status == 201
proposal = JSON.parse(response.body)
@@ -29,8 +29,7 @@ def request_invitation
private
def proposal_params
- proposal_attributes = %i[invitation_request_id email message profile_id project_id]
- params.require(:data).permit(proposal: proposal_attributes)
+ params.permit(:invitation_request_id)
end
end
end
diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb
index 73ba19a..8951cd0 100644
--- a/app/controllers/projects_controller.rb
+++ b/app/controllers/projects_controller.rb
@@ -6,6 +6,7 @@ def index
@invitation_request = current_user.invitation_requests.build
@invitation_requests = current_user.invitation_requests.pluck(:project_id).to_json
@invitation_requests_projects_ids = current_user.invitation_requests.pluck(:project_id)
+ @projects_url = Rails.configuration.portfoliorrr_api_v1.projects_url
@free_user = current_user.subscription.inactive?
end
diff --git a/app/javascript/components/projects_vue.js b/app/javascript/components/projects_vue.js
index 142c59c..53b7be4 100644
--- a/app/javascript/components/projects_vue.js
+++ b/app/javascript/components/projects_vue.js
@@ -12,6 +12,7 @@ export default {
invitationRequestsProjectsIds: window.invitationRequestsProjectsIds,
freeUser: window.freeUser,
errorMsg: false,
+ portfoliorrrProjectsApiUrl: window.portfoliorrrProjectsApiUrl,
}
},
computed:{
@@ -47,7 +48,7 @@ export default {
async created() {
if (!freeUser) {
try {
- let response = await fetch('/api/v1/projects', { signal });
+ let response = await fetch(this.portfoliorrrProjectsApiUrl, { signal });
if (response.ok) {
let data = await response.json();
if (!data.message) {
diff --git a/app/jobs/decline_invitation_job.rb b/app/jobs/decline_invitation_job.rb
index 85d2149..7588ff9 100644
--- a/app/jobs/decline_invitation_job.rb
+++ b/app/jobs/decline_invitation_job.rb
@@ -1,10 +1,12 @@
class DeclineInvitationJob < ApplicationJob
+ PORTFOLIORRR_BASE_URL = Rails.configuration.portfoliorrr_api_v1.base_url
+ PORTFOLIORRR_INVITATION_URL = Rails.configuration.portfoliorrr_api_v1.invitations_url
retry_on Faraday::ConnectionFailed, Faraday::ServerError, wait: :polynomially_longer, attempts: 5 do |job|
job.arguments.first.pending!
end
def perform(invitation)
- url = "http://localhost:4000/api/v1/invitations/#{invitation.colabora_invitation_id}"
+ url = "#{PORTFOLIORRR_BASE_URL}#{PORTFOLIORRR_INVITATION_URL}#{invitation.colabora_invitation_id}"
Faraday.new { |faraday| faraday.response :raise_error }.patch(url)
invitation.declined!
rescue Faraday::ResourceNotFound, Faraday::ConflictError
diff --git a/app/jobs/request_invitation_job.rb b/app/jobs/request_invitation_job.rb
index 23b5659..2805113 100644
--- a/app/jobs/request_invitation_job.rb
+++ b/app/jobs/request_invitation_job.rb
@@ -1,4 +1,6 @@
class RequestInvitationJob < ApplicationJob
+ PORTFOLIORRR_BASE_URL = Rails.configuration.portfoliorrr_api_v1.base_url
+ PORTFOLIORRRR_REQUEST_INVITATION_URL = Rails.configuration.portfoliorrr_api_v1.request_invitation_url
queue_as :default
retry_on Exceptions::PortfoliorrrAPIOffline, wait: 1.hour, attempts: :unlimited
retry_on Exceptions::ColaBoraAPIOffline, wait: 1.hour, attempts: 5 do |job, _error|
@@ -6,8 +8,8 @@ class RequestInvitationJob < ApplicationJob
end
def perform(invitation_request:)
- data = invitation_request.create_json_for_proposal_request
- response = Faraday.new(url: 'http://localhost:4000', params: data).get('/api/v1/projects/request_invitation')
+ data = { invitation_request_id: invitation_request.id }.as_json
+ response = Faraday.new(url: PORTFOLIORRR_BASE_URL, params: data).get(PORTFOLIORRRR_REQUEST_INVITATION_URL)
return raise Exceptions::PortfoliorrrAPIOffline if response.status == :internal_server_error
invitation_request.process_colabora_api_response(response)
diff --git a/app/models/invitation_request.rb b/app/models/invitation_request.rb
index ac2723f..2edd0af 100644
--- a/app/models/invitation_request.rb
+++ b/app/models/invitation_request.rb
@@ -22,14 +22,6 @@ def process_colabora_api_response(response)
end
end
- def create_json_for_proposal_request
- { data: { proposal: { invitation_request_id: id,
- project_id:,
- profile_id: profile.id,
- email: profile.email,
- message: } } }.as_json
- end
-
private
def json_treated_response(response)
diff --git a/app/services/invitation_request_service.rb b/app/services/invitation_request_service.rb
index 85a38c5..7822f0e 100644
--- a/app/services/invitation_request_service.rb
+++ b/app/services/invitation_request_service.rb
@@ -1,35 +1,15 @@
module InvitationRequestService
- COLABORA_PROJECTS_URL = 'http://localhost:3000/api/v1/projects'.freeze
- COLABORA_INVITATIONS_BASE_URL = 'http://localhost:3000/api/v1/invitations'.freeze
+ include ProjectsService
- class ColaboraProject
- def self.send
- @response = Faraday.get(COLABORA_PROJECTS_URL)
- return build_projects if @response.success?
-
- raise StandardError
- end
-
- class << self
- private
-
- def build_projects
- projects = JSON.parse(@response.body, symbolize_names: true)
- projects.map do |project|
- Project.new(id: project[:id],
- title: project[:title],
- description: project[:description],
- category: project[:category])
- end
- end
- end
- end
+ COLABORA_BASE_URL = Rails.configuration.colabora_api_v1.base_url
+ COLABORA_API_V1_PROJECTS_URL = Rails.configuration.colabora_api_v1.projects_url
+ COLABORA_API_V1_PROPOSALS_URL = Rails.configuration.colabora_api_v1.proposals_url
class InvitationRequest
def self.send(requests)
return [] if requests.empty?
- projects = ColaboraProject.send
+ projects = ProjectsService::ColaBoraProject.send
requests.map do |request|
project = projects.find { |proj| proj.id == request.project_id }
@@ -37,4 +17,28 @@ def self.send(requests)
end
end
end
+
+ class ColaBoraInvitationRequestPost
+ def self.send(invitation_request)
+ @invitation_request = invitation_request
+ post_connection
+
+ @response
+ end
+
+ class << self
+ private
+
+ def build_invitation_request_params(invitation_request)
+ { 'proposal': { 'invitation_request_id': invitation_request.id, 'email': invitation_request.profile.email,
+ 'message': invitation_request.message, 'profile_id': invitation_request.profile.id,
+ 'project_id': invitation_request.project_id } }.as_json
+ end
+
+ def post_connection
+ url = "#{COLABORA_BASE_URL}#{COLABORA_API_V1_PROPOSALS_URL}"
+ @response = Faraday.post(url, build_invitation_request_params(@invitation_request))
+ end
+ end
+ end
end
diff --git a/app/services/projects_service.rb b/app/services/projects_service.rb
new file mode 100644
index 0000000..449f2d6
--- /dev/null
+++ b/app/services/projects_service.rb
@@ -0,0 +1,34 @@
+module ProjectsService
+ COLABORA_BASE_URL = Rails.configuration.colabora_api_v1.base_url
+ COLABORA_API_V1_PROJECTS_URL = Rails.configuration.colabora_api_v1.projects_url
+
+ class ColaBoraProject
+ def self.send
+ @response = ColaBoraApiGetProjects.send
+ return build_projects if @response.success?
+
+ raise StandardError
+ end
+
+ class << self
+ private
+
+ def build_projects
+ projects = JSON.parse(@response.body, symbolize_names: true)
+ projects.map do |project|
+ Project.new(id: project[:id],
+ title: project[:title],
+ description: project[:description],
+ category: project[:category])
+ end
+ end
+ end
+ end
+
+ class ColaBoraApiGetProjects
+ def self.send
+ url = "#{COLABORA_BASE_URL}#{COLABORA_API_V1_PROJECTS_URL}"
+ Faraday.get(url)
+ end
+ end
+end
diff --git a/app/views/invitations/show.html.erb b/app/views/invitations/show.html.erb
index e6c2f0a..7ce9ebb 100644
--- a/app/views/invitations/show.html.erb
+++ b/app/views/invitations/show.html.erb
@@ -16,7 +16,7 @@
<% if @invitation.pending? %>
- <%= link_to t('accept_btn'), 'http://localhost:3000', class: 'btn btn-primary me-4' %>
+ <%= link_to t('accept_btn'), Rails.configuration.colabora_api_v1.base_url, class: 'btn btn-primary me-4' %>
<%= button_to t('decline_btn'), decline_invitation_path(@invitation), method: :patch, class: 'btn btn-secondary' %>
diff --git a/app/views/projects/index.html.erb b/app/views/projects/index.html.erb
index 40bbd77..a1e7925 100644
--- a/app/views/projects/index.html.erb
+++ b/app/views/projects/index.html.erb
@@ -74,6 +74,7 @@
diff --git a/config/application.rb b/config/application.rb
index ff33ae3..b2e37ee 100644
--- a/config/application.rb
+++ b/config/application.rb
@@ -38,5 +38,11 @@ class Application < Rails::Application
# Don't generate system test files.
config.generators.system_tests = nil
+
+ # ColaBora API configurations
+ config.colabora_api_v1 = config_for(:colabora_api_v1)
+
+ # Portfoliorrr API configurations
+ config.portfoliorrr_api_v1 = config_for(:portfoliorrr_api_v1)
end
end
diff --git a/config/colabora_api_v1.yml b/config/colabora_api_v1.yml
new file mode 100644
index 0000000..9168649
--- /dev/null
+++ b/config/colabora_api_v1.yml
@@ -0,0 +1,9 @@
+development:
+ base_url: 'http://localhost:3000'
+ projects_url: '/api/v1/projects'
+ proposals_url: '/api/v1/proposals'
+
+test:
+ base_url: 'http://localhost:3000'
+ projects_url: '/api/v1/projects'
+ proposals_url: '/api/v1/proposals'
\ No newline at end of file
diff --git a/config/portfoliorrr_api_v1.yml b/config/portfoliorrr_api_v1.yml
new file mode 100644
index 0000000..75c9712
--- /dev/null
+++ b/config/portfoliorrr_api_v1.yml
@@ -0,0 +1,11 @@
+development:
+ base_url: 'http://localhost:4000'
+ invitations_url: '/api/v1/invitations/'
+ request_invitation_url: '/api/v1/projects/request_invitation'
+ projects_url: '/api/v1/projects'
+
+test:
+ base_url: 'http://localhost:4000'
+ invitations_url: '/api/v1/invitations/'
+ request_invitation_url: '/api/v1/projects/request_invitation'
+ projects_url: '/api/v1/projects'
diff --git a/spec/jobs/request_invitation_job_spec.rb b/spec/jobs/request_invitation_job_spec.rb
index d72a645..7b97c16 100644
--- a/spec/jobs/request_invitation_job_spec.rb
+++ b/spec/jobs/request_invitation_job_spec.rb
@@ -3,11 +3,7 @@
RSpec.describe RequestInvitationJob, type: :job do
it 'altera a solicitação de convite para pending caso receba uma confirmação de sucesso do Cola?Bora!' do
invitation_request = create(:invitation_request)
- invitation_request_params = { data: { proposal: { invitation_request_id: invitation_request.id,
- project_id: invitation_request.project_id,
- profile_id: invitation_request.profile.id,
- email: invitation_request.profile.email,
- message: invitation_request.message } } }.as_json
+ invitation_request_params = { invitation_request_id: invitation_request.id }.as_json
json_proposal_response = File.read(Rails.root.join('./spec/support/json/proposal_201.json'))
fake_portfoliorrr_response = double('faraday_response', status: :ok, body: json_proposal_response)
@@ -30,11 +26,7 @@
it 'enfileira um novo job caso receba um aviso de erro no servidor do Cola?Bora!' do
invitation_request = create(:invitation_request)
- invitation_request_params = { data: { proposal: { invitation_request_id: invitation_request.id,
- project_id: invitation_request.project_id,
- profile_id: invitation_request.profile.id,
- email: invitation_request.profile.email,
- message: invitation_request.message } } }.as_json
+ invitation_request_params = { invitation_request_id: invitation_request.id }.as_json
fake_colabora_response_body = { 'errors': ['Erro interno de servidor.'] }.as_json
fake_portfoliorrr_response = double('faraday_response', status: :ok, body: fake_colabora_response_body)
@@ -57,11 +49,7 @@
it 'altera a solicitação de convite para error caso receba um aviso de erro do Cola?Bora!' do
invitation_request = create(:invitation_request)
- invitation_request_params = { data: { proposal: { invitation_request_id: invitation_request.id,
- project_id: invitation_request.project_id,
- profile_id: invitation_request.profile.id,
- email: invitation_request.profile.email,
- message: invitation_request.message } } }.as_json
+ invitation_request_params = { invitation_request_id: invitation_request.id }.as_json
fake_colabora_response_body = { 'errors': ['Usuário já faz parte deste projeto'] }.as_json
fake_portfoliorrr_response = double('faraday_response', status: :ok, body: fake_colabora_response_body)
@@ -84,11 +72,7 @@
it 'altera a solicitação de convite para aborted se receber pela quinta vez um erro da API do Cola?Bora!' do
invitation_request = create(:invitation_request)
- invitation_request_params = { data: { proposal: { invitation_request_id: invitation_request.id,
- project_id: invitation_request.project_id,
- profile_id: invitation_request.profile.id,
- email: invitation_request.profile.email,
- message: invitation_request.message } } }.as_json
+ invitation_request_params = { invitation_request_id: invitation_request.id }.as_json
fake_colabora_response_body = { 'errors': ['Erro interno de servidor.'] }.as_json
fake_portfoliorrr_response = double('faraday_response', status: :ok, body: fake_colabora_response_body)
@@ -114,11 +98,7 @@
it 'gera uma nova tentativa caso a API do Portfoliorrr esteja fora do ar, sem limite de tentativas' do
invitation_request = create(:invitation_request)
- invitation_request_params = { data: { proposal: { invitation_request_id: invitation_request.id,
- project_id: invitation_request.project_id,
- profile_id: invitation_request.profile.id,
- email: invitation_request.profile.email,
- message: invitation_request.message } } }.as_json
+ invitation_request_params = { invitation_request_id: invitation_request.id }.as_json
fake_response_body = { 'error': 'Houve um erro interno no servidor ao processar sua solicitação.' }.as_json
fake_portfoliorrr_response = double('faraday_response', status: :internal_server_error, body: fake_response_body)
diff --git a/spec/requests/apis/v1/projects/projects_request_invitations_api_spec.rb b/spec/requests/apis/v1/projects/projects_request_invitations_api_spec.rb
index c02a437..39d086b 100644
--- a/spec/requests/apis/v1/projects/projects_request_invitations_api_spec.rb
+++ b/spec/requests/apis/v1/projects/projects_request_invitations_api_spec.rb
@@ -4,25 +4,19 @@
context 'GET /api/v1/projects/request_invitation' do
it 'com sucesso e recebe confirmação da criação de proposal' do
invitation_request = create(:invitation_request)
- invitation_request_params = { data: { proposal: { invitation_request_id: invitation_request.id.to_s,
- project_id: invitation_request.project_id.to_s,
- profile_id: invitation_request.profile.id.to_s,
+ invitation_request_params = { data: { proposal: { invitation_request_id: invitation_request.id,
email: invitation_request.profile.email,
- message: invitation_request.message } } }.as_json
+ message: invitation_request.message,
+ profile_id: invitation_request.profile.id,
+ project_id: invitation_request.project_id } } }.as_json
json_proposal_response = File.read(Rails.root.join('./spec/support/json/proposal_201.json'))
fake_colabora_response = double('faraday_response', status: 201, body: json_proposal_response)
- colabora_api_connection = double('Faraday::Connection', post: fake_colabora_response)
- allow(Faraday).to receive(:new)
- .with(url: 'http://localhost:3000', params: invitation_request_params['data'])
- .and_return(colabora_api_connection)
- allow(colabora_api_connection)
- .to receive(:post)
- .with('/api/v1/proposals')
- .and_return(fake_colabora_response)
-
- get '/api/v1/projects/request_invitation', params: invitation_request_params
+ url = 'http://localhost:3000/api/v1/proposals'
+ allow(Faraday).to receive(:post).with(url, invitation_request_params['data'])
+ .and_return(fake_colabora_response)
+ get '/api/v1/projects/request_invitation', params: { invitation_request_id: invitation_request.id }.as_json
expect(response).to have_http_status :ok
expect(response.content_type).to include 'application/json'
json_response = JSON.parse(response.body)
@@ -32,24 +26,19 @@
it 'com sucesso, mas recebe alerta de erro 404 do Cola?Bora!' do
invitation_request = create(:invitation_request)
- invitation_request_params = { data: { proposal: { invitation_request_id: invitation_request.id.to_s,
- project_id: invitation_request.project_id.to_s,
- profile_id: invitation_request.profile.id.to_s,
+ invitation_request_params = { data: { proposal: { invitation_request_id: invitation_request.id,
email: invitation_request.profile.email,
- message: invitation_request.message } } }.as_json
+ message: invitation_request.message,
+ profile_id: invitation_request.profile.id,
+ project_id: invitation_request.project_id } } }.as_json
+ url = 'http://localhost:3000/api/v1/proposals'
fake_colabora_response_body = { 'errors': ['Projeto não encontrado'] }.as_json
fake_colabora_response = double('faraday_response', status: 404, body: fake_colabora_response_body)
- colabora_api_connection = double('Faraday::Connection', post: fake_colabora_response)
- allow(Faraday).to receive(:new)
- .with(url: 'http://localhost:3000', params: invitation_request_params['data'])
- .and_return(colabora_api_connection)
- allow(colabora_api_connection)
- .to receive(:post)
- .with('/api/v1/proposals')
- .and_return(fake_colabora_response)
+ allow(Faraday).to receive(:post).with(url, invitation_request_params['data'])
+ .and_return(fake_colabora_response)
- get '/api/v1/projects/request_invitation', params: invitation_request_params
+ get '/api/v1/projects/request_invitation', params: { invitation_request_id: invitation_request.id }.as_json
expect(response).to have_http_status :ok
expect(response.content_type).to include 'application/json'
@@ -60,24 +49,19 @@
it 'com sucesso, mas recebe alerta de erro 409 do Cola?Bora!' do
invitation_request = create(:invitation_request)
- invitation_request_params = { data: { proposal: { invitation_request_id: invitation_request.id.to_s,
- project_id: invitation_request.project_id.to_s,
- profile_id: invitation_request.profile.id.to_s,
+ invitation_request_params = { data: { proposal: { invitation_request_id: invitation_request.id,
email: invitation_request.profile.email,
- message: invitation_request.message } } }.as_json
+ message: invitation_request.message,
+ profile_id: invitation_request.profile.id,
+ project_id: invitation_request.project_id } } }.as_json
+ url = 'http://localhost:3000/api/v1/proposals'
fake_colabora_response_body = { 'errors': ['Usuário já faz parte deste projeto'] }.as_json
fake_colabora_response = double('faraday_response', status: 409, body: fake_colabora_response_body)
- colabora_api_connection = double('Faraday::Connection', post: fake_colabora_response)
- allow(Faraday).to receive(:new)
- .with(url: 'http://localhost:3000', params: invitation_request_params['data'])
- .and_return(colabora_api_connection)
- allow(colabora_api_connection)
- .to receive(:post)
- .with('/api/v1/proposals')
- .and_return(fake_colabora_response)
+ allow(Faraday).to receive(:post).with(url, invitation_request_params['data'])
+ .and_return(fake_colabora_response)
- get '/api/v1/projects/request_invitation', params: invitation_request_params
+ get '/api/v1/projects/request_invitation', params: { invitation_request_id: invitation_request.id }.as_json
expect(response).to have_http_status :ok
expect(response.content_type).to include 'application/json'
@@ -88,24 +72,19 @@
it 'com sucesso, mas recebe alerta de erro 500 do Cola?Bora!' do
invitation_request = create(:invitation_request)
- invitation_request_params = { data: { proposal: { invitation_request_id: invitation_request.id.to_s,
- project_id: invitation_request.project_id.to_s,
- profile_id: invitation_request.profile.id.to_s,
+ invitation_request_params = { data: { proposal: { invitation_request_id: invitation_request.id,
email: invitation_request.profile.email,
- message: invitation_request.message } } }.as_json
+ message: invitation_request.message,
+ profile_id: invitation_request.profile.id,
+ project_id: invitation_request.project_id } } }.as_json
+ url = 'http://localhost:3000/api/v1/proposals'
fake_colabora_response_body = { 'errors': ['Erro interno de servidor.'] }.as_json
fake_colabora_response = double('faraday_response', status: 500, body: fake_colabora_response_body)
- colabora_api_connection = double('Faraday::Connection', post: fake_colabora_response)
- allow(Faraday).to receive(:new)
- .with(url: 'http://localhost:3000', params: invitation_request_params['data'])
- .and_return(colabora_api_connection)
- allow(colabora_api_connection)
- .to receive(:post)
- .with('/api/v1/proposals')
- .and_return(fake_colabora_response)
+ allow(Faraday).to receive(:post).with(url, invitation_request_params['data'])
+ .and_return(fake_colabora_response)
- get '/api/v1/projects/request_invitation', params: invitation_request_params
+ get '/api/v1/projects/request_invitation', params: { invitation_request_id: invitation_request.id }.as_json
expect(response).to have_http_status :ok
expect(response.content_type).to include 'application/json'
@@ -116,17 +95,17 @@
it 'e retorna erro interno do servidor no Portfoliorrr' do
invitation_request = create(:invitation_request)
- invitation_request_params = { data: { proposal: { invitation_request_id: invitation_request.id.to_s,
- project_id: invitation_request.project_id.to_s,
- profile_id: invitation_request.profile.id.to_s,
+ invitation_request_params = { data: { proposal: { invitation_request_id: invitation_request.id,
email: invitation_request.profile.email,
- message: invitation_request.message } } }.as_json
+ message: invitation_request.message,
+ profile_id: invitation_request.profile.id,
+ project_id: invitation_request.project_id } } }.as_json
- allow(Faraday).to receive(:new)
- .with(url: 'http://localhost:3000', params: invitation_request_params['data'])
- .and_raise(ActiveRecord::ConnectionNotEstablished)
+ url = 'http://localhost:3000/api/v1/proposals'
+ allow(Faraday).to receive(:post).with(url, invitation_request_params['data'])
+ .and_raise(ActiveRecord::ConnectionNotEstablished)
- get '/api/v1/projects/request_invitation', params: invitation_request_params
+ get '/api/v1/projects/request_invitation', params: { invitation_request_id: invitation_request.id }.as_json
expect(response).to have_http_status :internal_server_error
json_response = JSON.parse(response.body)
diff --git a/spec/services/invitation_request_service/colabora_invitation_request_post_spec.rb b/spec/services/invitation_request_service/colabora_invitation_request_post_spec.rb
new file mode 100644
index 0000000..8d8830e
--- /dev/null
+++ b/spec/services/invitation_request_service/colabora_invitation_request_post_spec.rb
@@ -0,0 +1,18 @@
+require 'rails_helper'
+
+RSpec.describe InvitationRequestService::ColaBoraInvitationRequestPost do
+ context '.send' do
+ it 'retorna a resposta da requisição feita ao ColaBora' do
+ invitation_request = create(:invitation_request)
+ fake_colabora_body = File.read(Rails.root.join('./spec/support/json/proposal_201.json'))
+ fake_colabora_response = double('faraday_response', status: 201, body: fake_colabora_body)
+ allow(Faraday).to receive(:post).and_return(fake_colabora_response)
+
+ response = InvitationRequestService::ColaBoraInvitationRequestPost.send(invitation_request)
+
+ json_response = JSON.parse(response.body)
+ expect(json_response.class).to eq Hash
+ expect(json_response['data']['proposal_id']).to eq 1
+ end
+ end
+end
diff --git a/spec/services/projects_service/colabora_api_get_projects_spec.rb b/spec/services/projects_service/colabora_api_get_projects_spec.rb
new file mode 100644
index 0000000..ebfcffa
--- /dev/null
+++ b/spec/services/projects_service/colabora_api_get_projects_spec.rb
@@ -0,0 +1,18 @@
+require 'rails_helper'
+
+RSpec.describe ProjectsService::ColaBoraApiGetProjects do
+ context '.send' do
+ it 'retorna array de objetos do tipo Project' do
+ json_data = File.read(Rails.root.join('./spec/support/json/projects.json'))
+ fake_response = double('faraday_response', success?: true, body: json_data)
+
+ allow(Faraday).to receive(:get).with('http://localhost:3000/api/v1/projects').and_return(fake_response)
+
+ result = ProjectsService::ColaBoraApiGetProjects.send
+
+ json_response = JSON.parse(result.body)
+ expect(json_response.class).to eq Array
+ expect(json_response.count).to eq 4
+ end
+ end
+end
diff --git a/spec/services/invitation_request_service/colabora_project_spec.rb b/spec/services/projects_service/colabora_project_spec.rb
similarity index 82%
rename from spec/services/invitation_request_service/colabora_project_spec.rb
rename to spec/services/projects_service/colabora_project_spec.rb
index 8dcab46..7917426 100644
--- a/spec/services/invitation_request_service/colabora_project_spec.rb
+++ b/spec/services/projects_service/colabora_project_spec.rb
@@ -1,6 +1,6 @@
require 'rails_helper'
-RSpec.describe InvitationRequestService::ColaboraProject do
+RSpec.describe ProjectsService::ColaBoraProject do
context '.send' do
it 'retorna array de objetos do tipo Project' do
json_data = File.read(Rails.root.join('./spec/support/json/projects.json'))
@@ -20,9 +20,9 @@
category: 'Industrial')
]
allow(Faraday).to receive(:get).with('http://localhost:3000/api/v1/projects').and_return(fake_response)
- allow(InvitationRequestService::ColaboraProject).to receive(:build_projects).and_return(projects)
+ allow(ProjectsService::ColaBoraProject).to receive(:build_projects).and_return(projects)
- result = InvitationRequestService::ColaboraProject.send
+ result = ProjectsService::ColaBoraProject.send
expect(result.class).to eq Array
expect(result.count).to eq 4
@@ -33,7 +33,7 @@
fake_response = double('faraday_response', success?: false, status: :internal_server_error)
allow(Faraday).to receive(:get).with('http://localhost:3000/api/v1/projects').and_return(fake_response)
- expect { InvitationRequestService::ColaboraProject.send }.to raise_error(StandardError)
+ expect { ProjectsService::ColaBoraProject.send }.to raise_error(StandardError)
end
end
end