Add instagram handler validator

update entreprise model to match the correct pattern for instagram attribute & add migration to correct wrong links in db + test
This commit is contained in:
Laurel16
2022-11-01 20:45:48 +01:00
committed by Jean-Baptiste Bellet
parent fdf3a0d7b7
commit bfd396e644
7 changed files with 162 additions and 3 deletions

View File

@@ -0,0 +1,39 @@
# frozen_string_literal: true
require 'spec_helper'
require Rails.root.join('db/migrate/20221208150521_update_enterprise_instagram_links.rb')
describe UpdateEnterpriseInstagramLinks do
let!(:enterprise1) { create(:enterprise, instagram: "https://www.instagram.com/happyfarm") }
let!(:enterprise2) { create(:enterprise, instagram: "@happyfarm") }
let!(:enterprise3) { create(:enterprise, instagram: "happyfarm") }
# rubocop:disable Style/NumericLiterals
let(:current_version) { 20221208150521 }
# rubocop:enable Style/NumericLiterals
subject { ActiveRecord::Migrator.new(:up, migrations, current_version).migrate }
context "when link includes https://www.instagram.com/" do
it "removes https://www.instagram.com/" do
expect(enterprise1.instagram).to eq("happyfarm")
end
end
context "when link includes @" do
it "removes @" do
expect(enterprise2.instagram).to eq("happyfarm")
end
end
context "when link includes only the username" do
it "does nothing" do
expect(enterprise3.instagram).to eq("happyfarm")
end
end
end

View File

@@ -155,6 +155,94 @@ describe Enterprise do
end
end
describe "prevent a wrong instagram link pattern" do
it "invalidates the instagram attribute https://facebook.com/user" do
e = build(:enterprise, instagram: 'https://facebook.com/user')
expect(e).to_not be_valid
end
it "invalidates the instagram attribute tagram.com/user" do
e = build(:enterprise, instagram: 'tagram.com/user')
expect(e).to_not be_valid
end
it "invalidates the instagram attribute https://instagram.com/user/preferences" do
e = build(:enterprise, instagram: 'https://instagram.com/user/preferences')
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/')
expect(e).to_not be_valid
end
it "invalidates the instagram attribute https://instagram.com/user-user" do
e = build(:enterprise, instagram: 'https://instagram.com/user-user')
expect(e).to_not be_valid
end
end
describe "Verify accepted instagram url pattern" do
it "validates empty instagram attribute" do
e = build(:enterprise, instagram: '')
expect(e).to be_valid
expect(e.instagram).to eq ""
end
it "validates the instagram attribute @my_user" do
e = build(:enterprise, instagram: '@my_user')
expect(e).to be_valid
expect(e.instagram).to eq "my_user"
end
it "validates the instagram attribute user" do
e = build(:enterprise, instagram: 'user')
expect(e).to be_valid
expect(e.instagram).to eq "user"
end
it "validates the instagram attribute my_www5.example" do
e = build(:enterprise, instagram: 'my_www5.example')
expect(e).to be_valid
expect(e.instagram).to eq "my_www5.example"
end
it "validates the instagram attribute http://instagram.com/user" do
e = build(:enterprise, instagram: 'http://instagram.com/user')
expect(e).to be_valid
expect(e.instagram).to eq "user"
end
it "validates the instagram attribute https://www.instagram.com/user" do
e = build(:enterprise, instagram: 'https://www.instagram.com/user')
expect(e).to be_valid
expect(e.instagram).to eq "user"
end
it "validates the instagram attribute instagram.com/@user" do
e = build(:enterprise, instagram: 'instagram.com/@user')
expect(e).to be_valid
expect(e.instagram).to eq "user"
end
it "validates the instagram attribute Https://www.Instagram.com/@User" do
e = build(:enterprise, instagram: 'Https://www.Instagram.com/@User')
expect(e).to be_valid
expect(e.instagram).to eq "user"
end
it "validates the instagram attribute instagram.com/user" do
e = build(:enterprise, instagram: 'instagram.com/user')
expect(e).to be_valid
expect(e.instagram).to eq "user"
end
it "renders the expected pattern" do
e = build(:enterprise, instagram: 'instagram.com/user')
expect(e.instagram).to eq "user"
end
end
describe "preferred_shopfront_taxon_order" do
it "empty strings are valid" do
enterprise = build(:enterprise, preferred_shopfront_taxon_order: "")

View File

@@ -136,7 +136,7 @@ describe "Registration", js: true 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 "instagram"
click_link "Go to Enterprise Dashboard"
expect(page).to have_content "CHOOSE YOUR PACKAGE"