From 7aed068bb7ee27ee8e1dc9f1c41e4410af8cb589 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Bellet Date: Thu, 20 Jul 2023 10:13:11 +0200 Subject: [PATCH 1/4] Enterprises.visible attribute is set to `only_through_links` by default + update enterprise_factory.rb to create "public" enterprise through specs via its factory --- ...0080504_change_defaultvalue_for_visible_enterprise.rb | 9 +++++++++ db/schema.rb | 4 ++-- spec/controllers/admin/enterprises_controller_spec.rb | 9 +++++++++ spec/factories/enterprise_factory.rb | 1 + spec/system/admin/enterprises_spec.rb | 3 +++ 5 files changed, 24 insertions(+), 2 deletions(-) create mode 100644 db/migrate/20230720080504_change_defaultvalue_for_visible_enterprise.rb diff --git a/db/migrate/20230720080504_change_defaultvalue_for_visible_enterprise.rb b/db/migrate/20230720080504_change_defaultvalue_for_visible_enterprise.rb new file mode 100644 index 00000000000..786ec0b1f96 --- /dev/null +++ b/db/migrate/20230720080504_change_defaultvalue_for_visible_enterprise.rb @@ -0,0 +1,9 @@ +class ChangeDefaultvalueForVisibleEnterprise < ActiveRecord::Migration[7.0] + def up + change_column :enterprises, :visible, :string, default: "only_through_links" + end + + def down + change_column :enterprises, :visible, :string, default: "public" + end +end diff --git a/db/schema.rb b/db/schema.rb index 90a51e7208c..b5700a8ee98 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema[7.0].define(version: 2023_07_06_033212) do +ActiveRecord::Schema[7.0].define(version: 2023_07_20_080504) do # These are extensions that must be enabled in order to support this database enable_extension "pg_stat_statements" enable_extension "plpgsql" @@ -233,7 +233,7 @@ t.boolean "enable_subscriptions", default: false, null: false t.integer "business_address_id" t.boolean "show_customer_names_to_suppliers", default: false, null: false - t.string "visible", limit: 255, default: "public", null: false + t.string "visible", default: "only_through_links", null: false t.string "whatsapp_phone", limit: 255 t.boolean "hide_ofn_navigation", default: false, null: false t.text "white_label_logo_link" diff --git a/spec/controllers/admin/enterprises_controller_spec.rb b/spec/controllers/admin/enterprises_controller_spec.rb index 089d5c6ef16..4ac06280b90 100644 --- a/spec/controllers/admin/enterprises_controller_spec.rb +++ b/spec/controllers/admin/enterprises_controller_spec.rb @@ -47,6 +47,15 @@ expect(distributor_manager.enterprise_roles.where(enterprise_id: enterprise).first).to be end + it "set the `visible` attribute to `hidden`" do + allow(controller).to receive_messages spree_current_user: distributor_manager + enterprise_params[:enterprise][:owner_id] = distributor_manager + + spree_put :create, enterprise_params + enterprise = Enterprise.find_by name: 'zzz' + expect(enterprise.visible).to eq 'only_through_links' + end + context "when I already own a hub" do before { distributor } diff --git a/spec/factories/enterprise_factory.rb b/spec/factories/enterprise_factory.rb index d8259ecd15f..762d80c667c 100644 --- a/spec/factories/enterprise_factory.rb +++ b/spec/factories/enterprise_factory.rb @@ -14,6 +14,7 @@ description { 'enterprise' } long_description { '

Hello, world!

This is a paragraph.

' } address + visible { 'public' } after(:create) do |enterprise, proxy| proxy.users.each do |user| diff --git a/spec/system/admin/enterprises_spec.rb b/spec/system/admin/enterprises_spec.rb index 4ea82073e37..339898e673c 100644 --- a/spec/system/admin/enterprises_spec.rb +++ b/spec/system/admin/enterprises_spec.rb @@ -63,6 +63,9 @@ click_button 'Create' expect(flash_message).to eq('Enterprise "Eaterprises" has been successfully created!') + + # `Visible in search` radio button should be set to `Hide all references` by default + expect(page).to have_checked_field "enterprise_visible_only_through_links" end it "editing an existing enterprise" do From 5a0d4d2a937896805b54fb1478063dc7d0b59116 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Bellet Date: Tue, 25 Jul 2023 10:52:14 +0200 Subject: [PATCH 2/4] Set visible to `only_through_links` on enterprise registration --- app/controllers/admin/enterprises_controller.rb | 2 +- spec/controllers/admin/enterprises_controller_spec.rb | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/app/controllers/admin/enterprises_controller.rb b/app/controllers/admin/enterprises_controller.rb index 25668879957..170530f1448 100644 --- a/app/controllers/admin/enterprises_controller.rb +++ b/app/controllers/admin/enterprises_controller.rb @@ -92,7 +92,7 @@ def register return render :welcome, layout: "spree/layouts/bare_admin" end - attributes = { sells: register_params[:sells], visible: true } + attributes = { sells: register_params[:sells], visible: "only_through_links" } if @enterprise.update(attributes) flash[:success] = I18n.t(:enterprise_register_success_notice, enterprise: @enterprise.name) diff --git a/spec/controllers/admin/enterprises_controller_spec.rb b/spec/controllers/admin/enterprises_controller_spec.rb index 4ac06280b90..f965bb63575 100644 --- a/spec/controllers/admin/enterprises_controller_spec.rb +++ b/spec/controllers/admin/enterprises_controller_spec.rb @@ -453,6 +453,11 @@ expect(flash[:error]).to eq "Please select a package" end end + + it "set visibility to 'only_through_links' by default" do + spree_post :register, id: enterprise, sells: 'none' + expect(enterprise.reload.visible).to eq 'only_through_links' + end end end From d22566aa50ec615a6efcbc643bb3ad22f47b5efa Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Bellet Date: Tue, 25 Jul 2023 10:52:30 +0200 Subject: [PATCH 3/4] Set visible to `only_through_links` on enterprise creation --- app/controllers/api/v0/enterprises_controller.rb | 2 +- spec/controllers/api/v0/enterprises_controller_spec.rb | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/app/controllers/api/v0/enterprises_controller.rb b/app/controllers/api/v0/enterprises_controller.rb index 5a924390018..c5085f63e83 100644 --- a/app/controllers/api/v0/enterprises_controller.rb +++ b/app/controllers/api/v0/enterprises_controller.rb @@ -74,7 +74,7 @@ def override_sells end def override_visible - enterprise_params[:visible] = false + enterprise_params[:visible] = "only_through_links" end def enterprise_params diff --git a/spec/controllers/api/v0/enterprises_controller_spec.rb b/spec/controllers/api/v0/enterprises_controller_spec.rb index 2eb0127eeb6..9caa1362125 100644 --- a/spec/controllers/api/v0/enterprises_controller_spec.rb +++ b/spec/controllers/api/v0/enterprises_controller_spec.rb @@ -37,6 +37,14 @@ expect(enterprise.sells).to eq('any') end + it "creates a visible=hidden enterprise" do + api_post :create, { enterprise: new_enterprise_params } + expect(response.status).to eq 201 + + enterprise = Enterprise.last + expect(enterprise.visible).to eq("only_through_links") + end + it "saves all user ids submitted" do manager1 = create(:user) manager2 = create(:user) From 04f83fbccee8fab7c368bb8d17d7359dcf35f0c4 Mon Sep 17 00:00:00 2001 From: filipefurtad0 Date: Mon, 24 Jul 2023 14:31:27 +0100 Subject: [PATCH 4/4] Finally, update system test for an end-to-end testing --- spec/system/consumer/registration_spec.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/spec/system/consumer/registration_spec.rb b/spec/system/consumer/registration_spec.rb index b7e919f170b..9e184e7cd34 100644 --- a/spec/system/consumer/registration_spec.rb +++ b/spec/system/consumer/registration_spec.rb @@ -155,6 +155,8 @@ page.find('.full_hub h3').click click_button "Select and Continue" expect(page).to have_content "Your profile live" + click_link "Manage My Awesome Enterprise" + expect(page).to have_checked_field "enterprise_visible_only_through_links" end context "when the user has no more remaining enterprises" do