Merge pull request #11821 from mkllnk/feature-toggled-specs

Feature toggled specs
This commit is contained in:
Maikel
2023-11-22 14:18:13 +11:00
committed by GitHub
16 changed files with 27 additions and 55 deletions

View File

@@ -91,6 +91,16 @@ RSpec.configure do |config|
expectations.syntax = :expect
end
config.before(:each, :feature) do |example|
feature = example.metadata[:feature].to_s
unless OpenFoodNetwork::FeatureToggle::CURRENT_FEATURES.key?(feature)
raise "Unkown feature: #{feature}"
end
Flipper.enable(feature)
end
# Enable caching in any specs tagged with `caching: true`.
config.around(:each, :caching) do |example|
caching = ActionController::Base.perform_caching

View File

@@ -18,11 +18,7 @@ describe BulkInvoiceJob do
end
end
context "when invoices are enabled" do
before do
Flipper.enable(:invoices)
end
context "when invoices are enabled", feature: :invoices do
describe "#perform" do
let!(:order1) { create(:shipped_order) }
let!(:order2) { create(:order_with_line_items) }

View File

@@ -105,7 +105,7 @@ describe "Reporting::Reports::SalesTax::SalesTaxTotalsByOrder" do
expect(tax_total).to eq(0.2 + 2)
end
context "with a voucher" do
context "with a voucher", feature: :vouchers do
let(:voucher) do
create(:voucher_flat_rate, code: 'some_code', enterprise: order.distributor, amount: 10)
end
@@ -133,7 +133,7 @@ describe "Reporting::Reports::SalesTax::SalesTaxTotalsByOrder" do
expect(total).to eq(113.3 - 3.3)
end
context "with a voucher" do
context "with a voucher", feature: :vouchers do
let(:voucher) do
create(:voucher_flat_rate, code: 'some_code', enterprise: order.distributor, amount: 10)
end
@@ -214,7 +214,7 @@ describe "Reporting::Reports::SalesTax::SalesTaxTotalsByOrder" do
create(:voucher_flat_rate, code: 'some_code', enterprise: order.distributor, amount: 10)
end
it "adjusts total_excl_tax and tax with voucher tax" do
it "adjusts total_excl_tax and tax with voucher tax", feature: :vouchers do
add_voucher(order, voucher)
mock_voucher_adjustment_service(excluded_tax: -0.29)
@@ -269,8 +269,6 @@ describe "Reporting::Reports::SalesTax::SalesTaxTotalsByOrder" do
end
def add_voucher(order, voucher)
Flipper.enable :vouchers
# Add voucher to the order
voucher.create_adjustment(voucher.code, order)
VoucherAdjustmentsService.new(order).update

View File

@@ -248,10 +248,7 @@ describe Spree::OrderMailer do
end
end
context "When invoices feature is enabled" do
before do
Flipper.enable(:invoices)
end
context "When invoices feature is enabled", feature: :invoices do
it "should call the invoice renderer with invoice's presenter as argument" do
expect(generator).to receive(:generate_or_update_latest_invoice)
expect(order).to receive(:invoices).and_return([invoice])

View File

@@ -2,17 +2,12 @@
require "reflex_helper"
describe ProductsReflex, type: :reflex do
describe ProductsReflex, type: :reflex, feature: :admin_style_v3 do
let(:current_user) { create(:admin_user) } # todo: set up an enterprise user to test permissions
let(:context) {
{ url: admin_products_url, connection: { current_user: } }
}
before do
# activate feature toggle admin_style_v3 to use new admin interface
Flipper.enable(:admin_style_v3)
end
describe '#fetch' do
subject{ build_reflex(method_name: :fetch, **context) }

View File

@@ -2,13 +2,11 @@
require "spec_helper"
describe "/admin/enterprises/:enterprise_id/vouchers", type: :request do
describe "/admin/enterprises/:enterprise_id/vouchers", type: :request, feature: :vouchers do
let(:enterprise) { create(:supplier_enterprise, name: "Feedme") }
let(:enterprise_user) { create(:user, enterprise_limit: 1) }
before do
Flipper.enable(:vouchers)
enterprise_user.enterprise_roles.build(enterprise:).save
sign_in enterprise_user
end

View File

@@ -2,7 +2,7 @@
require "swagger_helper"
describe "Customers", type: :request, swagger_doc: "v1.yaml" do
describe "Customers", type: :request, swagger_doc: "v1.yaml", feature: :api_v1 do
let!(:enterprise1) { create(:enterprise, name: "The Farm") }
let!(:enterprise2) { create(:enterprise) }
let!(:enterprise3) { create(:enterprise) }
@@ -21,7 +21,6 @@ describe "Customers", type: :request, swagger_doc: "v1.yaml" do
let!(:customer3) { create(:customer, enterprise: enterprise2, created_manually: true,) }
before do
Flipper.enable(:api_v1)
login_as enterprise1.owner
end

View File

@@ -215,7 +215,7 @@ describe OrderAvailableShippingMethods do
end
end
context "when certain shipping categories are required" do
context "when certain shipping categories are required", feature: :match_shipping_categories do
subject { OrderAvailableShippingMethods.new(order) }
let(:order) { build(:order, distributor:, order_cycle: oc) }
let(:oc) { create(:order_cycle) }
@@ -232,8 +232,6 @@ describe OrderAvailableShippingMethods do
before {
standard_shipping
cooled_shipping
Flipper.enable(:match_shipping_categories)
}
it "provides all shipping methods for an empty order" do

View File

@@ -136,9 +136,6 @@ describe '
end
context "when invoice feature is not enabled" do
before do
Flipper.disable(:invoices)
end
it_behaves_like "contains right Payment Description at Checkout information"
it_behaves_like "Check display on each invoice: legacy and alternative", false
it_behaves_like "Check display on each invoice: legacy and alternative", true
@@ -442,10 +439,7 @@ describe '
end
end
end
context "when invoice feature is enabled" do
before do
Flipper.enable(:invoices)
end
context "when invoice feature is enabled", feature: :invoices do
it_behaves_like "contains right Payment Description at Checkout information"
it_behaves_like "Check display on each invoice: legacy and alternative", false
it_behaves_like "Check display on each invoice: legacy and alternative", true

View File

@@ -1042,9 +1042,8 @@ describe '
end
end
describe "Legal Invoices" do
describe "Legal Invoices", feature: :invoices do
before do
Flipper.enable(:invoices)
login_as user
end

View File

@@ -5,7 +5,7 @@ require 'system_helper'
describe '
As an administrator
I want to manage invoices for an order
' do
', feature: :invoices do
include WebHelper
include AuthenticationHelper
@@ -28,7 +28,6 @@ describe '
let(:customer) { order.customer }
before do
Flipper.enable(:invoices)
order.finalize!
login_as_admin
visit spree.edit_admin_order_path(order)

View File

@@ -2,14 +2,12 @@
require "system_helper"
describe 'As an admin, I can see the new product page' do
describe 'As an admin, I can see the new product page', feature: :admin_style_v3 do
include WebHelper
include AuthenticationHelper
include FileHelper
before do
# activate feature toggle admin_style_v3 to use new admin interface
Flipper.enable(:admin_style_v3)
login_as_admin
end

View File

@@ -31,11 +31,7 @@ describe '
end
end
describe "Background processing" do
before do
Flipper.enable(:background_reports)
end
describe "Background processing", feature: :background_reports do
it "can run the customers report" do
login_as_admin
visit admin_report_path(report_type: :customers)

View File

@@ -116,9 +116,7 @@ describe "As a consumer, I want to checkout my order" do
end
end
describe "vouchers" do
before { Flipper.enable :vouchers }
describe "vouchers", feature: :vouchers do
context "with no voucher available" do
before do
visit checkout_step_path(:payment)

View File

@@ -108,9 +108,7 @@ describe "As a consumer, I want to see adjustment breakdown" do
assert_db_tax_incl
end
context "when using a voucher" do
before { Flipper.enable :vouchers }
context "when using a voucher", feature: :vouchers do
let!(:voucher) do
create(:voucher_flat_rate, code: 'some_code', enterprise: distributor, amount: 10)
end

View File

@@ -2,7 +2,7 @@
require "system_helper"
describe "As a consumer, I want to see adjustment breakdown" do
describe "As a consumer, I want to see adjustment breakdown", feature: :vouchers do
include ShopWorkflow
include SplitCheckoutHelper
include CheckoutRequestsHelper
@@ -63,7 +63,6 @@ describe "As a consumer, I want to see adjustment breakdown" do
before do
# assures tax is charged in dependence of shipping address
Spree::Config.set(tax_using_ship_address: true)
Flipper.enable :vouchers
end
describe "a not-included tax" do