Skip to content

Commit

Permalink
Merge pull request #503 from senid231/active-calls-api-add-documentat…
Browse files Browse the repository at this point in the history
…ion-1-8

active calls api add documentation 1.8
  • Loading branch information
dmitry-sinina authored Jul 15, 2019
2 parents 5ae9d69 + d8e48bd commit 0e260ac
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 0 deletions.
50 changes: 50 additions & 0 deletions spec/acceptance/rest/admin/api/active_calls_spec.rb
Original file line number Diff line number Diff line change
@@ -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
27 changes: 27 additions & 0 deletions spec/support/contexts/json_rpc/active_calls_stub_helpers.rb
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 0e260ac

Please sign in to comment.