0
0
Fork 0
mirror of https://github.com/discourse/discourse.git synced 2026-08-11 02:59:07 +08:00
discourse/plugins/discourse-subscriptions/spec/system/subscription_product_spec.rb
David Taylor b447f12556
DEV: Block external requests in system specs via Chrome DNS resolver (#40685)
Add a catch-all `MAP * ~NOTFOUND` to Chrome's --host-resolver-rules so
any non-excluded host fails to resolve, instead of system specs reaching
the real internet. Local/test hosts (the Capybara server, *.localhost,
MinIO) are excluded. Unlike Playwright request interception this leaves
the browser HTTP cache enabled.

Specs that need an external host opt in with `allow_network:
["example.com"]`, which runs them in a dedicated browser with those
hosts excluded from the block.
2026-06-17 12:29:57 +01:00

49 lines
1.5 KiB
Ruby
Vendored

# frozen_string_literal: true
describe "Subscription products", allow_network: ["js.stripe.com"] do
fab!(:admin)
fab!(:product) { Fabricate(:product, external_id: "prod_OiK") }
let(:dialog) { PageObjects::Components::Dialog.new }
let(:product_subscriptions_page) { PageObjects::Pages::AdminSubscriptionProduct.new }
before do
SiteSetting.discourse_subscriptions_enabled = true
SiteSetting.discourse_subscriptions_secret_key = "sk_test_51xuu"
SiteSetting.discourse_subscriptions_public_key = "pk_test_51xuu"
# # this needs to be stubbed or it will try to make a request to stripe
one_product = {
id: "prod_OiK",
active: true,
name: "Tomtom",
metadata: {
description: "Photos of tomtom",
repurchaseable: true,
},
}
::Stripe::Product.stubs(:list).returns({ data: [one_product] })
::Stripe::Product.stubs(:delete).returns({ id: "prod_OiK" })
::Stripe::Product.stubs(:retrieve).returns(one_product)
::Stripe::Price.stubs(:list).returns({ data: [] })
end
it "shows the login screen" do
visit("/s")
find("button.login-required.subscriptions").click
expect(page).to have_css("#login-form")
end
it "shows products on the products and allows deletion" do
sign_in(admin)
product_subscriptions_page.visit_products.has_product?("Tomtom")
product_subscriptions_page.click_trash_nth_row(1)
dialog.click_yes
product_subscriptions_page.has_number_of_products?(0)
end
end