Remove white_label feature toggle

White label is now activated for everyone.

+ add mock for `spec/controllers/spree/orders_controller_spec.rb`
This commit is contained in:
Jean-Baptiste Bellet
2023-05-09 15:05:37 +02:00
parent a1e4c45daa
commit aaa9bac4dd
6 changed files with 303 additions and 351 deletions

View File

@@ -5,8 +5,6 @@ module WhiteLabel
include EnterprisesHelper
def hide_ofn_navigation(distributor = current_distributor)
return false unless OpenFoodNetwork::FeatureToggle.enabled?(:white_label)
# if the distributor has the hide_ofn_navigation preference set to true
# then we should hide the OFN navigation
@hide_ofn_navigation = distributor.hide_ofn_navigation

View File

@@ -49,13 +49,8 @@ module Admin
{ name: 'tag_rules', icon_class: "icon-random", show: is_shop },
{ name: 'shop_preferences', icon_class: "icon-shopping-cart", show: is_shop },
{ name: 'users', icon_class: "icon-user", show: true },
] + [add_white_label_if_feature_activated].compact
end
def add_white_label_if_feature_activated
return nil unless OpenFoodNetwork::FeatureToggle.enabled?(:white_label)
{ name: 'white_label', icon_class: "icon-leaf", show: true }
{ name: 'white_label', icon_class: "icon-leaf", show: true },
]
end
end
end

View File

@@ -41,9 +41,6 @@ module OpenFoodNetwork
"vouchers" => <<~DESC,
Add voucher functionality. Voucher can be managed via Enterprise settings.
DESC
"white_label" => <<~DESC,
Customize shopfront (shop, cart, checkout) and emails without OFN branding.
DESC
}.freeze
def self.setup!

View File

@@ -90,12 +90,13 @@ describe Spree::OrdersController, type: :controller do
it "redirects to shop when order is empty" do
allow(controller).to receive(:current_distributor).and_return(distributor)
allow(distributor).to receive(:hide_ofn_navigation).and_return false
allow(controller).to receive(:current_order_cycle).and_return(order_cycle)
allow(controller).to receive(:current_order).and_return order
allow(order).to receive_message_chain(:line_items, :empty?).and_return true
allow(order).to receive(:insufficient_stock_lines).and_return []
allow(order).to receive(:line_item_variants).and_return []
allow(order).to receive(:distributor).and_return distributor
allow(distributor).to receive(:hide_ofn_navigation).and_return false
allow(order_cycle).to receive(:variants_distributed_by).and_return []
session[:access_token] = order.token

View File

@@ -607,80 +607,78 @@ describe '
end
context "white label settings" do
context "when the feature is enabled" do
before do
Flipper.enable(:white_label)
visit edit_admin_enterprise_path(distributor1)
before do
visit edit_admin_enterprise_path(distributor1)
within(".side_menu") do
click_link "White Label"
end
end
it "set the hide_ofn_navigation preference for the current shop" do
check "Hide OFN navigation"
click_button 'Update'
success_message = 'Enterprise "First Distributor" has been successfully updated!'
expect(flash_message).to eq success_message
expect(distributor1.reload.hide_ofn_navigation).to be true
visit edit_admin_enterprise_path(distributor1)
within(".side_menu") do
click_link "White Label"
end
uncheck "Hide OFN navigation"
click_button 'Update'
expect(flash_message).to eq success_message
expect(distributor1.reload.hide_ofn_navigation).to be false
within(".side_menu") do
click_link "White Label"
end
end
context "when the feature is disabled" do
before do
Flipper.disable(:white_label)
visit edit_admin_enterprise_path(distributor1)
it "set the hide_ofn_navigation preference for the current shop" do
check "Hide OFN navigation"
click_button 'Update'
success_message = 'Enterprise "First Distributor" has been successfully updated!'
expect(flash_message).to eq success_message
expect(distributor1.reload.hide_ofn_navigation).to be true
visit edit_admin_enterprise_path(distributor1)
within(".side_menu") do
click_link "White Label"
end
it "does not show the white label settings" do
expect(page).not_to have_link "White Label"
end
uncheck "Hide OFN navigation"
click_button 'Update'
expect(flash_message).to eq success_message
expect(distributor1.reload.hide_ofn_navigation).to be false
end
context "when the feature is enabled" do
it "set the hide_ofn_navigation preference for the current shop" do
expect(page).not_to have_content "LOGO USED IN SHOPFRONT"
check "Hide OFN navigation"
click_button 'Update'
expect(flash_message)
.to eq('Enterprise "First Distributor" has been successfully updated!')
expect(distributor1.reload.hide_ofn_navigation).to be true
visit edit_admin_enterprise_path(distributor1)
within(".side_menu") do
click_link "White Label"
end
expect(page).to have_content "LOGO USED IN SHOPFRONT"
uncheck "Hide OFN navigation"
click_button 'Update'
expect(flash_message)
.to eq('Enterprise "First Distributor" has been successfully updated!')
expect(distributor1.reload.hide_ofn_navigation).to be false
end
context "when white label is active via `hide_ofn_navigation`" do
before do
Flipper.enable(:white_label)
visit edit_admin_enterprise_path(distributor1)
within(".side_menu") do
click_link "White Label"
end
end
it "set the hide_ofn_navigation preference for the current shop" do
expect(page).not_to have_content "LOGO USED IN SHOPFRONT"
check "Hide OFN navigation"
click_button 'Update'
expect(flash_message)
.to eq('Enterprise "First Distributor" has been successfully updated!')
expect(distributor1.reload.hide_ofn_navigation).to be true
distributor1.update_attribute(:hide_ofn_navigation, true)
visit edit_admin_enterprise_path(distributor1)
within(".side_menu") do
click_link "White Label"
end
end
expect(page).to have_content "LOGO USED IN SHOPFRONT"
uncheck "Hide OFN navigation"
it "can updload the white label logo for the current shop" do
attach_file "enterprise_white_label_logo", white_logo_path
click_button 'Update'
expect(flash_message)
.to eq('Enterprise "First Distributor" has been successfully updated!')
expect(distributor1.reload.hide_ofn_navigation).to be false
expect(distributor1.reload.white_label_logo_blob.filename).to eq("logo-white.png")
end
context "when white label is active via `hide_ofn_navigation`" do
it "does not show the white label logo link field" do
expect(page).not_to have_field "white_label_logo_link"
end
context "when enterprise has a white label logo" do
before do
distributor1.update_attribute(:hide_ofn_navigation, true)
distributor1.update white_label_logo: white_logo_file
visit edit_admin_enterprise_path(distributor1)
within(".side_menu") do
@@ -688,47 +686,24 @@ describe '
end
end
it "can updload the white label logo for the current shop" do
attach_file "enterprise_white_label_logo", white_logo_path
it "can remove the white label logo for the current shop" do
expect(page).to have_selector("img[src*='logo-white.png']")
expect(distributor1.white_label_logo).to be_attached
click_button "Remove"
within ".reveal-modal" do
click_button "Confirm"
end
expect(flash_message).to match(/Logo removed/)
distributor1.reload
expect(distributor1.white_label_logo).to_not be_attached
end
it "can edit the text field white_label_logo_link" do
fill_in "enterprise_white_label_logo_link", with: "https://www.openfoodnetwork.org"
click_button 'Update'
expect(flash_message)
.to eq('Enterprise "First Distributor" has been successfully updated!')
expect(distributor1.reload.white_label_logo_blob.filename).to eq("logo-white.png")
end
it "does not show the white label logo link field" do
expect(page).not_to have_field "white_label_logo_link"
end
context "when enterprise has a white label logo" do
before do
distributor1.update white_label_logo: white_logo_file
visit edit_admin_enterprise_path(distributor1)
within(".side_menu") do
click_link "White Label"
end
end
it "can remove the white label logo for the current shop" do
expect(page).to have_selector("img[src*='logo-white.png']")
expect(distributor1.white_label_logo).to be_attached
click_button "Remove"
within ".reveal-modal" do
click_button "Confirm"
end
expect(flash_message).to match(/Logo removed/)
distributor1.reload
expect(distributor1.white_label_logo).to_not be_attached
end
it "can edit the text field white_label_logo_link" do
fill_in "enterprise_white_label_logo_link", with: "https://www.openfoodnetwork.org"
click_button 'Update'
expect(flash_message)
.to eq('Enterprise "First Distributor" has been successfully updated!')
expect(distributor1.reload.white_label_logo_link).to eq("https://www.openfoodnetwork.org")
end
expect(distributor1.reload.white_label_logo_link).to eq("https://www.openfoodnetwork.org")
end
end
end

View File

@@ -46,294 +46,280 @@ describe 'White label setting' do
end
end
context "when the white label feature is activated" do
before do
Flipper.enable(:white_label)
end
context "manage the hide_ofn_navigation preference" do
context "when the preference is set to true" do
before do
distributor.update_attribute(:hide_ofn_navigation, true)
end
context "manage the hide_ofn_navigation preference" do
context "when the preference is set to true" do
before do
distributor.update_attribute(:hide_ofn_navigation, true)
shared_examples "hides the OFN navigation when needed only" do
it "hides the OFN navigation when visiting the shop" do
visit main_app.enterprise_shop_path(distributor)
expect(page).to have_no_selector ofn_navigation
end
shared_examples "hides the OFN navigation when needed only" do
it "hides the OFN navigation when visiting the shop" do
visit main_app.enterprise_shop_path(distributor)
it "does not hide the OFN navigation when visiting root path" do
visit main_app.root_path
expect(page).to have_selector ofn_navigation
end
end
context "without order or current distributor" do
it_behaves_like "hides the OFN navigation when needed only"
end
context "when the user has an order ready to checkout" do
before do
order.update_attribute(:state, 'cart')
order.line_items << create(:line_item, variant: product.variants.first)
set_order(order)
end
shared_examples "hides the OFN navigation when needed only for the checkout" do
it_behaves_like "hides the OFN navigation when needed only"
it "hides the OFN navigation when visiting cart path" do
visit main_app.cart_path
expect(page).to have_no_selector ofn_navigation
end
it "does not hide the OFN navigation when visiting root path" do
visit main_app.root_path
expect(page).to have_selector ofn_navigation
it "hides the OFN navigation when visiting checkout path" do
visit checkout_path
expect(page).to have_content "Checkout now"
expect(page).to have_content "Order ready for "
expect(page).to have_no_selector ofn_navigation
end
end
context "without order or current distributor" do
it_behaves_like "hides the OFN navigation when needed only"
context "when the split checkout is disabled" do
it_behaves_like "hides the OFN navigation when needed only for the checkout"
end
context "when the user has an order ready to checkout" do
context "when the split checkout is enabled" do
before do
order.update_attribute(:state, 'cart')
order.line_items << create(:line_item, variant: product.variants.first)
set_order(order)
Flipper.enable(:split_checkout)
end
shared_examples "hides the OFN navigation when needed only for the checkout" do
it_behaves_like "hides the OFN navigation when needed only"
it_behaves_like "hides the OFN navigation when needed only for the checkout"
end
end
it "hides the OFN navigation when visiting cart path" do
visit main_app.cart_path
expect(page).to have_no_selector ofn_navigation
end
context "when the user has a complete order" do
before do
set_order(complete_order)
end
it "hides the OFN navigation when visiting checkout path" do
visit checkout_path
expect(page).to have_content "Checkout now"
expect(page).to have_content "Order ready for "
expect(page).to have_no_selector ofn_navigation
end
end
context "when the split checkout is disabled" do
it_behaves_like "hides the OFN navigation when needed only for the checkout"
end
context "when the split checkout is enabled" do
before do
Flipper.enable(:split_checkout)
end
it_behaves_like "hides the OFN navigation when needed only for the checkout"
shared_examples "hides the OFN navigation when needed only for the order confirmation" do
it "hides" do
visit order_path(complete_order, order_token: complete_order.token)
expect(page).to have_no_selector ofn_navigation
end
end
context "when the user has a complete order" do
before do
set_order(complete_order)
end
shared_examples "hides the OFN navigation when needed only for the order confirmation" do
it "hides" do
visit order_path(complete_order, order_token: complete_order.token)
expect(page).to have_no_selector ofn_navigation
end
end
context "when the current distributor is the distributor of the order" do
before do
allow_any_instance_of(EnterprisesHelper).to receive(:current_distributor).
and_return(distributor)
end
it_behaves_like "hides the OFN navigation when needed only for the order confirmation"
end
context "when the user has a current distributor that is not the distributor's order" do
let!(:another_distributor) { create(:distributor_enterprise) }
before do
another_distributor.update_attribute(:hide_ofn_navigation, false)
allow_any_instance_of(EnterprisesHelper).to receive(:current_distributor).
and_return(another_distributor)
end
it_behaves_like "hides the OFN navigation when needed only for the order confirmation"
end
end
context "when the user has a current distributor" do
context "when the current distributor is the distributor of the order" do
before do
allow_any_instance_of(EnterprisesHelper).to receive(:current_distributor).
and_return(distributor)
end
it_behaves_like "hides the OFN navigation when needed only"
it_behaves_like "hides the OFN navigation when needed only for the order confirmation"
end
context "when the user has a current distributor that is not the distributor's order" do
let!(:another_distributor) { create(:distributor_enterprise) }
before do
another_distributor.update_attribute(:hide_ofn_navigation, false)
allow_any_instance_of(EnterprisesHelper).to receive(:current_distributor).
and_return(another_distributor)
end
it_behaves_like "hides the OFN navigation when needed only for the order confirmation"
end
end
context "when the preference is set to false" do
context "when the user has a current distributor" do
before do
distributor.update_attribute(:hide_ofn_navigation, false)
set_order(order)
allow_any_instance_of(EnterprisesHelper).to receive(:current_distributor).
and_return(distributor)
end
it_behaves_like "does not hide the OFN navigation"
it_behaves_like "hides the OFN navigation when needed only"
end
end
context "manage the white_label_logo preference" do
context "when the distributor has no logo" do
before do
distributor.update_attribute(:hide_ofn_navigation, true)
end
shared_examples "shows/hide the right logos" do
it "shows the OFN logo on shop page" do
expect(page).to have_selector "img[src*='/default_images/ofn-logo.png']"
end
end
context "on shop page" do
before do
visit main_app.enterprise_shop_path(distributor)
end
it_behaves_like "shows/hide the right logos"
end
context "on cart page" do
before do
order.update_attribute(:state, 'cart')
order.line_items << create(:line_item, variant: product.variants.first)
set_order(order)
visit main_app.cart_path
end
it_behaves_like "shows/hide the right logos"
end
context "on checkout page" do
before do
order.update_attribute(:state, 'cart')
order.line_items << create(:line_item, variant: product.variants.first)
set_order(order)
visit checkout_path
end
it_behaves_like "shows/hide the right logos"
end
context "on order confirmation page" do
before do
visit order_path(complete_order, order_token: complete_order.token)
end
it_behaves_like "shows/hide the right logos"
end
context "when the preference is set to false" do
before do
distributor.update_attribute(:hide_ofn_navigation, false)
set_order(order)
allow_any_instance_of(EnterprisesHelper).to receive(:current_distributor).
and_return(distributor)
end
context "when the distributor has a logo" do
before do
distributor.update_attribute(:hide_ofn_navigation, true)
distributor.update white_label_logo: white_logo_file
end
shared_examples "shows/hide the right logos" do
it "shows the white label logo on shop page" do
expect(page).to have_selector "img[src*='/logo-white.png']"
end
it "does not show the OFN logo on shop page" do
expect(page).not_to have_selector "img[src*='/default_images/ofn-logo.png']"
end
it "links the logo to the default URL" do
within ".nav-logo .ofn-logo" do
expect(page).to have_selector "a[href='/']"
end
end
end
context "on shop page" do
before do
visit main_app.enterprise_shop_path(distributor)
end
it_behaves_like "shows/hide the right logos"
end
context "on cart page" do
before do
order.update_attribute(:state, 'cart')
order.line_items << create(:line_item, variant: product.variants.first)
set_order(order)
visit main_app.cart_path
end
it_behaves_like "shows/hide the right logos"
end
context "on checkout page" do
before do
order.update_attribute(:state, 'cart')
order.line_items << create(:line_item, variant: product.variants.first)
set_order(order)
visit checkout_path
end
it_behaves_like "shows/hide the right logos"
end
context "on order confirmation page" do
before do
visit order_path(complete_order, order_token: complete_order.token)
end
it_behaves_like "shows/hide the right logos"
end
context "and a link on this logo" do
before do
distributor.update_attribute(:white_label_logo_link, "https://www.example.com")
end
shared_examples "shows the right link on the logo" do
it "shows the white label logo link" do
within ".nav-logo .ofn-logo" do
expect(page).to_not have_selector "a[href='/']"
expect(page).to have_selector "a[href*='https://www.example.com']"
end
end
end
context "on shop page" do
before do
visit main_app.enterprise_shop_path(distributor)
end
it_behaves_like "shows the right link on the logo"
end
context "on cart page" do
before do
order.update_attribute(:state, 'cart')
order.line_items << create(:line_item, variant: product.variants.first)
set_order(order)
visit main_app.cart_path
end
it_behaves_like "shows the right link on the logo"
end
context "on checkout page" do
before do
order.update_attribute(:state, 'cart')
order.line_items << create(:line_item, variant: product.variants.first)
set_order(order)
visit checkout_path
end
it_behaves_like "shows the right link on the logo"
end
context "on order confirmation page" do
before do
visit order_path(complete_order, order_token: complete_order.token)
end
it_behaves_like "shows the right link on the logo"
end
end
end
it_behaves_like "does not hide the OFN navigation"
end
end
context "when the white label feature is deactivated" do
before do
Flipper.disable(:white_label)
context "manage the white_label_logo preference" do
context "when the distributor has no logo" do
before do
distributor.update_attribute(:hide_ofn_navigation, true)
end
shared_examples "shows/hide the right logos" do
it "shows the OFN logo on shop page" do
expect(page).to have_selector "img[src*='/default_images/ofn-logo.png']"
end
end
context "on shop page" do
before do
visit main_app.enterprise_shop_path(distributor)
end
it_behaves_like "shows/hide the right logos"
end
context "on cart page" do
before do
order.update_attribute(:state, 'cart')
order.line_items << create(:line_item, variant: product.variants.first)
set_order(order)
visit main_app.cart_path
end
it_behaves_like "shows/hide the right logos"
end
context "on checkout page" do
before do
order.update_attribute(:state, 'cart')
order.line_items << create(:line_item, variant: product.variants.first)
set_order(order)
visit checkout_path
end
it_behaves_like "shows/hide the right logos"
end
context "on order confirmation page" do
before do
visit order_path(complete_order, order_token: complete_order.token)
end
it_behaves_like "shows/hide the right logos"
end
end
it_behaves_like "does not hide the OFN navigation"
context "when the distributor has a logo" do
before do
distributor.update_attribute(:hide_ofn_navigation, true)
distributor.update white_label_logo: white_logo_file
end
shared_examples "shows/hide the right logos" do
it "shows the white label logo on shop page" do
expect(page).to have_selector "img[src*='/logo-white.png']"
end
it "does not show the OFN logo on shop page" do
expect(page).not_to have_selector "img[src*='/default_images/ofn-logo.png']"
end
it "links the logo to the default URL" do
within ".nav-logo .ofn-logo" do
expect(page).to have_selector "a[href='/']"
end
end
end
context "on shop page" do
before do
visit main_app.enterprise_shop_path(distributor)
end
it_behaves_like "shows/hide the right logos"
end
context "on cart page" do
before do
order.update_attribute(:state, 'cart')
order.line_items << create(:line_item, variant: product.variants.first)
set_order(order)
visit main_app.cart_path
end
it_behaves_like "shows/hide the right logos"
end
context "on checkout page" do
before do
order.update_attribute(:state, 'cart')
order.line_items << create(:line_item, variant: product.variants.first)
set_order(order)
visit checkout_path
end
it_behaves_like "shows/hide the right logos"
end
context "on order confirmation page" do
before do
visit order_path(complete_order, order_token: complete_order.token)
end
it_behaves_like "shows/hide the right logos"
end
context "and a link on this logo" do
before do
distributor.update_attribute(:white_label_logo_link, "https://www.example.com")
end
shared_examples "shows the right link on the logo" do
it "shows the white label logo link" do
within ".nav-logo .ofn-logo" do
expect(page).to_not have_selector "a[href='/']"
expect(page).to have_selector "a[href*='https://www.example.com']"
end
end
end
context "on shop page" do
before do
visit main_app.enterprise_shop_path(distributor)
end
it_behaves_like "shows the right link on the logo"
end
context "on cart page" do
before do
order.update_attribute(:state, 'cart')
order.line_items << create(:line_item, variant: product.variants.first)
set_order(order)
visit main_app.cart_path
end
it_behaves_like "shows the right link on the logo"
end
context "on checkout page" do
before do
order.update_attribute(:state, 'cart')
order.line_items << create(:line_item, variant: product.variants.first)
set_order(order)
visit checkout_path
end
it_behaves_like "shows the right link on the logo"
end
context "on order confirmation page" do
before do
visit order_path(complete_order, order_token: complete_order.token)
end
it_behaves_like "shows the right link on the logo"
end
end
end
end
end