mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-03-16 04:24:23 +00:00
Merge branch 'master' into ent_types_frontend
This commit is contained in:
@@ -2,6 +2,7 @@ require 'spec_helper'
|
||||
|
||||
module Admin
|
||||
describe EnterprisesController do
|
||||
include AuthenticationWorkflow
|
||||
let(:distributor_owner) do
|
||||
user = create(:user)
|
||||
user.spree_roles = []
|
||||
@@ -110,36 +111,52 @@ module Admin
|
||||
end
|
||||
|
||||
describe "bulk updating enterprises" do
|
||||
let(:profile_enterprise1) { create(:enterprise, type: 'profile') }
|
||||
let(:profile_enterprise2) { create(:enterprise, type: 'profile') }
|
||||
let!(:original_owner) do
|
||||
user = create_enterprise_user
|
||||
user.enterprise_limit = 2
|
||||
user.save!
|
||||
user
|
||||
end
|
||||
let!(:new_owner) do
|
||||
user = create_enterprise_user
|
||||
user.enterprise_limit = 2
|
||||
user.save!
|
||||
user
|
||||
end
|
||||
let!(:profile_enterprise1) { create(:enterprise, type: 'profile', owner: original_owner ) }
|
||||
let!(:profile_enterprise2) { create(:enterprise, type: 'profile', owner: original_owner ) }
|
||||
|
||||
context "as manager" do
|
||||
it "does not allow 'type' to be changed" do
|
||||
profile_enterprise1.enterprise_roles.build(user: user).save
|
||||
profile_enterprise2.enterprise_roles.build(user: user).save
|
||||
controller.stub spree_current_user: user
|
||||
bulk_enterprise_params = { enterprise_set: { collection_attributes: { '0' => { id: profile_enterprise1.id, type: 'full' }, '1' => { id: profile_enterprise2.id, type: 'full' } } } }
|
||||
it "does not allow 'type' or 'owner' to be changed" do
|
||||
profile_enterprise1.enterprise_roles.build(user: new_owner).save
|
||||
profile_enterprise2.enterprise_roles.build(user: new_owner).save
|
||||
controller.stub spree_current_user: new_owner
|
||||
bulk_enterprise_params = { enterprise_set: { collection_attributes: { '0' => { id: profile_enterprise1.id, type: 'full', owner_id: new_owner.id }, '1' => { id: profile_enterprise2.id, type: 'full', owner_id: new_owner.id } } } }
|
||||
|
||||
spree_put :bulk_update, bulk_enterprise_params
|
||||
profile_enterprise1.reload
|
||||
profile_enterprise2.reload
|
||||
expect(profile_enterprise1.type).to eq 'profile'
|
||||
expect(profile_enterprise2.type).to eq 'profile'
|
||||
expect(profile_enterprise1.owner).to eq original_owner
|
||||
expect(profile_enterprise2.owner).to eq original_owner
|
||||
end
|
||||
end
|
||||
|
||||
context "as super admin" do
|
||||
it "allows 'type' to be changed" do
|
||||
profile_enterprise1.enterprise_roles.build(user: user).save
|
||||
profile_enterprise2.enterprise_roles.build(user: user).save
|
||||
it "allows 'type' and 'owner' to be changed" do
|
||||
profile_enterprise1.enterprise_roles.build(user: new_owner).save
|
||||
profile_enterprise2.enterprise_roles.build(user: new_owner).save
|
||||
controller.stub spree_current_user: admin_user
|
||||
bulk_enterprise_params = { enterprise_set: { collection_attributes: { '0' => { id: profile_enterprise1.id, type: 'full' }, '1' => { id: profile_enterprise2.id, type: 'full' } } } }
|
||||
bulk_enterprise_params = { enterprise_set: { collection_attributes: { '0' => { id: profile_enterprise1.id, type: 'full', owner_id: new_owner.id }, '1' => { id: profile_enterprise2.id, type: 'full', owner_id: new_owner.id } } } }
|
||||
|
||||
spree_put :bulk_update, bulk_enterprise_params
|
||||
profile_enterprise1.reload
|
||||
profile_enterprise2.reload
|
||||
expect(profile_enterprise1.type).to eq 'full'
|
||||
expect(profile_enterprise2.type).to eq 'full'
|
||||
expect(profile_enterprise1.owner).to eq new_owner
|
||||
expect(profile_enterprise2.owner).to eq new_owner
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
54
spec/controllers/api/enterprises_controller_spec.rb
Normal file
54
spec/controllers/api/enterprises_controller_spec.rb
Normal file
@@ -0,0 +1,54 @@
|
||||
require 'spec_helper'
|
||||
|
||||
module Api
|
||||
describe EnterprisesController do
|
||||
include AuthenticationWorkflow
|
||||
render_views
|
||||
|
||||
let(:enterprise) { create(:distributor_enterprise) }
|
||||
|
||||
before do
|
||||
stub_authentication!
|
||||
Enterprise.stub(:find).and_return(enterprise)
|
||||
end
|
||||
|
||||
describe "as an enterprise manager" do
|
||||
let(:enterprise_manager) { create_enterprise_user }
|
||||
|
||||
before do
|
||||
enterprise_manager.enterprise_roles.build(enterprise: enterprise).save
|
||||
Spree.user_class.stub :find_by_spree_api_key => enterprise_manager
|
||||
end
|
||||
|
||||
describe "submitting a valid image" do
|
||||
before do
|
||||
enterprise.stub(:update_attributes).and_return(true)
|
||||
end
|
||||
|
||||
it "I can update enterprise image" do
|
||||
spree_post :update_image, logo: 'a logo'
|
||||
response.should be_success
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "as an non-managing user" do
|
||||
let(:non_managing_user) { create_enterprise_user }
|
||||
|
||||
before do
|
||||
Spree.user_class.stub :find_by_spree_api_key => non_managing_user
|
||||
end
|
||||
|
||||
describe "submitting a valid image" do
|
||||
before do
|
||||
enterprise.stub(:update_attributes).and_return(true)
|
||||
end
|
||||
|
||||
it "I can't update enterprise image" do
|
||||
spree_post :update_image, logo: 'a logo'
|
||||
assert_unauthorized!
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -12,4 +12,28 @@ describe RegistrationController do
|
||||
response.should redirect_to registration_auth_path(anchor: "signup?after_login=/register/store")
|
||||
end
|
||||
end
|
||||
|
||||
describe "loading data when user is logged in" do
|
||||
let!(:user) { double(:user) }
|
||||
|
||||
before do
|
||||
controller.stub spree_current_user: user
|
||||
user.stub spree_api_key: '12345'
|
||||
user.stub last_incomplete_spree_order: nil
|
||||
end
|
||||
|
||||
describe "index" do
|
||||
it "loads the spree api key" do
|
||||
get :index
|
||||
expect(assigns(:spree_api_key)).to eq '12345'
|
||||
end
|
||||
end
|
||||
|
||||
describe "store" do
|
||||
it "loads the spree api key" do
|
||||
get :store
|
||||
expect(assigns(:spree_api_key)).to eq '12345'
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -10,21 +10,29 @@ FactoryGirl.define do
|
||||
|
||||
after(:create) do |oc|
|
||||
# Suppliers
|
||||
supplier1 = create(:supplier_enterprise)
|
||||
supplier2 = create(:supplier_enterprise)
|
||||
|
||||
# Incoming Exchanges
|
||||
ex1 = create(:exchange, :order_cycle => oc, :incoming => true,
|
||||
:sender => create(:supplier_enterprise), :receiver => oc.coordinator)
|
||||
:sender => supplier1, :receiver => oc.coordinator)
|
||||
ex2 = create(:exchange, :order_cycle => oc, :incoming => true,
|
||||
:sender => create(:supplier_enterprise), :receiver => oc.coordinator)
|
||||
:sender => supplier2, :receiver => oc.coordinator)
|
||||
ExchangeFee.create!(exchange: ex1,
|
||||
enterprise_fee: create(:enterprise_fee, enterprise: ex1.sender))
|
||||
ExchangeFee.create!(exchange: ex2,
|
||||
enterprise_fee: create(:enterprise_fee, enterprise: ex2.sender))
|
||||
|
||||
# Distributors
|
||||
#Distributors
|
||||
distributor1 = create(:distributor_enterprise)
|
||||
distributor2 = create(:distributor_enterprise)
|
||||
|
||||
# Outgoing Exchanges
|
||||
ex3 = create(:exchange, :order_cycle => oc, :incoming => false,
|
||||
:sender => oc.coordinator, :receiver => create(:distributor_enterprise),
|
||||
:sender => oc.coordinator, :receiver => distributor1,
|
||||
:pickup_time => 'time 0', :pickup_instructions => 'instructions 0')
|
||||
ex4 = create(:exchange, :order_cycle => oc, :incoming => false,
|
||||
:sender => oc.coordinator, :receiver => create(:distributor_enterprise),
|
||||
:sender => oc.coordinator, :receiver => distributor2,
|
||||
:pickup_time => 'time 1', :pickup_instructions => 'instructions 1')
|
||||
ExchangeFee.create!(exchange: ex3,
|
||||
enterprise_fee: create(:enterprise_fee, enterprise: ex3.receiver))
|
||||
|
||||
@@ -10,7 +10,7 @@ feature %q{
|
||||
after { Warden.test_reset! }
|
||||
stub_authorization!
|
||||
|
||||
pending "listing orders" do
|
||||
context "listing orders" do
|
||||
before :each do
|
||||
admin_user = quick_login_as_admin
|
||||
end
|
||||
@@ -92,7 +92,7 @@ feature %q{
|
||||
end
|
||||
end
|
||||
|
||||
pending "altering line item properties" do
|
||||
context "altering line item properties" do
|
||||
before :each do
|
||||
admin_user = quick_login_as_admin
|
||||
end
|
||||
@@ -140,7 +140,7 @@ feature %q{
|
||||
end
|
||||
end
|
||||
|
||||
pending "using page controls" do
|
||||
context "using page controls" do
|
||||
before :each do
|
||||
admin_user = quick_login_as_admin
|
||||
end
|
||||
@@ -562,7 +562,7 @@ feature %q{
|
||||
end
|
||||
end
|
||||
|
||||
pending "as an enterprise manager" do
|
||||
context "as an enterprise manager" do
|
||||
let(:s1) { create(:supplier_enterprise, name: 'First Supplier') }
|
||||
let(:d1) { create(:distributor_enterprise, name: 'First Distributor') }
|
||||
let(:d2) { create(:distributor_enterprise, name: 'Another Distributor') }
|
||||
|
||||
@@ -110,10 +110,10 @@ feature %q{
|
||||
let(:coordinator2) { create(:distributor_enterprise) }
|
||||
let!(:order_cycle1) { create(:order_cycle, coordinator: coordinator1) }
|
||||
let!(:order_cycle2) { create(:simple_order_cycle, coordinator: coordinator2) }
|
||||
let(:supplier1) { order_cycle1.suppliers.first }
|
||||
let(:supplier2) { order_cycle1.suppliers.last }
|
||||
let(:distributor1) { order_cycle1.distributors.first }
|
||||
let(:distributor2) { order_cycle1.distributors.last }
|
||||
let!(:supplier1) { order_cycle1.suppliers.first }
|
||||
let!(:supplier2) { order_cycle1.suppliers.last }
|
||||
let!(:distributor1) { order_cycle1.distributors.first }
|
||||
let!(:distributor2) { order_cycle1.distributors.reject{ |d| d == distributor1 }.last } # ensure d1 != d2
|
||||
let(:product) { order_cycle1.products.first }
|
||||
|
||||
before(:each) do
|
||||
@@ -132,19 +132,6 @@ feature %q{
|
||||
expect(page).to have_content 'ADD PRODUCT'
|
||||
targetted_select2_search product.name, from: '#add_variant_id', dropdown_css: '.select2-drop'
|
||||
|
||||
puts "c1: " + coordinator1.id.to_s + " "+ coordinator1.name
|
||||
puts "c2: " + coordinator2.id.to_s + " "+ coordinator2.name
|
||||
puts "s1: " + supplier1.id.to_s + " "+ supplier1.name
|
||||
puts "s2: " + supplier2.id.to_s + " "+ supplier2.name
|
||||
puts "d1: " + distributor1.id.to_s + " "+ distributor1.name
|
||||
puts "d2: " + distributor2.id.to_s + " "+ distributor2.name
|
||||
order_cycle1.distributors.each do |distributor|
|
||||
puts "oc1d: " + distributor.id.to_s + " "+ distributor.name
|
||||
end
|
||||
Enterprise.is_distributor.managed_by(@enterprise_user).each do |distributor|
|
||||
puts "eud: " + distributor.id.to_s + " "+ distributor.name
|
||||
end
|
||||
|
||||
click_link 'Add'
|
||||
page.has_selector? "table.index tbody[data-hook='admin_order_form_line_items'] tr" # Wait for JS
|
||||
expect(page).to have_selector 'td', text: product.name
|
||||
|
||||
@@ -60,15 +60,22 @@ feature "Registration", js: true do
|
||||
fill_in 'enterprise_acn', with: '54321'
|
||||
click_button 'Continue'
|
||||
|
||||
# Enterprise should be updated
|
||||
expect(page).to have_content 'Last step!'
|
||||
# Enterprise should be update
|
||||
expect(page).to have_content "Let's upload some pretty pictures so your profile looks great!"
|
||||
e.reload
|
||||
expect(e.description).to eq "Short description"
|
||||
expect(e.long_description).to eq "Long description"
|
||||
expect(e.abn).to eq '12345'
|
||||
expect(e.acn).to eq '54321'
|
||||
|
||||
# Images
|
||||
# Move from logo page
|
||||
click_button 'Continue'
|
||||
# Move from promo page
|
||||
click_button 'Continue'
|
||||
|
||||
# Filling in social
|
||||
expect(page).to have_content 'Last step!'
|
||||
fill_in 'enterprise_website', with: 'www.shop.com'
|
||||
fill_in 'enterprise_facebook', with: 'FaCeBoOk'
|
||||
fill_in 'enterprise_linkedin', with: 'LiNkEdIn'
|
||||
|
||||
@@ -7,7 +7,7 @@ describe "enterpriseCtrl", ->
|
||||
|
||||
beforeEach ->
|
||||
module('admin.enterprises')
|
||||
Enterprise =
|
||||
Enterprise =
|
||||
enterprise:
|
||||
payment_method_ids: [ 1, 3 ]
|
||||
shipping_method_ids: [ 2, 4 ]
|
||||
@@ -15,7 +15,7 @@ describe "enterpriseCtrl", ->
|
||||
paymentMethods: [ { id: 1 }, { id: 2 }, { id: 3 }, { id: 4 } ]
|
||||
ShippingMethods =
|
||||
shippingMethods: [ { id: 1 }, { id: 2 }, { id: 3 }, { id: 4 } ]
|
||||
|
||||
|
||||
inject ($controller) ->
|
||||
scope = {}
|
||||
ctrl = $controller 'enterpriseCtrl', {$scope: scope, Enterprise: Enterprise, PaymentMethods: PaymentMethods, ShippingMethods: ShippingMethods}
|
||||
@@ -82,4 +82,4 @@ describe "enterpriseCtrl", ->
|
||||
describe "counting selected shipping methods", ->
|
||||
it "counts only shipping methods with selected: true", ->
|
||||
scope.ShippingMethods = [ { selected: true }, { selected: true }, { selected: false }, { selected: true } ]
|
||||
expect(scope.selectedShippingMethodsCount()).toBe 3
|
||||
expect(scope.selectedShippingMethodsCount()).toBe 3
|
||||
|
||||
@@ -13,6 +13,13 @@ module Spree
|
||||
let(:enterprise_single) { create(:enterprise, type: 'single') }
|
||||
let(:enterprise_profile) { create(:enterprise, type: 'profile') }
|
||||
|
||||
describe "creating enterprises" do
|
||||
it "can create enterprises straight off the bat" do
|
||||
subject.is_new_user?(user).should be_true
|
||||
expect(user).to have_ability :create, for: Enterprise
|
||||
end
|
||||
end
|
||||
|
||||
describe "managing enterprises" do
|
||||
it "can manage enterprises when the user has at least one enterprise assigned" do
|
||||
user.enterprise_roles.create! enterprise: enterprise_full
|
||||
|
||||
@@ -3,20 +3,15 @@ RSpec::Matchers.define :have_table_row do |row|
|
||||
match_for_should do |node|
|
||||
@row = row
|
||||
|
||||
false_on_timeout_error do
|
||||
wait_until { rows_under(node).include? row }
|
||||
end
|
||||
node.has_selector? "tr", text: row.join(" ").strip # Check for appearance
|
||||
rows_under(node).include? row # Robust check of columns
|
||||
end
|
||||
|
||||
match_for_should_not do |node|
|
||||
@row = row
|
||||
|
||||
false_on_timeout_error do
|
||||
# Without this sleep, we trigger capybara's wait when looking up the table, for the full
|
||||
# period of default_wait_time.
|
||||
sleep 0.1
|
||||
wait_until { !rows_under(node).include? row }
|
||||
end
|
||||
node.has_no_selector? "tr", text: row.join(" ").strip # Check for appearance
|
||||
!rows_under(node).include? row # Robust check of columns
|
||||
end
|
||||
|
||||
failure_message_for_should do |text|
|
||||
@@ -27,17 +22,7 @@ RSpec::Matchers.define :have_table_row do |row|
|
||||
"expected not to find table row #{@row}"
|
||||
end
|
||||
|
||||
|
||||
def rows_under(node)
|
||||
node.all('tr').map { |tr| tr.all('th, td').map(&:text) }
|
||||
end
|
||||
|
||||
def false_on_timeout_error
|
||||
yield
|
||||
rescue TimeoutError
|
||||
false
|
||||
else
|
||||
true
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user