diff --git a/spec/acceptance/rest/admin/api/active_calls_spec.rb b/spec/acceptance/rest/admin/api/active_calls_spec.rb new file mode 100644 index 000000000..65b7dcb4a --- /dev/null +++ b/spec/acceptance/rest/admin/api/active_calls_spec.rb @@ -0,0 +1,50 @@ +# frozen_string_literal: true + +require 'spec_helper' +require 'rspec_api_documentation/dsl' + +resource 'Contractors' do + header 'Accept', 'application/vnd.api+json' + header 'Content-Type', 'application/vnd.api+json' + header 'Authorization', :auth_token + + let(:user) { create :admin_user } + let(:auth_token) { ::Knock::AuthToken.new(payload: { sub: user.id }).token } + let(:type) { 'active-calls' } + + include_context :active_calls_stub_helpers do + let!(:node) { FactoryGirl.create(:node) } + let(:active_call_attrs) { [:filled, node_id: node.id] } + end + + get '/api/rest/admin/active-calls' do + before { stub_active_calls_collection } + + example_request 'get listing' do + expect(status).to eq(200) + end + end + + get '/api/rest/admin/active-calls/:id' do + let(:id) { "#{active_call_single[:node_id]}*#{active_call_single[:local_tag]}" } + + before { stub_active_call_single } + + example_request 'get specific entry' do + expect(status).to eq(200) + end + end + + delete '/api/rest/admin/active-calls/:id' do + let(:id) { "#{active_call_single[:node_id]}*#{active_call_single[:local_tag]}" } + + before do + stub_active_call_single + stub_active_call_single_destroy + end + + example_request 'delete entry' do + expect(status).to eq(204) + end + end +end diff --git a/spec/support/contexts/json_rpc/active_calls_stub_helpers.rb b/spec/support/contexts/json_rpc/active_calls_stub_helpers.rb new file mode 100644 index 000000000..e3d8e8180 --- /dev/null +++ b/spec/support/contexts/json_rpc/active_calls_stub_helpers.rb @@ -0,0 +1,27 @@ +# frozen_string_literal: true + +RSpec.shared_context :active_calls_stub_helpers do + let(:stub_active_calls_collection) do + cdrs_filter_stub = instance_double(Yeti::CdrsFilter) + expect(Yeti::CdrsFilter).to receive(:new).with(Node.all, {}).and_return(cdrs_filter_stub) + expect(cdrs_filter_stub).to receive(:search).with(only: nil, empty_on_error: true) + .and_return(active_calls_collection.map(&:stringify_keys)) + end + + let(:stub_active_call_single) do + expect_any_instance_of(YetisNode::Client).to receive(:calls) + .with(active_call_single[:local_tag]).once.and_return(active_call_single) + end + + let(:stub_active_call_single_destroy) do + expect_any_instance_of(YetisNode::Client).to receive(:call_disconnect) + .with(active_call_single[:local_tag]).once + end + + let(:active_calls_collection_qty) { 2 } + let(:active_calls_collection) do + FactoryGirl.attributes_for_list(:active_call, active_calls_collection_qty, *active_call_attrs) + end + let(:active_call_single) { FactoryGirl.attributes_for(:active_call, *active_call_attrs) } + let(:active_call_attrs) { [:filled] } +end