From e0be25f927d6897933e8addd82fbceb4e9f84cf8 Mon Sep 17 00:00:00 2001 From: filipefurtad0 Date: Sun, 9 Jul 2023 21:45:22 +0100 Subject: [PATCH 1/3] Adds spec for profile change via admin path --- spec/system/admin/enterprises_spec.rb | 166 ++++++++++++++++++++++++++ 1 file changed, 166 insertions(+) diff --git a/spec/system/admin/enterprises_spec.rb b/spec/system/admin/enterprises_spec.rb index 25723c7a61..383c9f5c61 100644 --- a/spec/system/admin/enterprises_spec.rb +++ b/spec/system/admin/enterprises_spec.rb @@ -822,4 +822,170 @@ describe ' end end end + + context "changing package" do + let!(:owner) { create(:user) } + let!(:enterprise) { create(:distributor_enterprise, owner: owner, is_primary_producer: true) } + before do + login_as owner + end + + context "via admin path, for a producer" do + before do + visit spree.admin_dashboard_path + end + + it "changes user role" do + click_button "Change Package" + + # checks options for producer profile + expect(page).to have_content "PRODUCER PROFILE" + expect(page).to have_content "PRODUCER SHOP" + expect(page).to have_content "PRODUCER HUB" + expect(page).not_to have_content "PROFILE ONLY" + expect(page).not_to have_content "HUB SHOP" + + # Producer hub option is selected + page.find('a', class: 'selected', text: "PRODUCER HUB") + expect(enterprise.is_primary_producer).to eq true + expect(enterprise.reload.sells).to eq('any') + + # Displays the correct dashboard sections + assert_hub_menu + assert_hub_content + + # Changes to producer shop + page.find('a', text: "PRODUCER SHOP").click + click_button "Change now" + expect(page).to have_content update_message + + # Checks changes are persistent + click_button "Change Package" + + page.find('a', class: 'selected', text: "PRODUCER SHOP") + expect(enterprise.is_primary_producer).to eq true + expect(enterprise.reload.sells).to eq('own') + + # Displays the correct dashboard sections + assert_hub_menu + assert_hub_content + + # Changes to producer profile + page.find('a', text: "PRODUCER PROFILE").click + click_button "Change now" + expect(page).to have_content update_message + + # Checks changes are persistent + click_button "Change Package" + + page.find('a', class: 'selected', text: "PRODUCER PROFILE") + expect(enterprise.is_primary_producer).to eq true + expect(enterprise.reload.sells).to eq('none') + + # Displays the correct dashboard sections + assert_supplier_menu + assert_supplier_content + end + end + + context "via admin path, for a non-producer" do + before do + enterprise.update!(is_primary_producer: false) + visit spree.admin_dashboard_path + end + + it "changes user role" do + click_button "Change Package" + + # checks options for non-producer profile + expect(page).not_to have_content "PRODUCER PROFILE" + expect(page).not_to have_content "PRODUCER SHOP" + expect(page).not_to have_content "PRODUCER HUB" + expect(page).to have_content "PROFILE ONLY" + expect(page).to have_content "HUB SHOP" + + # Producer hub option is selected + page.find('a', class: 'selected', text: "HUB SHOP") + expect(enterprise.reload.is_primary_producer).to eq false + expect(enterprise.reload.producer_profile_only).to eq false + + # Displays the correct dashboard sections + assert_hub_menu + assert_hub_content + + # Changes to producer shop + page.find('a', text: "PROFILE ONLY").click + click_button "Change now" + expect(page).to have_content update_message + + # Checks changes are persistent + click_button "Change Package" + + page.find('a', class: 'selected', text: "PROFILE ONLY") + expect(enterprise.reload.is_primary_producer).to eq false + expect(enterprise.reload.producer_profile_only).to eq false # this should be true? + + # Displays the correct dashboard sections + assert_profile + end + end + end +end + +def update_message + %(Congratulations! Registration for #{enterprise.name} is complete!) +end + +def assert_hub_menu + within "#admin-menu" do + expect(page).to have_content "DASHBOARD" + expect(page).to have_content "PRODUCTS" + expect(page).to have_content "ORDER CYCLES" + expect(page).to have_content "ORDERS" + expect(page).to have_content "REPORTS" + expect(page).to have_content "ENTERPRISES" + expect(page).to have_content "CUSTOMERS" + end +end + +def assert_hub_content + within "#content" do + expect(page).to have_content "Your profile live" + expect(page).to have_content "Edit profile details" + expect(page).to have_content "Add & manage products" + expect(page).to have_content "Add & manage order cycles" + end +end + +def assert_supplier_menu + within "#admin-menu" do + expect(page).to have_content "DASHBOARD" + expect(page).to have_content "PRODUCTS" + expect(page).not_to have_content "ORDER CYCLES" + expect(page).not_to have_content "ORDERS" + expect(page).to have_content "REPORTS" + expect(page).to have_content "ENTERPRISES" + expect(page).not_to have_content "CUSTOMERS" + end +end + +def assert_supplier_content + within "#content" do + expect(page).to have_content "Your profile live" + expect(page).to have_content "Edit profile details" + expect(page).to have_content "Add & manage products" + expect(page).not_to have_content "Add & manage order cycles" + end +end + +def assert_profile + within "#admin-menu" do + expect(page).to have_content "DASHBOARD" + expect(page).to have_content "ENTERPRISES" + end + + within "#content" do + expect(page).to have_content "Your profile live" + expect(page).to have_content "Edit profile details" + end end From 16477cad516f99422056bb3595c07efc146d0891 Mon Sep 17 00:00:00 2001 From: filipefurtad0 Date: Sun, 9 Jul 2023 23:13:05 +0100 Subject: [PATCH 2/3] Adds spec for profile change (2) via enterprises path --- spec/system/admin/enterprises_spec.rb | 119 ++++++++++++++++++++++++++ 1 file changed, 119 insertions(+) diff --git a/spec/system/admin/enterprises_spec.rb b/spec/system/admin/enterprises_spec.rb index 383c9f5c61..b99e84eac0 100644 --- a/spec/system/admin/enterprises_spec.rb +++ b/spec/system/admin/enterprises_spec.rb @@ -929,6 +929,125 @@ describe ' assert_profile end end + + context "via enterprises path, for a producer" do + before do + visit admin_enterprises_path + end + + it "sees and changes user role" do + page.find("td.package").click + + # checks options for producer profile + expect(page).to have_content "PROFILE ONLY" + expect(page).to have_content "PRODUCER SHOP" + expect(page).to have_content "PRODUCER HUB" + expect(page).not_to have_content "HUB SHOP" + + # Producer hub option is selected + page.find('a', class: 'selected', text: "PRODUCER HUB") + expect(enterprise.is_primary_producer).to eq true + expect(enterprise.reload.sells).to eq('any') + + # Displays the correct dashboard sections + assert_hub_menu + + # Changes to producer shop + page.find('a', text: "PRODUCER SHOP").click + page.find('a', text: "SAVE").click + + # Checks changes are persistent + page.find('a', class: 'selected', text: "PRODUCER SHOP") + + # updates page + page.refresh + + # Displays the correct dashboard sections + assert_hub_menu + expect(enterprise.reload.sells).to eq('own') + expect(enterprise.is_primary_producer).to eq true + + # Changes to producer profile + page.find("td.package").click + page.find('a', text: "PROFILE ONLY").click + page.find('a', text: "SAVE").click + + # Checks changes are persistent + page.find('a', class: 'selected', text: "PROFILE ONLY") + + # updates page + page.refresh + + # Displays the correct dashboard sections + assert_supplier_menu + expect(enterprise.reload.sells).to eq('none') + expect(enterprise.reload.is_primary_producer).to eq true + end + end + + context "via enterprises path, for a non-producer" do + before do + visit admin_enterprises_path + end + + it "sees and changes user role" do + # changes to non-producer profile + page.find("td.producer").click + + # checks options for producer profile + expect(page).to have_content "PRODUCER" + expect(page).to have_content "NON-PRODUCER" + + # Producer hub option is selected + page.find('a', class: 'selected', text: "PRODUCER") + expect(enterprise.is_primary_producer).to eq true + expect(enterprise.reload.sells).to eq('any') + + # Changes to non-producer + page.find('a', text: "NON-PRODUCER").click + page.find('a', text: "SAVE").click + + # updates page + page.refresh + + # Displays the correct dashboard sections + assert_hub_menu + + page.find("td.package").click + + # checks options for non-producer profile + expect(page).not_to have_content "PRODUCER PROFILE" + expect(page).not_to have_content "PRODUCER SHOP" + expect(page).not_to have_content "PRODUCER HUB" + expect(page).to have_content "PROFILE ONLY" + expect(page).to have_content "HUB SHOP" + + # Producer hub option is selected + page.find('a', class: 'selected', text: "HUB SHOP") + expect(enterprise.reload.is_primary_producer).to eq false + expect(enterprise.reload.sells).to eq('any') + + # Changes to producer shop + page.find('a', text: "PROFILE ONLY").click + page.find('a', text: "SAVE").click + + # updates page + page.refresh + + # Checks changes are persistent + page.find("td.package").click + page.find('a', class: 'selected', text: "PROFILE ONLY") + + # Displays the correct dashboard sections + within "#admin-menu" do + expect(page).to have_content "DASHBOARD" + expect(page).to have_content "ENTERPRISES" + end + + expect(enterprise.reload.is_primary_producer).to eq false + expect(enterprise.reload.sells).to eq('none') + end + end end end From e14bc5e642dcc70e583bce2fed9a5aa888c11c28 Mon Sep 17 00:00:00 2001 From: filipefurtad0 Date: Tue, 11 Jul 2023 15:32:29 +0100 Subject: [PATCH 3/3] Adds comments on producer_profile_only attribute Fixing typo --- spec/system/admin/enterprises_spec.rb | 28 ++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/spec/system/admin/enterprises_spec.rb b/spec/system/admin/enterprises_spec.rb index b99e84eac0..b179223557 100644 --- a/spec/system/admin/enterprises_spec.rb +++ b/spec/system/admin/enterprises_spec.rb @@ -847,7 +847,7 @@ describe ' # Producer hub option is selected page.find('a', class: 'selected', text: "PRODUCER HUB") - expect(enterprise.is_primary_producer).to eq true + expect(enterprise.reload.is_primary_producer).to eq true expect(enterprise.reload.sells).to eq('any') # Displays the correct dashboard sections @@ -863,7 +863,7 @@ describe ' click_button "Change Package" page.find('a', class: 'selected', text: "PRODUCER SHOP") - expect(enterprise.is_primary_producer).to eq true + expect(enterprise.reload.is_primary_producer).to eq true expect(enterprise.reload.sells).to eq('own') # Displays the correct dashboard sections @@ -879,9 +879,18 @@ describe ' click_button "Change Package" page.find('a', class: 'selected', text: "PRODUCER PROFILE") - expect(enterprise.is_primary_producer).to eq true + + # a primary producer: + expect(enterprise.reload.is_primary_producer).to eq true + + # which is not selling: expect(enterprise.reload.sells).to eq('none') + # then, this should imply + # producer_profile_only to be true + # this probably relates to issue #7835 + expect(enterprise.reload.producer_profile_only).to eq false + # Displays the correct dashboard sections assert_supplier_menu assert_supplier_content @@ -923,7 +932,7 @@ describe ' page.find('a', class: 'selected', text: "PROFILE ONLY") expect(enterprise.reload.is_primary_producer).to eq false - expect(enterprise.reload.producer_profile_only).to eq false # this should be true? + expect(enterprise.reload.producer_profile_only).to eq false # Displays the correct dashboard sections assert_profile @@ -980,8 +989,17 @@ describe ' # Displays the correct dashboard sections assert_supplier_menu - expect(enterprise.reload.sells).to eq('none') + + # a primary producer: expect(enterprise.reload.is_primary_producer).to eq true + + # which is not selling: + expect(enterprise.reload.sells).to eq('none') + + # then, this should imply + # producer_profile_only to be true + # this probably relates to issue #7835 + expect(enterprise.reload.producer_profile_only).to eq false end end