Skip to content

Commit

Permalink
🥗 Marketplace: System spec for the Vendor Representative
Browse files Browse the repository at this point in the history
- #2044

Testings good, actually
  • Loading branch information
zspencer committed Feb 8, 2024
1 parent 1768518 commit 6c3fad4
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 6 deletions.
4 changes: 4 additions & 0 deletions app/furniture/marketplace/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
4 changes: 2 additions & 2 deletions app/furniture/marketplace/vendor_representative.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -16,7 +16,7 @@ def claimed?
end

def claimable?
matching_person.present?
!claimed? && matching_person.present?
end

def matching_person
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<%= render CardComponent.new do |card| %>

<%- marketplace.vendor_representatives.each do |vendor_representative| %>
<div class="flex flex-row gap-3">
<div id="<%= dom_id(vendor_representative)%>" class="flex flex-row gap-3">
<span class="flex-initial">
<%- if vendor_representative.claimed? %>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
44 changes: 44 additions & 0 deletions spec/furniture/marketplace/vendor_representatives_system_spec.rb
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 6c3fad4

Please sign in to comment.