From 533f7048bfb37ff0f224a6c916aeab4005ea56e1 Mon Sep 17 00:00:00 2001 From: binarygit Date: Wed, 4 Jan 2023 16:33:21 +0545 Subject: [PATCH 1/5] [Enterprise->Create] Show correct error message when user inputs url in instagram field --- .../services/enterprise_registration_service.js.coffee | 4 ++++ app/views/registration/steps/_social.html.haml | 1 + spec/system/consumer/registration_spec.rb | 7 +++++++ 3 files changed, 12 insertions(+) diff --git a/app/assets/javascripts/darkswarm/services/enterprise_registration_service.js.coffee b/app/assets/javascripts/darkswarm/services/enterprise_registration_service.js.coffee index 485bc5a36f..614e109eac 100644 --- a/app/assets/javascripts/darkswarm/services/enterprise_registration_service.js.coffee +++ b/app/assets/javascripts/darkswarm/services/enterprise_registration_service.js.coffee @@ -55,6 +55,10 @@ angular.module('Darkswarm').factory "EnterpriseRegistrationService", ($http, Reg ).catch((response) -> Loading.clear() alert(t('failed_to_update_enterprise_unknown')) + if response.data.errors.instagram + igErr = document.querySelector("#instagram-error") + igErr.style.display = 'block' + igErr.textContent = response.data.errors.instagram[0] ) prepare: => diff --git a/app/views/registration/steps/_social.html.haml b/app/views/registration/steps/_social.html.haml index 8552b927b7..9cd86ead1c 100644 --- a/app/views/registration/steps/_social.html.haml +++ b/app/views/registration/steps/_social.html.haml @@ -37,6 +37,7 @@ .field %label{ for: 'enterprise_instagram' }= t(".instagram")+":" %input.chunky{ id: 'enterprise_instagram', placeholder: "{{'registration.steps.social.instagram_placeholder' | t}}", ng: { model: 'enterprise.instagram' } } + %span.error.small-12.columns#instagram-error{ style: "display: none" } .row.buttons .small-12.columns diff --git a/spec/system/consumer/registration_spec.rb b/spec/system/consumer/registration_spec.rb index 695455b0f4..1c17aff003 100644 --- a/spec/system/consumer/registration_spec.rb +++ b/spec/system/consumer/registration_spec.rb @@ -125,6 +125,13 @@ describe "Registration" do click_button "Continue" expect(page).to have_content 'How can people find My Awesome Enterprise online?' + # Filling in social with invalid value for instagram + fill_in "enterprise_instagram", with: "www.instagram.com/coopcircuits/ " + click_button "Continue" + accept_alert "Failed to update your enterprise." do + expect(page).to have_content "Must be user name only eg. the_prof" + end + # Filling in social fill_in 'enterprise_website', with: 'www.shop.com' fill_in 'enterprise_facebook', with: 'FaCeBoOk' From ae166ae2202b331e9f8ae46ecdccf69412f0693c Mon Sep 17 00:00:00 2001 From: binarygit Date: Thu, 5 Jan 2023 15:22:06 +0545 Subject: [PATCH 2/5] Fix: User does not get stuck when going backwards while creating new ent --- app/views/registration/steps/_about.html.haml | 2 +- spec/system/consumer/registration_spec.rb | 15 ++++++++------- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/app/views/registration/steps/_about.html.haml b/app/views/registration/steps/_about.html.haml index 5ec5dbb2c7..65a688e54b 100644 --- a/app/views/registration/steps/_about.html.haml +++ b/app/views/registration/steps/_about.html.haml @@ -10,7 +10,7 @@ %span{ ng: { class: "{brick: !enterprise.is_primary_producer, turquoise: enterprise.is_primary_producer}" } } {{ enterprise.name }} - %form{ name: 'about', novalidate: true, ng: { controller: "RegistrationFormCtrl", submit: "update('images',about)" } } + %form{ name: 'about', novalidate: true, ng: { controller: "RegistrationFormCtrl", submit: "selectIfValid('images', about)" } } .row .small-12.columns .alert-box.info{ "ofn-inline-alert" => true, ng: { show: "visible" } } diff --git a/spec/system/consumer/registration_spec.rb b/spec/system/consumer/registration_spec.rb index 1c17aff003..8486533e64 100644 --- a/spec/system/consumer/registration_spec.rb +++ b/spec/system/consumer/registration_spec.rb @@ -98,13 +98,6 @@ describe "Registration" do click_button "Continue" expect(page).to have_content 'Step 1. Select Logo Image' - # Enterprise should be updated - e.reload - expect(e.description).to eq "Short description" - expect(e.long_description).to eq "Long description" - expect(e.abn).to eq '12345' - expect(e.acn).to eq '54321' - expect(e.charges_sales_tax).to be true # Images # Upload logo image @@ -142,7 +135,15 @@ describe "Registration" do expect(page).to have_content 'Finished!' # Done + # Check values set in about tab e.reload + expect(e.description).to eq "Short description" + expect(e.long_description).to eq "Long description" + expect(e.abn).to eq '12345' + expect(e.acn).to eq '54321' + expect(e.charges_sales_tax).to be true + + # Check values set in social tab expect(e.website).to eq "www.shop.com" expect(e.facebook).to eq "FaCeBoOk" expect(e.linkedin).to eq "LiNkEdIn" From 6d05d57846ca3ba63bcad953c2e0b526f679b6a1 Mon Sep 17 00:00:00 2001 From: filipefurtad0 Date: Mon, 6 Mar 2023 10:38:27 +0000 Subject: [PATCH 3/5] Fixes spec when introducing invalid instagram link It seems that only the slash at the end of the address is making it invalid, which does not correspond to the error message. This is a separate issue. --- spec/system/consumer/registration_spec.rb | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/spec/system/consumer/registration_spec.rb b/spec/system/consumer/registration_spec.rb index 8486533e64..6d3febe1c7 100644 --- a/spec/system/consumer/registration_spec.rb +++ b/spec/system/consumer/registration_spec.rb @@ -98,7 +98,6 @@ describe "Registration" do click_button "Continue" expect(page).to have_content 'Step 1. Select Logo Image' - # Images # Upload logo image attach_file "image-select", Rails.root.join("spec/fixtures/files/logo.png"), visible: false @@ -118,12 +117,12 @@ describe "Registration" do click_button "Continue" expect(page).to have_content 'How can people find My Awesome Enterprise online?' - # Filling in social with invalid value for instagram - fill_in "enterprise_instagram", with: "www.instagram.com/coopcircuits/ " - click_button "Continue" + # Filling in social with invalid value for instagram - slash after InStAgRaM + fill_in "enterprise_instagram", with: 'www.instagram.com/InStAgRaM/' accept_alert "Failed to update your enterprise." do - expect(page).to have_content "Must be user name only eg. the_prof" + click_button "Continue" end + expect(page).to have_content "Must be user name only eg. the_prof" # Filling in social fill_in 'enterprise_website', with: 'www.shop.com' From 9e7e176cf957e3097d39ddb8585576a5b17883ae Mon Sep 17 00:00:00 2001 From: David Cook Date: Thu, 9 Mar 2023 09:47:37 +1100 Subject: [PATCH 4/5] Accept full URLs It looks like the intention was there, so I made it work. I've included a real world example, but added capitalisation to complete the test. --- app/models/enterprise.rb | 3 ++- spec/models/enterprise_spec.rb | 4 ++-- spec/system/consumer/registration_spec.rb | 8 ++++---- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/app/models/enterprise.rb b/app/models/enterprise.rb index 20f0aba26d..771aba8bc9 100644 --- a/app/models/enterprise.rb +++ b/app/models/enterprise.rb @@ -450,7 +450,8 @@ class Enterprise < ApplicationRecord end def strip_url(url) - url&.sub(%r{(https?://)?}, '') + # Strip protocol and trailing slash + url&.sub(%r{(https?://)?}, '')&.sub(%r{/\z}, '') end def correct_whatsapp_url(phone_number) diff --git a/spec/models/enterprise_spec.rb b/spec/models/enterprise_spec.rb index 6055360bbd..f6290a8687 100644 --- a/spec/models/enterprise_spec.rb +++ b/spec/models/enterprise_spec.rb @@ -171,8 +171,8 @@ describe Enterprise do expect(e).to_not be_valid end - it "invalidates the instagram attribute https://instagram.com/user/" do - e = build(:enterprise, instagram: 'https://instagram.com/user/') + it "invalidates the instagram attribute https://www.instagram.com/p/Cpg4McNPyJA/" do + e = build(:enterprise, instagram: 'https://www.instagram.com/p/Cpg4McNPyJA/') expect(e).to_not be_valid end diff --git a/spec/system/consumer/registration_spec.rb b/spec/system/consumer/registration_spec.rb index 6d3febe1c7..938f6afda7 100644 --- a/spec/system/consumer/registration_spec.rb +++ b/spec/system/consumer/registration_spec.rb @@ -117,8 +117,8 @@ describe "Registration" do click_button "Continue" expect(page).to have_content 'How can people find My Awesome Enterprise online?' - # Filling in social with invalid value for instagram - slash after InStAgRaM - fill_in "enterprise_instagram", with: 'www.instagram.com/InStAgRaM/' + # Filling in social with invalid value for instagram - a link to a post instead of user + fill_in "enterprise_instagram", with: 'https://www.instagram.com/p/Cpg4McNPyJA/' accept_alert "Failed to update your enterprise." do click_button "Continue" end @@ -129,7 +129,7 @@ describe "Registration" do fill_in 'enterprise_facebook', with: 'FaCeBoOk' fill_in 'enterprise_linkedin', with: 'LiNkEdIn' fill_in 'enterprise_twitter', with: 'https://www.twitter.com/@TwItTeR' - fill_in 'enterprise_instagram', with: 'www.instagram.com/InStAgRaM' + fill_in 'enterprise_instagram', with: 'https://www.instagram.com/OpenFoodNetwork/' click_button "Continue" expect(page).to have_content 'Finished!' @@ -147,7 +147,7 @@ describe "Registration" do expect(e.facebook).to eq "FaCeBoOk" expect(e.linkedin).to eq "LiNkEdIn" expect(e.twitter).to eq "TwItTeR" - expect(e.instagram).to eq "instagram" + expect(e.instagram).to eq "openfoodnetwork" click_link "Go to Enterprise Dashboard" expect(page).to have_content "CHOOSE YOUR PACKAGE" From fdeeab5750285b2acbed8bfd011c9452eb111b27 Mon Sep 17 00:00:00 2001 From: David Cook Date: Thu, 9 Mar 2023 10:02:29 +1100 Subject: [PATCH 5/5] Test twitter with (almost) real world example I discovered that twitter doesn't have 'www' in the url anymore, no '@' symbol and interestingly no trailing slash. I added back the '@' just so we can test that still. Using a regex group we can cater for optional www in a single regex. --- app/models/enterprise.rb | 4 ++-- spec/system/consumer/registration_spec.rb | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/app/models/enterprise.rb b/app/models/enterprise.rb index 771aba8bc9..605a5691d5 100644 --- a/app/models/enterprise.rb +++ b/app/models/enterprise.rb @@ -459,11 +459,11 @@ class Enterprise < ApplicationRecord end def correct_instagram_url(url) - url && strip_url(url.downcase).sub(%r{www.instagram.com/}, '').sub(%r{instagram.com/}, '').delete("@") + url && strip_url(url.downcase).sub(%r{(www\.)?instagram.com/}, '').delete("@") end def correct_twitter_url(url) - url && strip_url(url).sub(%r{www.twitter.com/}, '').delete("@") + url && strip_url(url).sub(%r{(www\.)?twitter.com/}, '').delete("@") end def set_unused_address_fields diff --git a/spec/system/consumer/registration_spec.rb b/spec/system/consumer/registration_spec.rb index 938f6afda7..b7e919f170 100644 --- a/spec/system/consumer/registration_spec.rb +++ b/spec/system/consumer/registration_spec.rb @@ -128,7 +128,7 @@ describe "Registration" do fill_in 'enterprise_website', with: 'www.shop.com' fill_in 'enterprise_facebook', with: 'FaCeBoOk' fill_in 'enterprise_linkedin', with: 'LiNkEdIn' - fill_in 'enterprise_twitter', with: 'https://www.twitter.com/@TwItTeR' + fill_in 'enterprise_twitter', with: 'https://twitter.com/@OpenFoodNet' fill_in 'enterprise_instagram', with: 'https://www.instagram.com/OpenFoodNetwork/' click_button "Continue" expect(page).to have_content 'Finished!' @@ -146,7 +146,7 @@ describe "Registration" do expect(e.website).to eq "www.shop.com" expect(e.facebook).to eq "FaCeBoOk" expect(e.linkedin).to eq "LiNkEdIn" - expect(e.twitter).to eq "TwItTeR" + expect(e.twitter).to eq "OpenFoodNet" expect(e.instagram).to eq "openfoodnetwork" click_link "Go to Enterprise Dashboard"