Skip to content

Commit

Permalink
Merge pull request #136 from ryanmillergm/card_#42
Browse files Browse the repository at this point in the history
Card #42
  • Loading branch information
MillsProvosty authored May 28, 2019
2 parents 358e902 + 85c8d0f commit fe753d1
Show file tree
Hide file tree
Showing 6 changed files with 255 additions and 4 deletions.
3 changes: 1 addition & 2 deletions app/controllers/admin/merchants_controller.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
class Admin::MerchantsController < ApplicationController

def show
@merchant = User.find(params[:id])
@top_five_items = @merchant.top_items_for_merchant

end
end
6 changes: 5 additions & 1 deletion app/controllers/merchants_controller.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
class MerchantsController < ApplicationController
def index
@merchants = User.active_merchants
if current_admin?
@merchants = User.where(role: 1)
else
@merchants = User.active_merchants
end
end

end
21 changes: 21 additions & 0 deletions app/views/merchants/index.html.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,24 @@
<div>
<<<<<<< HEAD
<%@merchants.each do |merchant| %>
<div id="merchant-<%= merchant.id %>">
<% if !current_admin? %>
<h1><p>Name: <%= merchant.name %> </p></h1>
<p>State: <%= merchant.state %></p>
<p>City: <%= merchant.city %></p>
<p>Registered: <%= merchant.date_registered %></p>
<% elsif current_admin? %>
<h1>Name:<a href="<%= admin_merchant_path(merchant.id) %>"><%= merchant.name %></a></h1>
<p>State: <%= merchant.state %></p>
<p>City: <%= merchant.city %></p>
<p>Active: <%= merchant.active %></p>
<% if merchant.active %>
<%= link_to "Disable Merchant" %>
<% elsif !merchant.active %>
<%= link_to "Enable Merchant" %>
<% end %>
<% end %>
=======
<% @merchants.each do |merchant| %>
<div id="merchant-<%= merchant.id %>">
<% if current_admin? %>
Expand All @@ -9,6 +29,7 @@
<p>State: <%=merchant.state %></p>
<p>City: <%= merchant.city %></p>
<p>Registered: <%=merchant.date_registered%></p>
>>>>>>> 358e902a81349a1624dc0296b6c16ecedf057a95
<div>
<% end %>
</div>
177 changes: 177 additions & 0 deletions spec/features/merchant/merchants/show_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,177 @@
require 'rails_helper'

RSpec.describe 'Merchant Show page' do
context 'when I visit my dashboard' do

before :each do
@merchant = create(:merchant)
@i1,@i2,@i3,@i4,@i5,@i6,@i7,@i8,@i9 = create_list(:item, 10, user: @merchant, price: 1.00)

#item with different merchant
@i12,@i13 = create_list(:item, 2)

#orders with pending status
@o1,@o2,@o3 = create_list(:order, 3)

#orders with shipped status
@o4,@o5,@o6 = create_list(:order, 3, status: 'shipped')

create(:order_item, item: @i1, order: @o1, quantity: 1)
create(:order_item, item: @i2, order: @o1, quantity: 2)
create(:order_item, item: @i3, order: @o1, quantity: 3)
create(:order_item, item: @i4, order: @o2, quantity: 6)
create(:order_item, item: @i5, order: @o2, quantity: 2)
create(:order_item, item: @i6, order: @o2, quantity: 4)
create(:order_item, item: @i7, order: @o3, quantity: 9)
create(:order_item, item: @i8, order: @o3, quantity: 5)
create(:order_item, item: @i9, order: @o3, quantity: 6)
create(:order_item, item: @i2, order: @o4, quantity: 1)
create(:order_item, item: @i2, order: @o5, quantity: 2)

#shipped order
create(:order_item, item: @i2, order: @o6, quantity: 2, fulfilled: true)
create(:order_item, item: @i7, order: @o6, quantity: 20, fulfilled: true)
create(:order_item, item: @i4, order: @o6, quantity: 19, fulfilled: true)
create(:order_item, item: @i9, order: @o6, quantity: 17, fulfilled: true)
create(:order_item, item: @i8, order: @o6, quantity: 15, fulfilled: true)
create(:order_item, item: @i6, order: @o6, quantity: 13, fulfilled: true)

#additional items added to order from different merchant
create(:order_item, item: @i13, order: @o1)
create(:order_item, item: @i12, order: @o1)

visit login_path

fill_in "email", with: @merchant.email
fill_in "password", with: @merchant.password

click_on "Log In"
end

scenario 'i see my profile data but cannot edit it' do
expect(current_path).to eq(merchant_dashboard_path)

expect(page).to have_content(@merchant.name)
expect(page).to have_content(@merchant.email)
expect(page).to have_content(@merchant.address)
expect(page).to have_content(@merchant.city)
expect(page).to have_content(@merchant.state)
expect(page).to have_content(@merchant.zip)

expect(page).to_not have_link("Edit Profile")
end


scenario 'I see a list of pending orders and their information' do
within '#order-info' do
expect(page).to have_link("Order# " << @o1.id.to_s)
expect(page).to have_link("Order# " << @o2.id.to_s)
expect(page).to have_link("Order# " << @o3.id.to_s)
expect(page).to_not have_link("Order# " << @o4.id.to_s)
expect(page).to_not have_link("Order# " << @o5.id.to_s)

expect(page).to have_content("Date Ordered: " << @o1.created_at.strftime("%B %d, %Y"))
expect(page).to have_content("Date Ordered: " << @o2.created_at.strftime("%B %d, %Y"))
expect(page).to have_content("Date Ordered: " << @o3.created_at.strftime("%B %d, %Y"))

expect(page).to have_content("Quantity: " << @o1.item_count_for_merchant(@merchant.id).to_s)
expect(page).to have_content("Quantity: " << @o2.item_count_for_merchant(@merchant.id).to_s)
expect(page).to have_content("Quantity: " << @o3.item_count_for_merchant(@merchant.id).to_s)

expect(page).to have_content("Grand Total: #{number_to_currency @o1.item_total_value_for_merchant(@merchant.id)}")
expect(page).to have_content("Grand Total: #{number_to_currency @o2.item_total_value_for_merchant(@merchant.id)}")
expect(page).to have_content("Grand Total: #{number_to_currency @o3.item_total_value_for_merchant(@merchant.id)}")
end
end

scenario 'there is a link to view just my items' do
expect(page).to have_link('View my items')
click_link('View my items')

expect(current_path).to eq(merchant_items_path)
end

scenario 'I can view details of an order as it pertains to me' do
click_link "Order# #{@o1.id}"
expect(current_path).to eq(merchant_order_path(@o1))
customer = @o1.user

expect(page).to have_content(customer.name)
expect(page).to have_content(customer.address)
expect(page).to have_content(customer.city)
expect(page).to have_content(customer.state)
expect(page).to have_content(customer.zip)

#items from my inventory
within "#item-#{@i1.id}" do
expect(page).to have_content(@i1.name)
expect(find("img")[:src]).to eq(@i1.image)
expect(page).to have_content("Quantity on Order: 1")
expect(page).to have_content("Price: $1.00")
end

within "#item-#{@i2.id}" do
expect(page).to have_content(@i2.name)
expect(find("img")[:src]).to eq(@i2.image)
expect(page).to have_content("Quantity on Order: 2")
expect(page).to have_content("Price: $1.00")
end

within "#item-#{@i3.id}" do
expect(page).to have_content(@i3.name)
expect(find("img")[:src]).to eq(@i3.image)
expect(page).to have_content("Quantity on Order: 3")
expect(page).to have_content("Price: $1.00")
end
end


describe "I see an area with statistics" do

it " top 5 items sold by quantity, quantity of each" do
within("#merchant_stats") do
#7,4,9,8,6
expect(page).to have_content("Top 5 items sold:")
expect(page.all("p")[0]).to have_content("#{@i7.name} : #{@i7.quantity_bought}")
expect(page.all("p")[1]).to have_content("#{@i4.name} : #{@i4.quantity_bought}")
expect(page.all("p")[2]).to have_content("#{@i9.name} : #{@i9.quantity_bought}")
expect(page.all("p")[3]).to have_content("#{@i8.name} : #{@i8.quantity_bought}")
expect(page.all("p")[4]).to have_content("#{@i6.name} : #{@i6.quantity_bought}")
end

end

it "shows total quantity of items sold, % against sold units plus remaining inventory" do
visit merchant_dashboard_path
expect(page).to have_content("Quantity Sold vs. Remaining Inventory")
expect(page).to have_content("Item: #{@i1.name}#{@i1.quantity_bought}, Percentage Remaining: #{number_to_percentage(@i1.percentage_remaining)}")
expect(page).to have_content("Item: #{@i3.name}#{@i3.quantity_bought}, Percentage Remaining: #{number_to_percentage(@i3.percentage_remaining)}")
expect(page).to have_content("Item: #{@i7.name}#{@i7.quantity_bought}, Percentage Remaining: #{number_to_percentage(@i7.percentage_remaining)}")
end

xit "shows top 3 states where items were shipped/quantities shipped, and the top 3 city/states where items shipped and quantities " do
visit merchant_dashboard_path
expect(page).to have_content("Top Three States Where Items Were Shipped:")
expect(page).to have_content("Top Three Cities Where Items Were Shipped:")
expect(page.all("p")[0]).to have_content("#{@i7.name} : #{@i7.quantity_bought}")
within("#states") do
expect(page.all("p")[0]).to have_content("#{@merchant.top_three_states[0]}")
expect(page.all("p")[1]).to have_content("#{@merchant.top_three_states[1]}")
expect(page.all("p")[2]).to have_content("#{@merchant.top_three_states[2]}")
end

within("#cities") do
expect(page.all("p")[0]).to have_content("#{@merchant.top_three_cities[0]}")
expect(page.all("p")[1]).to have_content("#{@merchant.top_three_cities[1]}")
expect(page.all("p")[2]).to have_content("#{@merchant.top_three_cities[2]}")
end
end

xit "shows name of user: with most orders, who bought the most total itmes and total quantity, and top 3 users who have spent the most money and total amount they've spent. " do



end
end
end
end
51 changes: 50 additions & 1 deletion spec/features/merchants/index_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'rails_helper'

RSpec.describe 'Mechant index page' do
RSpec.describe 'Merchant index page' do

context 'As an unregistered user visiting the merchants index page' do
before :each do
Expand Down Expand Up @@ -29,4 +29,53 @@
end
end
end

describe "As an admin user, when I visit the merchant's index page at '/merchants'" do
before :each do
@user = create(:user, role: "admin")
visit login_path

fill_in "email", with: @user.email
fill_in "password", with: @user.password
click_on "Log In"
@merchant_1 = create(:merchant, city: "New Orleans", state: "Louisiana", active: true)
@merchant_2 = create(:merchant, city: "Seatle", state: "Washington", active: false)
visit merchants_path
end

it "I see all merchants, and their city and state" do
within "#merchant-#{@merchant_1.id}" do
expect(page).to have_content("#{@merchant_1.city}")
expect(page).to have_content("#{@merchant_1.state}")
end

within "#merchant-#{@merchant_2.id}" do
expect(page).to have_content("#{@merchant_2.city}")
expect(page).to have_content("#{@merchant_2.state}")
end
end

it "each merchant's name is a link to their dashboard, route admin/merchant/id" do
within "#merchant-#{@merchant_1.id}" do
expect(page).to have_link("#{@merchant_1.name}")
end

within "#merchant-#{@merchant_2.id}" do
expect(page).to have_link("#{@merchant_2.name}")
end
end

it "I see a disable button next to merchants not disabled, and enable button next to those disabled" do
# expect(user.status).to eq("disabled")
within "#merchant-#{@merchant_1.id}" do
expect(@merchant_1.active).to eq(true)
expect(page).to have_link("Disable Merchant")
end

within "#merchant-#{@merchant_2.id}" do
expect(@merchant_2.active).to eq(false)
expect(page).to have_link("Enable Merchant")
end
end
end
end
1 change: 1 addition & 0 deletions spec/features/users/profile_orders_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
@o4_oi3 = create(:order_item, order: @order_4, item: @item_12)

end

it "I see the ID of the order, date created and updated, status, item quantity, grand total" do

allow_any_instance_of(ApplicationController).to receive(:current_user).and_return(@user)
Expand Down

0 comments on commit fe753d1

Please sign in to comment.