chore: Disable copilot usage after the response count is over (#11845)
Disable copilot if the response usage is over.
This commit is contained in:
@@ -86,7 +86,28 @@ RSpec.describe 'Api::V1::Accounts::Captain::CopilotThreads', type: :request do
|
||||
end
|
||||
|
||||
context 'with valid params' do
|
||||
it 'returns error when usage limit is exceeded' do
|
||||
account.limits = { captain_responses: 2 }
|
||||
account.custom_attributes = { captain_responses_usage: 2 }
|
||||
account.save!
|
||||
|
||||
post "/api/v1/accounts/#{account.id}/captain/copilot_threads",
|
||||
params: valid_params,
|
||||
headers: agent.create_new_auth_token,
|
||||
as: :json
|
||||
|
||||
expect(response).to have_http_status(:success)
|
||||
|
||||
expect(CopilotMessage.last.message['content']).to eq(
|
||||
'You are out of Copilot credits. You can buy more credits from the billing section.'
|
||||
)
|
||||
end
|
||||
|
||||
it 'creates a new copilot thread with initial message' do
|
||||
account.limits = { captain_responses: 2 }
|
||||
account.custom_attributes = { captain_responses_usage: 0 }
|
||||
account.save!
|
||||
|
||||
expect do
|
||||
post "/api/v1/accounts/#{account.id}/captain/copilot_threads",
|
||||
params: valid_params,
|
||||
@@ -103,8 +124,15 @@ RSpec.describe 'Api::V1::Accounts::Captain::CopilotThreads', type: :request do
|
||||
expect(thread.assistant_id).to eq(assistant.id)
|
||||
|
||||
message = thread.copilot_messages.last
|
||||
expect(message.message_type).to eq('user')
|
||||
expect(message.message).to eq({ 'content' => valid_params[:message] })
|
||||
|
||||
expect(Captain::Copilot::ResponseJob).to have_been_enqueued.with(
|
||||
assistant: assistant,
|
||||
conversation_id: valid_params[:conversation_id],
|
||||
user_id: agent.id,
|
||||
copilot_thread_id: thread.id,
|
||||
message: valid_params[:message]
|
||||
)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user