From 6c3fad4ddaa9ea0b33b3434d7f3f4618084efca5 Mon Sep 17 00:00:00 2001
From: Zee Spencer <50284+zspencer@users.noreply.github.com>
Date: Wed, 7 Feb 2024 17:10:50 -0800
Subject: [PATCH] =?UTF-8?q?=F0=9F=A5=97=20`Marketplace`:=20System=20spec?=
=?UTF-8?q?=20for=20the=20Vendor=20Representative?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
- https://github.com/zinc-collective/convene/issues/2044
Testings good, actually
---
app/furniture/marketplace/locales/en.yml | 4 ++
.../marketplace/vendor_representative.rb | 4 +-
.../vendor_representatives/index.html.erb | 2 +-
.../vendor_representatives_controller.rb | 6 +--
.../vendor_representatives_system_spec.rb | 44 +++++++++++++++++++
5 files changed, 54 insertions(+), 6 deletions(-)
create mode 100644 spec/furniture/marketplace/vendor_representatives_system_spec.rb
diff --git a/app/furniture/marketplace/locales/en.yml b/app/furniture/marketplace/locales/en.yml
index 031326954..a8c0aa18a 100644
--- a/app/furniture/marketplace/locales/en.yml
+++ b/app/furniture/marketplace/locales/en.yml
@@ -119,6 +119,10 @@ en:
link_to: "Vendor Representatives"
new:
link_to: "Add a Representative"
+ create:
+ success: "Added Representative '%{email_address}'"
+ update:
+ success: "Updated Representative '%{email_address}'"
cart_products:
destroy:
success: "Removed %{quantity} %{product} from Cart"
diff --git a/app/furniture/marketplace/vendor_representative.rb b/app/furniture/marketplace/vendor_representative.rb
index bf4667f90..3d89df960 100644
--- a/app/furniture/marketplace/vendor_representative.rb
+++ b/app/furniture/marketplace/vendor_representative.rb
@@ -4,7 +4,7 @@ class VendorRepresentative < Record
belongs_to :marketplace, inverse_of: :vendor_representatives
has_one :room, through: :marketplace
- belongs_to :person
+ belongs_to :person, optional: true
attribute :email_address, :string
validates :email_address, uniqueness: true, presence: true
@@ -16,7 +16,7 @@ def claimed?
end
def claimable?
- matching_person.present?
+ !claimed? && matching_person.present?
end
def matching_person
diff --git a/app/furniture/marketplace/vendor_representatives/index.html.erb b/app/furniture/marketplace/vendor_representatives/index.html.erb
index 22acabd09..24a90aabb 100644
--- a/app/furniture/marketplace/vendor_representatives/index.html.erb
+++ b/app/furniture/marketplace/vendor_representatives/index.html.erb
@@ -3,7 +3,7 @@
<%= render CardComponent.new do |card| %>
<%- marketplace.vendor_representatives.each do |vendor_representative| %>
-
+
<%- if vendor_representative.claimed? %>
✅
diff --git a/app/furniture/marketplace/vendor_representatives_controller.rb b/app/furniture/marketplace/vendor_representatives_controller.rb
index c91fc687e..c036a94b7 100644
--- a/app/furniture/marketplace/vendor_representatives_controller.rb
+++ b/app/furniture/marketplace/vendor_representatives_controller.rb
@@ -13,7 +13,7 @@ def create
authorize(vendor_representative).save
if vendor_representative.persisted?
- redirect_to marketplace.location(child: :vendor_representatives), notice: t(".success", name: vendor_representative.email_address)
+ redirect_to marketplace.location(child: :vendor_representatives), notice: t(".success", email_address: vendor_representative.email_address)
else
render :new, status: :unprocessable_entity
end
@@ -25,10 +25,10 @@ def index
def update
if authorize(vendor_representative).update(vendor_representative_params)
- redirect_to marketplace.location(child: :vendor_representatives), notice: t(".success", name: vendor_representative.email_address)
+ redirect_to marketplace.location(child: :vendor_representatives), notice: t(".success", email_address: vendor_representative.email_address)
else
- redirect_to marketplace.location(child: :vendor_representatives), notice: t(".failure", name: vendor_representative.email_address)
+ redirect_to marketplace.location(child: :vendor_representatives), notice: t(".failure", email_address: vendor_representative.email_address)
end
end
diff --git a/spec/furniture/marketplace/vendor_representatives_system_spec.rb b/spec/furniture/marketplace/vendor_representatives_system_spec.rb
new file mode 100644
index 000000000..3eafa5de8
--- /dev/null
+++ b/spec/furniture/marketplace/vendor_representatives_system_spec.rb
@@ -0,0 +1,44 @@
+require "rails_helper"
+
+# @see https://github.com/zinc-collective/convene/issues/2044
+describe "Marketplace: Vendor Representatives", type: :system do
+ let(:space) { create(:space, :with_entrance, :with_members) }
+ let(:marketplace) { create(:marketplace, :ready_for_shopping, room: space.entrance) }
+
+ before do
+ sign_in(space.members.first, space)
+ end
+
+ describe "Adding a Vendor Representative" do
+ it "Requires a Member confirm the Vendor" do # rubocop:disable RSpec/ExampleLength
+ visit(polymorphic_path(marketplace.location(child: :vendor_representatives)))
+ click_link("Add a Representative")
+ fill_in("Email address", with: "milton@swingline.example.com")
+ expect do
+ click_button("Create")
+ expect(page).to have_content("Added Representative 'milton@swingline.example.com'")
+ marketplace.reload
+ end.to change(marketplace.vendor_representatives, :count).by(1)
+ representative_milton = marketplace.vendor_representatives.find_by(email_address: "milton@swingline.example.com")
+
+ within("##{dom_id(representative_milton)}") do
+ expect(page).to have_content("🛌")
+ end
+ expect(representative_milton).not_to be_claimable
+ expect(representative_milton).not_to be_claimed
+ milton = create(:authentication_method, contact_location: "milton@swingline.example.com").person
+
+ expect(representative_milton).to be_claimable
+ visit(polymorphic_path(marketplace.location(child: :vendor_representatives)))
+
+ expect do
+ within("##{dom_id(representative_milton)}") do
+ click_button("👍")
+ representative_milton.reload
+ end
+ end.to change(representative_milton, :claimed?).to(true)
+
+ expect(representative_milton.person).to eq(milton)
+ end
+ end
+end