-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
218 additions
and
28 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,27 @@ | ||
name: build | ||
on: | ||
- push | ||
- pull_request | ||
jobs: | ||
build: | ||
strategy: | ||
fail-fast: false | ||
matrix: | ||
ruby: ['2.1', '2.2', '2.3', '2.4', '2.5', '2.6', '2.7', 'jruby-9.1.17', 'jruby-9.2.21'] | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v3 | ||
|
||
- name: Setup Ruby | ||
uses: ruby/setup-ruby@v1 | ||
with: | ||
ruby-version: ${{ matrix.ruby }} | ||
bundler: 1.17.3 | ||
bundler-cache: true | ||
|
||
- name: Create build | ||
run: bundle exec rake build | ||
|
||
- name: Run Specs | ||
run: bundle exec rake spec |
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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
*.swp | ||
Gemfile.lock | ||
pkg | ||
.tool-versions |
This file was deleted.
Oops, something went wrong.
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
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
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
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
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
# encoding: utf-8 | ||
class ElectricSlide | ||
VERSION = '0.5.0' | ||
VERSION = '0.5.1' | ||
end |
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 |
---|---|---|
|
@@ -63,4 +63,56 @@ def foo | |
expect(old_presence).to eq :unavailable | ||
expect(extra_params[:triggered_by]).to eq 'auto' | ||
end | ||
|
||
describe '#update' do | ||
it 'returns the agent' do | ||
expect(subject.update).to eq(subject) | ||
end | ||
|
||
context 'when given a hash with an agent attribute as key' do | ||
it "sets the corresponding agent's attribute to the given value" do | ||
expect { | ||
subject.update(address: '[email protected]') | ||
}.to change(subject, :address).from('[email protected]').to('[email protected]') | ||
end | ||
end | ||
|
||
context 'when given an non-hash argument' do | ||
it 'raises an error' do | ||
expect { | ||
subject.update(nil) | ||
}.to raise_error(ArgumentError, 'Agent attributes must be a hash') | ||
end | ||
end | ||
|
||
context 'when given a hash with a key that does not correspond to any agent attribute' do | ||
it "raises an error" do | ||
expect { | ||
subject.update(blah: 1) | ||
}.to raise_error(NoMethodError) | ||
end | ||
end | ||
end | ||
|
||
describe '#callable?' do | ||
context 'when the agent has an address' do | ||
before do | ||
subject.address = 'Baker St.' | ||
end | ||
|
||
it 'returns `true`' do | ||
expect(subject).to be_callable | ||
end | ||
end | ||
|
||
context 'when the agent has no address' do | ||
before do | ||
subject.address = '' | ||
end | ||
|
||
it 'returns `false`' do | ||
expect(subject).to_not be_callable | ||
end | ||
end | ||
end | ||
end |
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 |
---|---|---|
|
@@ -54,6 +54,7 @@ | |
let(:agent_id) { '123' } | ||
let(:agent) { ElectricSlide::Agent.new id: agent_id, address: '123', presence: :available } | ||
let!(:agent_call) { Adhearsion::OutboundCall.new } | ||
let!(:new_agent_call) { Adhearsion::OutboundCall.new } | ||
let(:queued_call) { dummy_call } | ||
let(:connected_time) { DateTime.now } | ||
|
||
|
@@ -71,6 +72,7 @@ | |
|
||
before do | ||
allow(agent_call).to receive(:dial) | ||
allow(new_agent_call).to receive(:dial) | ||
queue.add_agent agent | ||
queue.enqueue queued_call | ||
end | ||
|
@@ -101,6 +103,16 @@ | |
}.to change(agent, :call).from(agent_call).to(nil) | ||
end | ||
|
||
it "does not unsets the agent's `call` attribute when the agent connects to another call" do | ||
queue.remove_agent double_agent # We only want one agent in the queue so they get the next call | ||
allow(Adhearsion::OutboundCall).to receive(:new) { new_agent_call } | ||
queue.enqueue dummy_call # We want another call to be waiting after this call | ||
|
||
expect { | ||
agent_call << Punchblock::Event::End.new(reason: :hangup) | ||
}.to change(agent, :call).from(agent_call).to(new_agent_call) | ||
end | ||
|
||
context "when the return strategy is :auto" do | ||
let(:agent_return_method) { :auto } | ||
|
||
|
@@ -287,6 +299,54 @@ | |
end | ||
end | ||
|
||
describe '#update_agent' do | ||
let(:queue) { ElectricSlide::CallQueue.new(connection_type: :call) } | ||
let(:agent) { ElectricSlide::Agent.new(id: '1', address: '[email protected]', presence: :on_call) } | ||
|
||
before do | ||
queue.add_agent(agent) | ||
end | ||
|
||
it 'updates the agent with the given attributes' do | ||
expect { | ||
queue.update_agent(agent, address: '[email protected]') | ||
}.to change(agent, :address).from('[email protected]').to('[email protected]') | ||
end | ||
|
||
it 'returns the agent to the queue' do | ||
expect(queue.wrapped_object).to receive(:return_agent).with(agent, :on_call) | ||
queue.update_agent(agent, address: '[email protected]') | ||
end | ||
|
||
context 'when given a set of attributes that makes the agent unacceptable in the queue' do | ||
it 'raises an error' do | ||
expect { | ||
queue.update_agent(agent, address: '') | ||
}.to raise_error(ArgumentError, 'Agent has no callable address') | ||
end | ||
|
||
it "does not change the agent's attributes" do | ||
expect { queue.update_agent(agent, address: '') }.to raise_error(ArgumentError) | ||
|
||
expect(agent.id).to eq('1') | ||
expect(agent.address).to eq('[email protected]') | ||
expect(agent.presence).to eq(:on_call) | ||
end | ||
end | ||
|
||
context 'when given an agent not in the queue' do | ||
before do | ||
queue.remove_agent agent | ||
end | ||
|
||
it 'raises an error' do | ||
expect { | ||
queue.update_agent(agent, address: '[email protected]') | ||
}.to raise_error(ElectricSlide::CallQueue::MissingAgentError, 'Agent is not in the queue') | ||
end | ||
end | ||
end | ||
|
||
describe '#return_agent' do | ||
let(:queue) { ElectricSlide::CallQueue.new } | ||
let(:agent) { ElectricSlide::Agent.new(id: '1', address: '[email protected]', presence: :on_call) } | ||
|