Files
openfoodnetwork/spec/system/consumer/account/developer_settings_spec.rb
David Cook 00a823b2fc 6. Add webhook endpoints to user developer settings screen
Allowing creation and deleting via the user association.
It probably won't be much effort to allow editing and multiple records, but I cut it down to the minimum needed to avoid any further delays.

I couldn't find a way to test a failure in the destroy method, but decided to keep the condition because I thought it was worth having.
2023-03-07 15:38:50 +11:00

68 lines
2.0 KiB
Ruby

# frozen_string_literal: true
require "system_helper"
describe "Developer Settings" do
include AuthenticationHelper
include WebHelper
describe "as a logged in user" do
before do
login_as user
visit "/account"
end
context "when show_api_key_view is true" do
let(:spree_api_key) { SecureRandom.hex(24) }
let(:user) { create(:user, show_api_key_view: true, spree_api_key: spree_api_key) }
it "shows the developer settings tab" do
find("a", text: "DEVELOPER SETTINGS").click
expect(page).to have_content "Developer Settings"
end
context "when the user has an api key" do
before do
find("a", text: "DEVELOPER SETTINGS").click
end
it "shows the api key" do
expect(page).to have_input "api_key", with: spree_api_key
end
it "lets the user regenerate the api key" do
click_button "Regenerate Key"
expect(page).to have_content "Key generated"
expect(page).to have_input "api_key", with: user.reload.spree_api_key
end
describe "Webhook Endpoints" do
it "creates a new webhook endpoint and deletes it" do
within "#webhook_endpoints" do
fill_in "webhook_endpoint_url", with: "https://url"
click_button I18n.t(:create)
expect(page.document).to have_content I18n.t('webhook_endpoints.create.success')
expect(page).to have_content "https://url"
click_button I18n.t(:delete)
expect(page.document).to have_content I18n.t('webhook_endpoints.destroy.success')
expect(page).to_not have_content "https://url"
end
end
end
end
end
context "when show_api_key_view is false" do
let(:user) { create(:user, show_api_key_view: false) }
it "does not show the developer settings tab" do
within("#account-tabs") do
expect(page).to_not have_selector("a", text: "DEVELOPER SETTINGS")
end
end
end
end
end