2024-06-27 03:27:40 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require "rails_helper"
|
|
|
|
|
|
|
|
describe "AI Tool Management", type: :system do
|
|
|
|
fab!(:admin)
|
2024-12-11 18:48:58 -05:00
|
|
|
let(:admin_header) { PageObjects::Components::AdminHeader.new }
|
2024-06-27 03:27:40 -04:00
|
|
|
|
|
|
|
before do
|
|
|
|
SiteSetting.ai_embeddings_enabled = true
|
|
|
|
sign_in(admin)
|
|
|
|
end
|
|
|
|
|
2024-10-08 17:17:45 -04:00
|
|
|
def ensure_can_run_test
|
2024-06-27 03:27:40 -04:00
|
|
|
find(".ai-tool-editor__test-button").click
|
|
|
|
|
|
|
|
modal = PageObjects::Modals::AiToolTest.new
|
|
|
|
modal.base_currency = "USD"
|
|
|
|
modal.target_currency = "EUR"
|
|
|
|
modal.amount = "100"
|
|
|
|
|
|
|
|
stub_request(:get, %r{https://open\.er-api\.com/v6/latest/USD}).to_return(
|
|
|
|
status: 200,
|
|
|
|
body: '{"rates": {"EUR": 0.85}}',
|
|
|
|
headers: {
|
|
|
|
"Content-Type" => "application/json",
|
|
|
|
},
|
|
|
|
)
|
|
|
|
modal.run_test
|
|
|
|
|
|
|
|
expect(modal).to have_content("exchange_rate")
|
|
|
|
expect(modal).to have_content("0.85")
|
|
|
|
|
|
|
|
modal.close
|
2024-10-08 17:17:45 -04:00
|
|
|
end
|
2024-06-27 03:27:40 -04:00
|
|
|
|
2024-10-08 17:17:45 -04:00
|
|
|
it "allows admin to create a new AI tool from preset" do
|
|
|
|
visit "/admin/plugins/discourse-ai/ai-tools"
|
|
|
|
|
2024-12-11 18:48:58 -05:00
|
|
|
expect(admin_header).to be_visible
|
2024-10-08 17:17:45 -04:00
|
|
|
expect(page).to have_content("Tools")
|
|
|
|
|
|
|
|
find(".ai-tool-list-editor__new-button").click
|
2024-12-11 18:48:58 -05:00
|
|
|
expect(admin_header).to be_hidden
|
2024-10-08 17:17:45 -04:00
|
|
|
|
|
|
|
select_kit = PageObjects::Components::SelectKit.new(".ai-tool-editor__presets")
|
|
|
|
select_kit.expand
|
|
|
|
select_kit.select_row_by_value("exchange_rate")
|
|
|
|
|
|
|
|
find(".ai-tool-editor__next").click
|
|
|
|
|
|
|
|
expect(page.first(".parameter-row__required-toggle").checked?).to eq(true)
|
|
|
|
expect(page.first(".parameter-row__enum-toggle").checked?).to eq(false)
|
|
|
|
|
2024-10-25 01:01:25 -04:00
|
|
|
# not allowed to test yet
|
|
|
|
expect(page).not_to have_button(".ai-tool-editor__test-button")
|
2024-10-08 17:17:45 -04:00
|
|
|
|
|
|
|
expect(page).not_to have_button(".ai-tool-editor__delete")
|
2024-06-27 03:27:40 -04:00
|
|
|
find(".ai-tool-editor__save").click
|
|
|
|
|
|
|
|
expect(page).to have_content("Tool saved")
|
|
|
|
|
2024-08-29 02:05:38 -04:00
|
|
|
last_tool = AiTool.order("id desc").limit(1).first
|
2024-12-11 18:48:58 -05:00
|
|
|
visit "/admin/plugins/discourse-ai/ai-tools/#{last_tool.id}/edit"
|
2024-08-29 02:05:38 -04:00
|
|
|
|
2024-10-08 17:17:45 -04:00
|
|
|
ensure_can_run_test
|
|
|
|
|
2024-08-29 02:05:38 -04:00
|
|
|
expect(page.first(".parameter-row__required-toggle").checked?).to eq(true)
|
|
|
|
expect(page.first(".parameter-row__enum-toggle").checked?).to eq(false)
|
|
|
|
|
2024-06-27 03:27:40 -04:00
|
|
|
visit "/admin/plugins/discourse-ai/ai-personas/new"
|
|
|
|
|
|
|
|
tool_id = AiTool.order("id desc").limit(1).pluck(:id).first
|
|
|
|
tool_selector = PageObjects::Components::SelectKit.new(".ai-persona-editor__tools")
|
|
|
|
tool_selector.expand
|
|
|
|
|
|
|
|
tool_selector.select_row_by_value("custom-#{tool_id}")
|
|
|
|
expect(tool_selector).to have_selected_value("custom-#{tool_id}")
|
|
|
|
end
|
|
|
|
end
|