mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-03-25 05:45:15 +00:00
Adding basic routing and templates for standing orders index
This commit is contained in:
@@ -23,6 +23,10 @@ module Admin
|
||||
|
||||
private
|
||||
|
||||
def collection
|
||||
StandingOrder.where("1=0")
|
||||
end
|
||||
|
||||
def load_shop
|
||||
@shop = Enterprise.find(params[:shop_id])
|
||||
end
|
||||
|
||||
@@ -252,7 +252,7 @@ class AbilityDecorator
|
||||
|
||||
can [:create], Customer
|
||||
can [:admin, :index, :update, :destroy], Customer, enterprise_id: Enterprise.managed_by(user).pluck(:id)
|
||||
can [:admin, :new], StandingOrder
|
||||
can [:admin, :new, :index], StandingOrder
|
||||
can [:create], StandingOrder do |standing_order|
|
||||
user.enterprises.include?(standing_order.shop)
|
||||
end
|
||||
|
||||
4
app/views/admin/standing_orders/index.html.haml
Normal file
4
app/views/admin/standing_orders/index.html.haml
Normal file
@@ -0,0 +1,4 @@
|
||||
- content_for :page_title do
|
||||
= t('admin.standing_orders.standing_orders')
|
||||
|
||||
Listing Standing Orders
|
||||
@@ -790,6 +790,7 @@ en:
|
||||
name: Packing Reports
|
||||
|
||||
standing_orders:
|
||||
standing_orders: Standing Orders
|
||||
new: New Standing Order
|
||||
create: Create Standing Order
|
||||
steps:
|
||||
|
||||
@@ -177,7 +177,7 @@ Openfoodnetwork::Application.routes.draw do
|
||||
|
||||
resources :schedules, only: [:index, :create, :update, :destroy], format: :json
|
||||
|
||||
resources :standing_orders, only: [:new, :create]
|
||||
resources :standing_orders, only: [:index, :new, :create]
|
||||
|
||||
resources :standing_line_items, only: [], format: :json do
|
||||
post :build, on: :collection
|
||||
|
||||
@@ -3,6 +3,40 @@ require 'spec_helper'
|
||||
describe Admin::StandingOrdersController, type: :controller do
|
||||
include AuthenticationWorkflow
|
||||
|
||||
|
||||
describe 'index' do
|
||||
context 'html' do
|
||||
let(:params) { { format: :html } }
|
||||
|
||||
context 'as an regular user' do
|
||||
let!(:user) { create(:user) }
|
||||
|
||||
before do
|
||||
allow(controller).to receive(:spree_current_user) { user }
|
||||
end
|
||||
|
||||
it 'renders the index page' do
|
||||
spree_get :index, params
|
||||
expect(response).to redirect_to spree.unauthorized_path
|
||||
end
|
||||
end
|
||||
|
||||
context 'as an enterprise user' do
|
||||
let!(:user) { create(:user) }
|
||||
let!(:enterprise) { create(:enterprise, owner: user) }
|
||||
|
||||
before do
|
||||
allow(controller).to receive(:spree_current_user) { user }
|
||||
end
|
||||
|
||||
it 'renders the index page' do
|
||||
spree_get :index, params
|
||||
expect(response).to render_template 'index'
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe 'new' do
|
||||
let!(:user) { create(:user) }
|
||||
let!(:shop) { create(:distributor_enterprise, owner: user) }
|
||||
|
||||
@@ -7,75 +7,86 @@ feature 'Standing Orders' do
|
||||
context "as an enterprise user", js: true do
|
||||
let!(:user) { create_enterprise_user(enterprise_limit: 10) }
|
||||
let!(:shop) { create(:distributor_enterprise, owner: user) }
|
||||
let!(:customer) { create(:customer, enterprise: shop) }
|
||||
let!(:product) { create(:product, supplier: shop) }
|
||||
let!(:variant) { create(:variant, product: product, unit_value: '100', price: 12.00, option_values: []) }
|
||||
let!(:enterprise_fee) { create(:enterprise_fee, amount: 1.75) }
|
||||
let!(:order_cycle) { create(:simple_order_cycle, coordinator: shop, orders_open_at: 2.days.from_now, orders_close_at: 7.days.from_now) }
|
||||
let!(:outgoing_exchange) { order_cycle.exchanges.create(sender: shop, receiver: shop, variants: [variant], enterprise_fees: [enterprise_fee]) }
|
||||
let!(:schedule) { create(:schedule, order_cycles: [order_cycle]) }
|
||||
let!(:payment_method) { create(:payment_method, distributors: [shop]) }
|
||||
let!(:shipping_method) { create(:shipping_method, distributors: [shop]) }
|
||||
|
||||
before { quick_login_as user }
|
||||
|
||||
it "I can create a new standing order" do
|
||||
visit new_admin_standing_order_path(shop_id: shop.id)
|
||||
context 'listing standing orders' do
|
||||
it "passes the smoke test" do
|
||||
visit admin_standing_orders_path
|
||||
|
||||
select2_select customer.email, from: 'customer_id'
|
||||
select2_select schedule.name, from: 'schedule_id'
|
||||
select2_select payment_method.name, from: 'payment_method_id'
|
||||
select2_select shipping_method.name, from: 'shipping_method_id'
|
||||
|
||||
# No date filled out, so error returned
|
||||
click_button('Next')
|
||||
expect(page).to have_content 'can\'t be blank'
|
||||
expect(page).to have_content 'Oops! Please fill in all of the required fields...'
|
||||
fill_in 'begins_at', with: Date.today.strftime('%F')
|
||||
|
||||
click_button('Next')
|
||||
expect(page).to have_content 'NAME OR SKU'
|
||||
click_button('Next')
|
||||
expect(page).to have_content 'Please add at least one product'
|
||||
|
||||
# Adding a product and getting a price estimate
|
||||
targetted_select2_search product.name, from: '#add_variant_id', dropdown_css: '.select2-drop'
|
||||
fill_in 'add_quantity', with: 2
|
||||
click_link 'Add'
|
||||
within 'table#standing-line-items tr.item', match: :first do
|
||||
expect(page).to have_selector 'td.description', text: "#{product.name} - #{variant.full_name}"
|
||||
expect(page).to have_selector 'td.price', text: "$13.75"
|
||||
expect(page).to have_input 'quantity', with: "2"
|
||||
expect(page).to have_selector 'td.total', text: "$27.50"
|
||||
expect(page).to have_content 'Listing Standing Orders'
|
||||
end
|
||||
end
|
||||
|
||||
click_button('Next')
|
||||
context 'creating a new standing order' do
|
||||
let!(:customer) { create(:customer, enterprise: shop) }
|
||||
let!(:product) { create(:product, supplier: shop) }
|
||||
let!(:variant) { create(:variant, product: product, unit_value: '100', price: 12.00, option_values: []) }
|
||||
let!(:enterprise_fee) { create(:enterprise_fee, amount: 1.75) }
|
||||
let!(:order_cycle) { create(:simple_order_cycle, coordinator: shop, orders_open_at: 2.days.from_now, orders_close_at: 7.days.from_now) }
|
||||
let!(:outgoing_exchange) { order_cycle.exchanges.create(sender: shop, receiver: shop, variants: [variant], enterprise_fees: [enterprise_fee]) }
|
||||
let!(:schedule) { create(:schedule, order_cycles: [order_cycle]) }
|
||||
let!(:payment_method) { create(:payment_method, distributors: [shop]) }
|
||||
let!(:shipping_method) { create(:shipping_method, distributors: [shop]) }
|
||||
|
||||
expect{
|
||||
click_button('Create Standing Order')
|
||||
expect(page).to have_content 'Saved'
|
||||
}.to change(StandingOrder, :count).by(1)
|
||||
it "passes the smoke test" do
|
||||
visit new_admin_standing_order_path(shop_id: shop.id)
|
||||
|
||||
# Prices are shown
|
||||
within 'table#standing-line-items tr.item', match: :first do
|
||||
expect(page).to have_selector 'td.description', text: "#{product.name} - #{variant.full_name}"
|
||||
expect(page).to have_selector 'td.price', text: "$13.75"
|
||||
expect(page).to have_input 'quantity', with: "2"
|
||||
expect(page).to have_selector 'td.total', text: "$27.50"
|
||||
select2_select customer.email, from: 'customer_id'
|
||||
select2_select schedule.name, from: 'schedule_id'
|
||||
select2_select payment_method.name, from: 'payment_method_id'
|
||||
select2_select shipping_method.name, from: 'shipping_method_id'
|
||||
|
||||
# No date filled out, so error returned
|
||||
click_button('Next')
|
||||
expect(page).to have_content 'can\'t be blank'
|
||||
expect(page).to have_content 'Oops! Please fill in all of the required fields...'
|
||||
fill_in 'begins_at', with: Date.today.strftime('%F')
|
||||
|
||||
click_button('Next')
|
||||
expect(page).to have_content 'NAME OR SKU'
|
||||
click_button('Next')
|
||||
expect(page).to have_content 'Please add at least one product'
|
||||
|
||||
# Adding a product and getting a price estimate
|
||||
targetted_select2_search product.name, from: '#add_variant_id', dropdown_css: '.select2-drop'
|
||||
fill_in 'add_quantity', with: 2
|
||||
click_link 'Add'
|
||||
within 'table#standing-line-items tr.item', match: :first do
|
||||
expect(page).to have_selector 'td.description', text: "#{product.name} - #{variant.full_name}"
|
||||
expect(page).to have_selector 'td.price', text: "$13.75"
|
||||
expect(page).to have_input 'quantity', with: "2"
|
||||
expect(page).to have_selector 'td.total', text: "$27.50"
|
||||
end
|
||||
|
||||
click_button('Next')
|
||||
|
||||
expect{
|
||||
click_button('Create Standing Order')
|
||||
expect(page).to have_content 'Saved'
|
||||
}.to change(StandingOrder, :count).by(1)
|
||||
|
||||
# Prices are shown
|
||||
within 'table#standing-line-items tr.item', match: :first do
|
||||
expect(page).to have_selector 'td.description', text: "#{product.name} - #{variant.full_name}"
|
||||
expect(page).to have_selector 'td.price', text: "$13.75"
|
||||
expect(page).to have_input 'quantity', with: "2"
|
||||
expect(page).to have_selector 'td.total', text: "$27.50"
|
||||
end
|
||||
|
||||
# Basic properties of standing order are set
|
||||
standing_order = StandingOrder.last
|
||||
expect(standing_order.customer).to eq customer
|
||||
expect(standing_order.schedule).to eq schedule
|
||||
expect(standing_order.payment_method).to eq payment_method
|
||||
expect(standing_order.shipping_method).to eq shipping_method
|
||||
|
||||
# Standing Line Items are created
|
||||
expect(standing_order.standing_line_items.count).to eq 1
|
||||
standing_line_item = standing_order.standing_line_items.first
|
||||
expect(standing_line_item.variant).to eq variant
|
||||
expect(standing_line_item.quantity).to eq 2
|
||||
end
|
||||
|
||||
# Basic properties of standing order are set
|
||||
standing_order = StandingOrder.last
|
||||
expect(standing_order.customer).to eq customer
|
||||
expect(standing_order.schedule).to eq schedule
|
||||
expect(standing_order.payment_method).to eq payment_method
|
||||
expect(standing_order.shipping_method).to eq shipping_method
|
||||
|
||||
# Standing Line Items are created
|
||||
expect(standing_order.standing_line_items.count).to eq 1
|
||||
standing_line_item = standing_order.standing_line_items.first
|
||||
expect(standing_line_item.variant).to eq variant
|
||||
expect(standing_line_item.quantity).to eq 2
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user