Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions lib/livekit/agent_dispatch_service_client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def delete_dispatch(dispatch_id, room_name)
self.rpc(
:DeleteDispatch,
request,
headers: auth_header(VideoGrant.new(roomAdmin: true, room: room_name)),
headers: auth_header(video_grant: VideoGrant.new(roomAdmin: true, room: room_name)),
)
end

Expand All @@ -69,7 +69,7 @@ def get_dispatch(dispatch_id, room_name)
res = self.rpc(
:ListDispatch,
request,
headers: auth_header(VideoGrant.new(roomAdmin: true, room: room_name)),
headers: auth_header(video_grant: VideoGrant.new(roomAdmin: true, room: room_name)),
)
if res.agent_dispatches.size > 0
return res.agent_dispatches[0]
Expand All @@ -87,7 +87,7 @@ def list_dispatch(room_name)
res = self.rpc(
:ListDispatch,
request,
headers: auth_header(VideoGrant.new(roomAdmin: true, room: room_name)),
headers: auth_header(video_grant: VideoGrant.new(roomAdmin: true, room: room_name)),
)
res.agent_dispatches
end
Expand Down
96 changes: 96 additions & 0 deletions spec/livekit/agent_dispatch_service_client_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe LiveKit::AgentDispatchServiceClient do
let(:base_url) { 'http://localhost:7880' }
let(:api_key) { 'test_api_key' }
let(:api_secret) { 'test_api_secret' }
let(:client) { described_class.new(base_url, api_key: api_key, api_secret: api_secret) }
let(:room_name) { 'test-room' }
let(:agent_name) { 'test-agent' }
let(:dispatch_id) { 'dispatch-123' }

describe '#create_dispatch' do
it 'calls auth_header with keyword arguments' do
expect(client).to receive(:auth_header).with(
video_grant: have_attributes(roomAdmin: true, room: room_name)
).and_call_original

# Mock the RPC call to avoid actual network request
allow(client).to receive(:rpc).and_return(
LiveKit::Proto::AgentDispatch.new(id: dispatch_id)
)

client.create_dispatch(room_name, agent_name)
end
end

describe '#delete_dispatch' do
it 'calls auth_header with keyword arguments' do
expect(client).to receive(:auth_header).with(
video_grant: instance_of(LiveKit::VideoGrant)
).and_call_original

# Mock the RPC call to avoid actual network request
allow(client).to receive(:rpc).and_return(
LiveKit::Proto::AgentDispatch.new(id: dispatch_id)
)

client.delete_dispatch(dispatch_id, room_name)
end
end

describe '#get_dispatch' do
it 'calls auth_header with keyword arguments' do
expect(client).to receive(:auth_header).with(
video_grant: instance_of(LiveKit::VideoGrant)
).and_call_original

# Mock the RPC call to avoid actual network request
allow(client).to receive(:rpc).and_return(
LiveKit::Proto::ListAgentDispatchResponse.new(
agent_dispatches: [LiveKit::Proto::AgentDispatch.new(id: dispatch_id)]
)
)

client.get_dispatch(dispatch_id, room_name)
end
end

describe '#list_dispatch' do
it 'calls auth_header with keyword arguments' do
expect(client).to receive(:auth_header).with(
video_grant: instance_of(LiveKit::VideoGrant)
).and_call_original

# Mock the RPC call to avoid actual network request
allow(client).to receive(:rpc).and_return(
LiveKit::Proto::ListAgentDispatchResponse.new(
agent_dispatches: []
)
)

client.list_dispatch(room_name)
end
end

describe 'Ruby 3 compatibility' do
it 'does not raise ArgumentError when calling methods' do
# Mock the RPC calls
allow(client).to receive(:rpc).and_return(
LiveKit::Proto::AgentDispatch.new(id: dispatch_id)
)

expect { client.create_dispatch(room_name, agent_name) }.not_to raise_error
expect { client.delete_dispatch(dispatch_id, room_name) }.not_to raise_error

allow(client).to receive(:rpc).and_return(
LiveKit::Proto::ListAgentDispatchResponse.new(agent_dispatches: [])
)

expect { client.get_dispatch(dispatch_id, room_name) }.not_to raise_error
expect { client.list_dispatch(room_name) }.not_to raise_error
end
end
end