Merge pull request #10232 from binarygit/show-correct-error-when-user-inputs-url-as-ig-acc

[Enterprise->Create] Show correct error message when user inputs url in instagram field
This commit is contained in:
Konrad
2023-03-19 21:57:02 +01:00
committed by GitHub
6 changed files with 31 additions and 18 deletions

View File

@@ -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: =>

View File

@@ -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)
@@ -458,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

View File

@@ -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" } }

View File

@@ -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

View File

@@ -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

View File

@@ -98,14 +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
attach_file "image-select", Rails.root.join("spec/fixtures/files/logo.png"), visible: false
@@ -125,22 +117,37 @@ 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 - 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
expect(page).to have_content "Must be user name only eg. the_prof"
# Filling in social
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_instagram', with: 'www.instagram.com/InStAgRaM'
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!'
# 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"
expect(e.twitter).to eq "TwItTeR"
expect(e.instagram).to eq "instagram"
expect(e.twitter).to eq "OpenFoodNet"
expect(e.instagram).to eq "openfoodnetwork"
click_link "Go to Enterprise Dashboard"
expect(page).to have_content "CHOOSE YOUR PACKAGE"