-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #503 from senid231/active-calls-api-add-documentat…
…ion-1-8 active calls api add documentation 1.8
- Loading branch information
Showing
2 changed files
with
77 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
27
spec/support/contexts/json_rpc/active_calls_stub_helpers.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |