Merge branch 'master' into include-ready-for-in-producer-notification

This commit is contained in:
Cillian O'Ruanaidh
2021-01-29 11:30:11 +00:00
123 changed files with 1743 additions and 1530 deletions

View File

@@ -20,7 +20,7 @@ describe Admin::BulkLineItemsController, type: :controller do
before { allow(controller).to receive_messages spree_current_user: create(:user) }
it "should deny me access to the index action" do
spree_get :index, format: :json
get :index, format: :json
expect(response).to redirect_to unauthorized_path
end
end
@@ -32,7 +32,7 @@ describe Admin::BulkLineItemsController, type: :controller do
context "when no ransack params are passed in" do
before do
spree_get :index, format: :json
get :index, format: :json
end
it "retrieves a list of line_items with appropriate attributes, including line items with appropriate attributes" do
@@ -56,7 +56,7 @@ describe Admin::BulkLineItemsController, type: :controller do
context "when ransack params are passed in for line items" do
before do
spree_get :index, format: :json, q: { order_id_eq: order2.id }
get :index, format: :json, q: { order_id_eq: order2.id }
end
it "retrives a list of line items which match the criteria" do
@@ -66,7 +66,7 @@ describe Admin::BulkLineItemsController, type: :controller do
context "when ransack params are passed in for orders" do
before do
spree_get :index, format: :json, q: { order: { completed_at_gt: 2.hours.ago } }
get :index, format: :json, q: { order: { completed_at_gt: 2.hours.ago } }
end
it "retrives a list of line items whose orders match the criteria" do
@@ -90,7 +90,7 @@ describe Admin::BulkLineItemsController, type: :controller do
context "producer enterprise" do
before do
allow(controller).to receive_messages spree_current_user: supplier.owner
spree_get :index, format: :json
get :index, format: :json
end
it "does not display line items for which my enterprise is a supplier" do
@@ -101,7 +101,7 @@ describe Admin::BulkLineItemsController, type: :controller do
context "coordinator enterprise" do
before do
allow(controller).to receive_messages spree_current_user: coordinator.owner
spree_get :index, format: :json
get :index, format: :json
end
it "retrieves a list of line_items" do
@@ -113,7 +113,7 @@ describe Admin::BulkLineItemsController, type: :controller do
context "hub enterprise" do
before do
allow(controller).to receive_messages spree_current_user: distributor1.owner
spree_get :index, format: :json
get :index, format: :json
end
it "retrieves a list of line_items" do
@@ -130,7 +130,7 @@ describe Admin::BulkLineItemsController, type: :controller do
context "with pagination args" do
it "returns paginated results" do
spree_get :index, { page: 1, per_page: 2 }, format: :json
get :index, { page: 1, per_page: 2 }, format: :json
expect(line_item_ids).to eq [line_item1.id, line_item2.id]
expect(json_response['pagination']).to eq(
@@ -139,7 +139,7 @@ describe Admin::BulkLineItemsController, type: :controller do
end
it "returns paginated results for a second page" do
spree_get :index, { page: 2, per_page: 2 }, format: :json
get :index, { page: 2, per_page: 2 }, format: :json
expect(line_item_ids).to eq [line_item3.id, line_item4.id]
expect(json_response['pagination']).to eq(

View File

@@ -17,7 +17,7 @@ module Admin
end
it "returns an empty @collection" do
spree_get :index, format: :html
get :index, format: :html
expect(assigns(:collection)).to eq []
end
end
@@ -34,13 +34,13 @@ module Admin
let(:params) { { format: :json, enterprise_id: enterprise.id } }
it "scopes @collection to customers of that enterprise" do
spree_get :index, params
get :index, params
expect(assigns(:collection)).to eq [customer]
end
it "serializes the data" do
expect(ActiveModel::ArraySerializer).to receive(:new)
spree_get :index, params
get :index, params
end
context 'when the customer_balance feature is enabled' do
@@ -57,13 +57,13 @@ module Admin
expect(customers_with_balance).to receive(:query) { Customer.none }
spree_get :index, params
get :index, params
end
it 'serializes using CustomerWithBalanceSerializer' do
expect(Api::Admin::CustomerWithBalanceSerializer).to receive(:new)
spree_get :index, params
get :index, params
end
end
@@ -75,20 +75,20 @@ module Admin
it 'calls Customer.of' do
expect(Customer).to receive(:of).twice.with(enterprise) { Customer.none }
spree_get :index, params
get :index, params
end
it 'serializes calling the UserBalanceCalculator' do
expect(OpenFoodNetwork::UserBalanceCalculator)
.to receive(:new).with(customer.email, customer.enterprise) { calculator }
spree_get :index, params
get :index, params
end
end
context 'when the customer has no orders' do
it 'includes the customer balance in the response' do
spree_get :index, params
get :index, params
expect(json_response.first["balance"]).to eq("$0.00")
end
end
@@ -103,7 +103,7 @@ module Admin
end
it 'includes the customer balance in the response' do
spree_get :index, params
get :index, params
expect(json_response.first["balance"]).to eq("$-10.00")
end
end
@@ -124,7 +124,7 @@ module Admin
end
it 'includes the customer balance in the response' do
spree_get :index, params
get :index, params
expect(json_response.first["balance"]).to eq("$10.00")
end
end
@@ -134,7 +134,7 @@ module Admin
let!(:line_item) { create(:line_item, order: order, price: 10.0) }
it 'includes the customer balance in the response' do
spree_get :index, params
get :index, params
expect(json_response.first["balance"]).to eq("$0.00")
end
end
@@ -156,7 +156,7 @@ module Admin
it 'includes the customer balance in the response' do
expect(order.payment_total).to eq(0)
spree_get :index, params
get :index, params
expect(json_response.first["balance"]).to eq('$-10.00')
end
end
@@ -164,7 +164,7 @@ module Admin
context "and enterprise_id is not given in params" do
it "returns an empty collection" do
spree_get :index, format: :json
get :index, format: :json
expect(assigns(:collection)).to eq []
end
end
@@ -176,7 +176,7 @@ module Admin
end
it "returns an empty collection" do
spree_get :index, format: :json
get :index, format: :json
expect(assigns(:collection)).to eq []
end
end
@@ -276,7 +276,7 @@ module Admin
end
it "renders the customer as json" do
spree_get :show, format: :json, id: customer.id
get :show, format: :json, id: customer.id
expect(JSON.parse(response.body)["id"]).to eq customer.id
end
end
@@ -287,7 +287,7 @@ module Admin
end
it "prevents me from updating the customer" do
spree_get :show, format: :json, id: customer.id
get :show, format: :json, id: customer.id
expect(response).to redirect_to unauthorized_path
end
end

View File

@@ -457,28 +457,28 @@ describe Admin::EnterprisesController, type: :controller do
end
context "when no order_cycle or coordinator is provided in params" do
before { spree_get :for_order_cycle, format: :json }
before { get :for_order_cycle, format: :json }
it "initializes permissions with nil" do
expect(OpenFoodNetwork::OrderCyclePermissions).to have_received(:new).with(user, nil)
end
end
context "when an order_cycle_id is provided in params" do
before { spree_get :for_order_cycle, format: :json, order_cycle_id: 1 }
before { get :for_order_cycle, format: :json, order_cycle_id: 1 }
it "initializes permissions with the existing OrderCycle" do
expect(OpenFoodNetwork::OrderCyclePermissions).to have_received(:new).with(user, "existing OrderCycle")
end
end
context "when a coordinator is provided in params" do
before { spree_get :for_order_cycle, format: :json, coordinator_id: 1 }
before { get :for_order_cycle, format: :json, coordinator_id: 1 }
it "initializes permissions with a new OrderCycle" do
expect(OpenFoodNetwork::OrderCyclePermissions).to have_received(:new).with(user, "new OrderCycle")
end
end
context "when both an order cycle and a coordinator are provided in params" do
before { spree_get :for_order_cycle, format: :json, order_cycle_id: 1, coordinator_id: 1 }
before { get :for_order_cycle, format: :json, order_cycle_id: 1, coordinator_id: 1 }
it "initializes permissions with the existing OrderCycle" do
expect(OpenFoodNetwork::OrderCyclePermissions).to have_received(:new).with(user, "existing OrderCycle")
end
@@ -500,7 +500,7 @@ describe Admin::EnterprisesController, type: :controller do
it "uses permissions to determine which enterprises are visible and should be rendered" do
expect(controller).to receive(:render_as_json).with([visible_enterprise], ams_prefix: 'basic', spree_current_user: user).and_call_original
spree_get :visible, format: :json
get :visible, format: :json
end
end
@@ -518,14 +518,14 @@ describe Admin::EnterprisesController, type: :controller do
context "html" do
it "returns all enterprises" do
spree_get :index, format: :html
get :index, format: :html
expect(assigns(:collection)).to include enterprise1, enterprise2, enterprise3
end
end
context "json" do
it "returns all enterprises" do
spree_get :index, format: :json
get :index, format: :json
expect(assigns(:collection)).to include enterprise1, enterprise2, enterprise3
end
end
@@ -543,14 +543,14 @@ describe Admin::EnterprisesController, type: :controller do
context "html" do
it "returns an empty @collection" do
spree_get :index, format: :html
get :index, format: :html
expect(assigns(:collection)).to eq []
end
end
context "json" do
it "scopes @collection to enterprises editable by the user" do
spree_get :index, format: :json
get :index, format: :json
expect(assigns(:collection)).to include enterprise1, enterprise2
expect(assigns(:collection)).to_not include enterprise3
end

View File

@@ -20,7 +20,7 @@ module Admin
context "html" do
it "doesn't load any data" do
spree_get :index, format: :html
get :index, format: :html
expect(assigns(:collection)).to be_empty
end
end
@@ -28,7 +28,7 @@ module Admin
context "json" do
context "where ransack conditions are specified" do
it "loads order cycles that closed within the past month, and orders without a close_at date" do
spree_get :index, format: :json
get :index, format: :json
expect(assigns(:collection)).to_not include oc1, oc2
expect(assigns(:collection)).to include oc3, oc4
end
@@ -38,7 +38,7 @@ module Admin
let(:q) { { orders_close_at_gt: 45.days.ago } }
it "loads order cycles that closed after the specified date, and orders without a close_at date" do
spree_get :index, format: :json, q: q
get :index, format: :json, q: q
expect(assigns(:collection)).to_not include oc1
expect(assigns(:collection)).to include oc2, oc3, oc4
end
@@ -47,7 +47,7 @@ module Admin
before { q.merge!(id_not_in: [oc2.id, oc4.id]) }
it "loads order cycles that meet all conditions" do
spree_get :index, format: :json, q: q
get :index, format: :json, q: q
expect(assigns(:collection)).to_not include oc1, oc2, oc4
expect(assigns(:collection)).to include oc3
end
@@ -62,7 +62,7 @@ module Admin
let!(:distributor) { create(:distributor_enterprise, owner: distributor_owner) }
it "renders the new template" do
spree_get :new
get :new
expect(response).to render_template :new
end
end
@@ -73,21 +73,21 @@ module Admin
let!(:distributor3) { create(:distributor_enterprise) }
it "renders the set_coordinator template" do
spree_get :new
get :new
expect(response).to render_template :set_coordinator
end
describe "and a coordinator_id is submitted as part of the request" do
describe "when the user manages the enterprise" do
it "renders the new template" do
spree_get :new, coordinator_id: distributor1.id
get :new, coordinator_id: distributor1.id
expect(response).to render_template :new
end
end
describe "when the user does not manage the enterprise" do
it "renders the set_coordinator template and sets a flash error" do
spree_get :new, coordinator_id: distributor3.id
get :new, coordinator_id: distributor3.id
expect(response).to render_template :set_coordinator
expect(flash[:error]).to eq "You don't have permission to create an order cycle coordinated by that enterprise"
end
@@ -331,7 +331,7 @@ module Admin
describe "when an order cycle is deleteable" do
it "allows the order_cycle to be destroyed" do
spree_get :destroy, id: oc.id
get :destroy, id: oc.id
expect(OrderCycle.find_by(id: oc.id)).to be nil
end
end
@@ -340,7 +340,7 @@ module Admin
let!(:order) { create(:order, order_cycle: oc) }
it "displays an error message when we attempt to delete it" do
spree_get :destroy, id: oc.id
get :destroy, id: oc.id
expect(response).to redirect_to admin_order_cycles_path
expect(flash[:error]).to eq I18n.t('admin.order_cycles.destroy_errors.orders_present')
end
@@ -350,7 +350,7 @@ module Admin
let!(:schedule) { create(:schedule, order_cycles: [oc]) }
it "displays an error message when we attempt to delete it" do
spree_get :destroy, id: oc.id
get :destroy, id: oc.id
expect(response).to redirect_to admin_order_cycles_path
expect(flash[:error]).to eq I18n.t('admin.order_cycles.destroy_errors.schedule_present')
end

View File

@@ -42,7 +42,7 @@ describe Admin::ProxyOrdersController, type: :controller do
context "when cancellation succeeds" do
it 'renders the cancelled proxy_order as json' do
spree_get :cancel, params
get :cancel, params
json_response = JSON.parse(response.body)
expect(json_response['state']).to eq "canceled"
expect(json_response['id']).to eq proxy_order.id
@@ -54,7 +54,7 @@ describe Admin::ProxyOrdersController, type: :controller do
before { order_cycle.update(orders_close_at: 1.day.ago) }
it "shows an error" do
spree_get :cancel, params
get :cancel, params
json_response = JSON.parse(response.body)
expect(json_response['errors']).to eq ['Could not cancel the order']
end
@@ -111,7 +111,7 @@ describe Admin::ProxyOrdersController, type: :controller do
context "when resuming succeeds" do
it 'renders the resumed proxy_order as json' do
spree_get :resume, params
get :resume, params
json_response = JSON.parse(response.body)
expect(json_response['state']).to eq "resumed"
expect(json_response['id']).to eq proxy_order.id
@@ -123,7 +123,7 @@ describe Admin::ProxyOrdersController, type: :controller do
before { order_cycle.update(orders_close_at: 1.day.ago) }
it "shows an error" do
spree_get :resume, params
get :resume, params
json_response = JSON.parse(response.body)
expect(json_response['errors']).to eq ['Could not resume the order']
end

View File

@@ -21,13 +21,13 @@ describe Admin::SchedulesController, type: :controller do
let(:params) { { format: :json } }
it "scopes @collection to schedules containing order_cycles coordinated by enterprises I manage" do
spree_get :index, params
get :index, params
expect(assigns(:collection)).to eq [coordinated_schedule]
end
it "serializes the data" do
expect(ActiveModel::ArraySerializer).to receive(:new)
spree_get :index, params
get :index, params
end
context "and there is a schedule of an OC coordinated by _another_ enterprise I manage and the first enterprise is given" do
@@ -37,7 +37,7 @@ describe Admin::SchedulesController, type: :controller do
let(:params) { { format: :json, enterprise_id: managed_coordinator.id } }
it "scopes @collection to schedules containing order_cycles coordinated by the first enterprise" do
spree_get :index, params
get :index, params
expect(assigns(:collection)).to eq [coordinated_schedule]
end
end
@@ -45,7 +45,7 @@ describe Admin::SchedulesController, type: :controller do
context "where I dont manage an order cycle coordinator" do
it "returns an empty collection" do
spree_get :index, format: :json
get :index, format: :json
expect(assigns(:collection)).to be_nil
end
end

View File

@@ -15,7 +15,7 @@ describe Admin::StripeAccountsController, type: :controller do
end
it "redirects to Stripe Authorization url constructed OAuth" do
spree_get :connect, enterprise_id: 1 # A deterministic id results in a deterministic state JWT token
get :connect, enterprise_id: 1 # A deterministic id results in a deterministic state JWT token
expect(response).to redirect_to("https://connect.stripe.com/oauth/authorize?state=eyJhbGciOiJIUzI1NiJ9.eyJlbnRlcnByaXNlX2lkIjoiMSJ9.jSSFGn0bLhwuiQYK5ORmHWW7aay1l030bcfGwn1JbFg&scope=read_write&client_id=some_id&response_type=code")
end
@@ -98,7 +98,7 @@ describe Admin::StripeAccountsController, type: :controller do
end
it "redirects to unauthorized" do
spree_get :status, params
get :status, params
expect(response).to redirect_to unauthorized_path
end
end
@@ -110,7 +110,7 @@ describe Admin::StripeAccountsController, type: :controller do
context "when Stripe is not enabled" do
it "returns with a status of 'stripe_disabled'" do
spree_get :status, params
get :status, params
json_response = JSON.parse(response.body)
expect(json_response["status"]).to eq "stripe_disabled"
end
@@ -121,7 +121,7 @@ describe Admin::StripeAccountsController, type: :controller do
context "when no stripe account is associated with the specified enterprise" do
it "returns with a status of 'account_missing'" do
spree_get :status, params
get :status, params
json_response = JSON.parse(response.body)
expect(json_response["status"]).to eq "account_missing"
end
@@ -136,7 +136,7 @@ describe Admin::StripeAccountsController, type: :controller do
end
it "returns with a status of 'access_revoked'" do
spree_get :status, params
get :status, params
json_response = JSON.parse(response.body)
expect(json_response["status"]).to eq "access_revoked"
end
@@ -157,7 +157,7 @@ describe Admin::StripeAccountsController, type: :controller do
end
it "returns with a status of 'connected'" do
spree_get :status, params
get :status, params
json_response = JSON.parse(response.body)
expect(json_response["status"]).to eq "connected"
# serializes required attrs

View File

@@ -17,7 +17,7 @@ describe Admin::StripeConnectSettingsController, type: :controller do
before { allow(controller).to receive(:spree_current_user) { user } }
it "does not allow access" do
spree_get :edit
get :edit
expect(response).to redirect_to unauthorized_path
end
end
@@ -34,7 +34,7 @@ describe Admin::StripeConnectSettingsController, type: :controller do
end
it "sets the account status to :empty_api_key_error_html" do
spree_get :edit
get :edit
expect(assigns(:stripe_account)[:status]).to eq :empty_api_key_error_html
expect(assigns(:settings).stripe_connect_enabled).to be true
end
@@ -52,7 +52,7 @@ describe Admin::StripeConnectSettingsController, type: :controller do
end
it "sets the account status to :auth_fail_error" do
spree_get :edit
get :edit
expect(assigns(:stripe_account)[:status]).to eq :auth_fail_error
expect(assigns(:settings).stripe_connect_enabled).to be true
end
@@ -65,7 +65,7 @@ describe Admin::StripeConnectSettingsController, type: :controller do
end
it "sets the account status to :ok, loads settings into Struct" do
spree_get :edit
get :edit
expect(assigns(:stripe_account)[:status]).to eq :ok
expect(assigns(:obfuscated_secret_key)).to eq "sk_test_****xxxx"
expect(assigns(:settings).stripe_connect_enabled).to be true
@@ -82,7 +82,7 @@ describe Admin::StripeConnectSettingsController, type: :controller do
before { allow(controller).to receive(:spree_current_user) { user } }
it "does not allow access" do
spree_get :update, params
get :update, params
expect(response).to redirect_to unauthorized_path
end
end
@@ -95,7 +95,7 @@ describe Admin::StripeConnectSettingsController, type: :controller do
it "sets global config to the specified values" do
expect(Spree::Config.stripe_connect_enabled).to be true
spree_get :update, params
get :update, params
expect(Spree::Config.stripe_connect_enabled).to be false
end
end

View File

@@ -19,7 +19,7 @@ describe Admin::SubscriptionsController, type: :controller do
context 'as a regular user' do
it 'redirects to unauthorized' do
spree_get :index, params
get :index, params
expect(response).to redirect_to unauthorized_path
end
end
@@ -32,7 +32,7 @@ describe Admin::SubscriptionsController, type: :controller do
let!(:subscription) { create(:subscription, shop: shop) }
it 'renders the index page with appropriate data' do
spree_get :index, params
get :index, params
expect(response).to render_template 'index'
expect(assigns(:collection)).to eq [] # No collection loaded
expect(assigns(:shops)).to eq [shop] # Shops are loaded
@@ -41,7 +41,7 @@ describe Admin::SubscriptionsController, type: :controller do
context "where I don't manage a shop that is set up for subscriptions" do
it 'renders the setup_explanation page' do
spree_get :index, params
get :index, params
expect(response).to render_template 'setup_explanation'
expect(assigns(:collection)).to eq [] # No collection loaded
expect(assigns(:shop)).to eq shop # First SO enabled shop is loaded
@@ -56,7 +56,7 @@ describe Admin::SubscriptionsController, type: :controller do
context 'as a regular user' do
it 'redirects to unauthorized' do
spree_get :index, params
get :index, params
expect(response).to redirect_to unauthorized_path
end
end
@@ -67,7 +67,7 @@ describe Admin::SubscriptionsController, type: :controller do
let!(:subscription2) { create(:subscription, shop: shop2) }
it 'renders the collection as json' do
spree_get :index, params
get :index, params
json_response = JSON.parse(response.body)
expect(json_response.count).to be 2
expect(json_response.map{ |so| so['id'] }).to include subscription.id, subscription2.id
@@ -77,7 +77,7 @@ describe Admin::SubscriptionsController, type: :controller do
before { params.merge!(q: { shop_id_eq: shop2.id }) }
it "restricts the list of subscriptions" do
spree_get :index, params
get :index, params
json_response = JSON.parse(response.body)
expect(json_response.count).to be 1
ids = json_response.map{ |so| so['id'] }
@@ -99,7 +99,7 @@ describe Admin::SubscriptionsController, type: :controller do
it 'loads the preloads the necessary data' do
expect(controller).to receive(:load_form_data)
spree_get :new, subscription: { shop_id: shop.id }
get :new, subscription: { shop_id: shop.id }
expect(assigns(:subscription)).to be_a_new Subscription
expect(assigns(:subscription).shop).to eq shop
end
@@ -238,7 +238,7 @@ describe Admin::SubscriptionsController, type: :controller do
it 'loads the preloads the necessary data' do
expect(controller).to receive(:load_form_data)
spree_get :edit, id: subscription.id
get :edit, id: subscription.id
expect(assigns(:subscription)).to eq subscription
end
end

View File

@@ -19,7 +19,7 @@ module Api
end
it "lists customers associated with the current user" do
spree_get :index
get :index
expect(response.status).to eq 200
expect(json_response.length).to eq 1
expect(json_response.first[:id]).to eq customer1.id

View File

@@ -26,7 +26,7 @@ module Api
let(:products_relation) { Spree::Product.where("1=0") }
it "handles it gracefully" do
spree_get :index, exchange_id: exchange.id
get :index, exchange_id: exchange.id
expect(json_response["products"].length).to eq 0
end
end
@@ -36,7 +36,7 @@ module Api
describe "when an exchange id param is provided" do
it "uses exchange order_cycle, incoming and enterprise to fetch products" do
spree_get :index, exchange_id: exchange.id, order_cycle_id: 666, enterprise_id: 666, incoming: false
get :index, exchange_id: exchange.id, order_cycle_id: 666, enterprise_id: 666, incoming: false
expect(json_response["products"].first["supplier_name"]).to eq exchange.variants.first.product.supplier.name
end
end
@@ -59,7 +59,7 @@ module Api
describe "when a specific page is requested" do
it "returns the requested page with paginated data" do
spree_get :index, exchange_id: exchange.id, page: 1
get :index, exchange_id: exchange.id, page: 1
expect(json_response["products"].size).to eq 1
expect(json_response["pagination"]["results"]).to eq 2
@@ -69,7 +69,7 @@ module Api
describe "when no specific page is requested" do
it "returns all results without paginating" do
spree_get :index, exchange_id: exchange.id
get :index, exchange_id: exchange.id
expect(json_response["products"].size).to eq 2
expect(json_response["pagination"]).to be nil

View File

@@ -23,7 +23,7 @@ describe Api::ShopsController, type: :controller do
describe "#show" do
it "returns shopfront data for an enterprise" do
spree_get :show, id: producer.id
get :show, id: producer.id
expect(json_response['name']).to eq 'Shopfront Test Producer'
expect(json_response['hubs'][0]['name']).to eq 'Shopfront Test Hub'
@@ -33,7 +33,7 @@ describe Api::ShopsController, type: :controller do
describe "#closed_shops" do
it "returns data for all closed shops" do
spree_get :closed_shops, {}
get :closed_shops, {}
expect(json_response).not_to match hub.name

View File

@@ -9,21 +9,21 @@ module Api
describe "job queue status" do
it "returns alive when up to date" do
Spree::Config.last_job_queue_heartbeat_at = Time.now.in_time_zone
spree_get :job_queue
get :job_queue
expect(response).to be_success
expect(response.body).to eq({ alive: true }.to_json)
end
it "returns dead otherwise" do
Spree::Config.last_job_queue_heartbeat_at = 10.minutes.ago
spree_get :job_queue
get :job_queue
expect(response).to be_success
expect(response.body).to eq({ alive: false }.to_json)
end
it "returns dead when no heartbeat recorded" do
Spree::Config.last_job_queue_heartbeat_at = nil
spree_get :job_queue
get :job_queue
expect(response).to be_success
expect(response.body).to eq({ alive: false }.to_json)
end

View File

@@ -26,7 +26,7 @@ describe Api::VariantsController, type: :controller do
end
it "retrieves a list of variants with appropriate attributes" do
spree_get :index, format: :json
get :index, format: :json
keys = json_response.first.keys.map(&:to_sym)
expect(attributes.all?{ |attr| keys.include? attr }).to eq(true)

View File

@@ -101,7 +101,7 @@ describe BaseController, type: :controller do
end
it "redirects to home with message if order cycle is expired" do
expect(controller).to receive(:current_order_cycle).and_return(oc).twice
expect(controller).to receive(:current_order_cycle).and_return(oc)
expect(controller).to receive(:current_order).and_return(order).twice
expect(oc).to receive(:closed?).and_return(true)
expect(order).to receive(:empty!)
@@ -109,7 +109,6 @@ describe BaseController, type: :controller do
get :index
expect(session[:expired_order_cycle_id]).to eq oc.id
expect(response).to redirect_to root_url
expect(flash[:info]).to eq I18n.t('order_cycle_closed')
end

View File

@@ -82,7 +82,7 @@ describe CheckoutController, concurrency: true, type: :controller do
# see the order page. This is basically verifying a "double click"
# scenario.
expect(response.status).to eq(200)
expect(response.body).to eq({ path: spree.order_path(order) }.to_json)
expect(response.body).to eq({ path: order_path(order) }.to_json)
expect(order.payments.count).to eq 1
expect(order.completed?).to be true
end

View File

@@ -110,7 +110,7 @@ describe CheckoutController, type: :controller do
it "completes the order and redirects to the order confirmation page" do
get :edit, { payment_intent: "pi_123" }
expect(order.completed?).to be true
expect(response).to redirect_to spree.order_path(order)
expect(response).to redirect_to order_path(order)
end
end
end
@@ -242,7 +242,7 @@ describe CheckoutController, type: :controller do
spree_post :update, format: :json, order: {}
expect(response.status).to eq(200)
expect(response.body).to eq({ path: spree.order_path(order) }.to_json)
expect(response.body).to eq({ path: order_path(order) }.to_json)
end
it "returns an error on unexpected failure" do

View File

@@ -18,7 +18,7 @@ describe EnterprisesController, type: :controller do
end
it "sets the shop as the distributor on the order when shopping for the distributor" do
spree_get :shop, id: distributor
get :shop, id: distributor
expect(controller.current_distributor).to eq(distributor)
expect(controller.current_order.distributor).to eq(distributor)
@@ -29,7 +29,7 @@ describe EnterprisesController, type: :controller do
before { allow(controller).to receive(:spree_current_user) { user } }
it "sets the shop as the distributor on the order when shopping for the distributor" do
spree_get :shop, id: distributor
get :shop, id: distributor
expect(controller.current_distributor).to eq(distributor)
expect(controller.current_order.distributor).to eq(distributor)
@@ -39,11 +39,11 @@ describe EnterprisesController, type: :controller do
it "sorts order cycles by the distributor's preferred ordering attr" do
distributor.update_attribute(:preferred_shopfront_order_cycle_order, 'orders_close_at')
spree_get :shop, id: distributor
get :shop, id: distributor
expect(assigns(:order_cycles)).to eq([order_cycle1, order_cycle2].sort_by(&:orders_close_at))
distributor.update_attribute(:preferred_shopfront_order_cycle_order, 'orders_open_at')
spree_get :shop, id: distributor
get :shop, id: distributor
expect(assigns(:order_cycles)).to eq([order_cycle1, order_cycle2].sort_by(&:orders_open_at))
end
@@ -64,23 +64,23 @@ describe EnterprisesController, type: :controller do
preferred_exchange_tags: "wholesale",
preferred_matched_order_cycles_visibility: 'hidden')
spree_get :shop, id: distributor
get :shop, id: distributor
expect(assigns(:order_cycles)).to include order_cycle1, order_cycle2, order_cycle3
allow(controller).to receive(:spree_current_user) { user }
spree_get :shop, id: distributor
get :shop, id: distributor
expect(assigns(:order_cycles)).to include order_cycle1, order_cycle2, order_cycle3
oc3_exchange.update_attribute(:tag_list, "wholesale")
spree_get :shop, id: distributor
get :shop, id: distributor
expect(assigns(:order_cycles)).to include order_cycle1, order_cycle2
expect(assigns(:order_cycles)).not_to include order_cycle3
customer.update_attribute(:tag_list, ["wholesale"])
spree_get :shop, id: distributor
get :shop, id: distributor
expect(assigns(:order_cycles)).to include order_cycle1, order_cycle2, order_cycle3
end
end
@@ -89,7 +89,7 @@ describe EnterprisesController, type: :controller do
line_item = create(:line_item)
controller.current_order.line_items << line_item
spree_get :shop, id: distributor
get :shop, id: distributor
expect(controller.current_order.distributor).to eq(distributor)
expect(controller.current_order.order_cycle).to be_nil
@@ -97,7 +97,7 @@ describe EnterprisesController, type: :controller do
end
it "should not empty an order if returning to the same distributor" do
spree_get :shop, id: current_distributor
get :shop, id: current_distributor
expect(controller.current_order.distributor).to eq current_distributor
expect(controller.current_order.line_items.first.variant).to eq line_item.variant
@@ -117,7 +117,7 @@ describe EnterprisesController, type: :controller do
end
it "redirects to the cart" do
spree_get :shop, id: current_distributor
get :shop, id: current_distributor
expect(response).to redirect_to cart_path
end
@@ -129,7 +129,7 @@ describe EnterprisesController, type: :controller do
order.save
order_cycle1.update_attribute :orders_close_at, Time.zone.now
spree_get :shop, id: distributor
get :shop, id: distributor
expect(controller.current_order.distributor).to eq(distributor)
expect(controller.current_order.order_cycle).to eq(order_cycle2)
@@ -139,7 +139,7 @@ describe EnterprisesController, type: :controller do
it "sets order cycle if only one is available at the chosen distributor" do
order_cycle2.destroy
spree_get :shop, id: distributor
get :shop, id: distributor
expect(controller.current_order.distributor).to eq(distributor)
expect(controller.current_order.order_cycle).to eq(order_cycle1)
@@ -155,7 +155,7 @@ describe EnterprisesController, type: :controller do
end
it "responds with status of 409 when the permalink matches an existing route" do
# spree_get :check_permalink, { permalink: 'enterprise_permalink', format: :js }
# get :check_permalink, { permalink: 'enterprise_permalink', format: :js }
# expect(response.status).to be 409
xhr :get, :check_permalink, permalink: 'map', format: :js
expect(response.status).to be 409
@@ -166,7 +166,7 @@ describe EnterprisesController, type: :controller do
context "checking access on nonexistent enterprise" do
before do
spree_get :shop, id: "some_nonexistent_enterprise"
get :shop, id: "some_nonexistent_enterprise"
end
it "redirects to shops_path" do

View File

@@ -8,7 +8,7 @@ describe ShopController, type: :controller do
let(:distributor) { create(:distributor_enterprise, payment_methods: [pm], shipping_methods: [sm]) }
it "redirects to the home page if no distributor is selected" do
spree_get :show
get :show
expect(response).to redirect_to root_path
end
@@ -20,14 +20,14 @@ describe ShopController, type: :controller do
describe "selecting an order cycle" do
it "should select an order cycle when only one order cycle is open" do
oc1 = create(:simple_order_cycle, distributors: [distributor])
spree_get :show
get :show
expect(controller.current_order_cycle).to eq(oc1)
end
it "should not set an order cycle when multiple order cycles are open" do
oc1 = create(:simple_order_cycle, distributors: [distributor])
oc2 = create(:simple_order_cycle, distributors: [distributor])
spree_get :show
get :show
expect(controller.current_order_cycle).to be_nil
end
@@ -55,7 +55,7 @@ describe ShopController, type: :controller do
it "should return the current order cycle when hit with GET" do
oc1 = create(:simple_order_cycle, distributors: [distributor])
allow(controller).to receive(:current_order_cycle).and_return oc1
spree_get :order_cycle
get :order_cycle
expect(response.body).to have_content oc1.id
end

View File

@@ -10,7 +10,7 @@ describe Spree::Admin::MailMethodsController do
context "#update" do
it "should reinitialize the mail settings" do
expect(Spree::Core::MailSettings).to receive(:init)
spree_put :update, enable_mail_delivery: "1", mails_from: "ofn@example.com"
spree_put :update, mails_from: "ofn@example.com"
end
end
@@ -24,7 +24,6 @@ describe Spree::Admin::MailMethodsController do
has_spree_role?: true,
locale: nil)
allow(controller).to receive_messages(spree_current_user: user)
Spree::Config[:enable_mail_delivery] = "1"
ActionMailer::Base.perform_deliveries = true
expect {

View File

@@ -22,12 +22,12 @@ describe Spree::OrdersController, type: :controller do
let(:current_user) { nil }
it "loads page" do
spree_get :show, id: order.number, token: order.token
get :show, id: order.number, token: order.token
expect(response).to be_success
end
it "stores order token in session as 'access_token'" do
spree_get :show, id: order.number, token: order.token
get :show, id: order.number, token: order.token
expect(session[:access_token]).to eq(order.token)
end
end
@@ -41,7 +41,7 @@ describe Spree::OrdersController, type: :controller do
end
it "loads page" do
spree_get :show, id: order.number
get :show, id: order.number
expect(response).to be_success
end
end
@@ -50,7 +50,7 @@ describe Spree::OrdersController, type: :controller do
let(:current_user) { order.user }
it "loads page" do
spree_get :show, id: order.number
get :show, id: order.number
expect(response).to be_success
end
end
@@ -59,7 +59,7 @@ describe Spree::OrdersController, type: :controller do
let(:current_user) { create(:user) }
it "redirects to unauthorized" do
spree_get :show, id: order.number
get :show, id: order.number
expect(response).to redirect_to unauthorized_path
end
end
@@ -68,12 +68,12 @@ describe Spree::OrdersController, type: :controller do
let(:current_user) { nil }
before do
request.env["PATH_INFO"] = spree.order_path(order)
request.env["PATH_INFO"] = order_path(order)
end
it "redirects to unauthorized" do
spree_get :show, id: order.number
expect(response).to redirect_to(root_path(anchor: "login?after_login=#{spree.order_path(order)}"))
get :show, id: order.number
expect(response).to redirect_to(root_path(anchor: "login?after_login=#{order_path(order)}"))
expect(flash[:error]).to eq("Please log in to view your order.")
end
end
@@ -81,7 +81,7 @@ describe Spree::OrdersController, type: :controller do
describe "viewing cart" do
it "redirects home when no distributor is selected" do
spree_get :edit
get :edit
expect(response).to redirect_to root_path
end
@@ -95,13 +95,13 @@ describe Spree::OrdersController, type: :controller do
allow(order_cycle).to receive(:variants_distributed_by).and_return []
session[:access_token] = order.token
spree_get :edit
get :edit
expect(response).to redirect_to shop_path
end
it "redirects to the shop when no order cycle is selected" do
allow(controller).to receive(:current_distributor).and_return(distributor)
spree_get :edit
get :edit
expect(response).to redirect_to shop_path
end
@@ -115,7 +115,7 @@ describe Spree::OrdersController, type: :controller do
expect(order).to receive(:empty!)
expect(order).to receive(:set_distribution!).with(nil, nil)
spree_get :edit
get :edit
expect(response).to redirect_to root_url
expect(flash[:info]).to eq(I18n.t('order_cycles_closed_for_hub'))
@@ -144,7 +144,7 @@ describe Spree::OrdersController, type: :controller do
# We fixed our view by hardcoding the link.
spree_registration_path = '/signup'
ofn_registration_path = '/register'
spree_get :edit
get :edit
expect(response.body).to_not match spree_registration_path
expect(response.body).to match ofn_registration_path
end
@@ -156,7 +156,7 @@ describe Spree::OrdersController, type: :controller do
end
it "displays a flash message when we view the cart" do
spree_get :edit
get :edit
expect(response.status).to eq 200
expect(flash[:error]).to eq I18n.t('spree.orders.error_flash_for_unavailable_items')
end
@@ -168,7 +168,7 @@ describe Spree::OrdersController, type: :controller do
end
it "displays a flash message when we view the cart" do
spree_get :edit
get :edit
expect(response.status).to eq 200
expect(flash[:error]).to eq I18n.t('spree.orders.error_flash_for_unavailable_items')
end
@@ -181,7 +181,7 @@ describe Spree::OrdersController, type: :controller do
it "should silently ignore the missing line item" do
order = subject.current_order(true)
li = order.add_variant(create(:simple_product, on_hand: 110).variants.first)
spree_get :update, order: { line_items_attributes: {
get :update, order: { line_items_attributes: {
"0" => { quantity: "0", id: "9999" },
"1" => { quantity: "99", id: li.id }
} }
@@ -209,7 +209,7 @@ describe Spree::OrdersController, type: :controller do
line_item = order.add_variant(create(:simple_product, on_hand: 110).variants.first)
adjustment = create(:adjustment, adjustable: order)
spree_get :update, order: { line_items_attributes: {
get :update, order: { line_items_attributes: {
"1" => { quantity: "99", id: line_item.id }
} }
@@ -318,7 +318,7 @@ describe Spree::OrdersController, type: :controller do
it "removes the items" do
spree_post :update, params
expect(flash[:error]).to be nil
expect(response).to redirect_to spree.order_path(order)
expect(response).to redirect_to order_path(order)
expect(order.reload.line_items.count).to eq 1
end
end
@@ -329,7 +329,7 @@ describe Spree::OrdersController, type: :controller do
it "does not remove items, flash suggests cancellation" do
spree_post :update, params
expect(flash[:error]).to eq I18n.t(:orders_cannot_remove_the_final_item)
expect(response).to redirect_to spree.order_path(order)
expect(response).to redirect_to order_path(order)
expect(order.reload.line_items.count).to eq 2
end
end
@@ -426,7 +426,7 @@ describe Spree::OrdersController, type: :controller do
context "when the order is not yet complete" do
it "responds with forbidden" do
spree_put :cancel, params
expect(response.status).to redirect_to spree.order_path(order)
expect(response.status).to redirect_to order_path(order)
expect(flash[:error]).to eq I18n.t(:orders_could_not_cancel)
end
end
@@ -440,7 +440,7 @@ describe Spree::OrdersController, type: :controller do
it "responds with success" do
spree_put :cancel, params
expect(response.status).to redirect_to spree.order_path(order)
expect(response.status).to redirect_to order_path(order)
expect(flash[:success]).to eq I18n.t(:orders_your_order_has_been_cancelled)
end
end

View File

@@ -40,6 +40,22 @@ describe Spree::UsersController, type: :controller do
# Doesn't return uncompleted orders" do
expect(orders).not_to include d1o3
end
context 'when the customer_balance feature is enabled' do
let(:outstanding_balance) { double(:outstanding_balance) }
before do
allow(OpenFoodNetwork::FeatureToggle)
.to receive(:enabled?).with(:customer_balance, controller.spree_current_user) { true }
end
it 'calls OutstandingBalance' do
allow(OutstandingBalance).to receive(:new).and_return(outstanding_balance)
expect(outstanding_balance).to receive(:query) { Spree::Order.none }
spree_get :show
end
end
end
describe "registered_email" do

View File

@@ -157,26 +157,35 @@ feature 'shipping methods' do
expect(page).to have_selector 'td', text: 'Two', count: 1
end
pending "shows me only shipping methods for the enterprise I select" do
it "shows me only shipping methods for the enterprise I select" do
shipping_method1
shipping_method2
visit admin_enterprises_path
within("#e_#{distributor1.id}") { click_link 'Settings' }
within(".side_menu") do
click_link "Shipping Methods"
end
expect(page).to have_content shipping_method1.name
expect(page).to have_content shipping_method2.name
expect(page).to have_content shipping_method1.name
expect(page).to have_content shipping_method2.name
expect(page).to have_checked_field "enterprise_shipping_method_ids_#{shipping_method2.id}"
expect(page).to have_checked_field "enterprise_shipping_method_ids_#{shipping_method1.id}"
click_link 'Enterprises'
within("#e_#{distributor2.id}") { click_link 'Settings' }
within(".side_menu") do
click_link "Shipping Methods"
end
expect(page).not_to have_content shipping_method1.name
expect(page).to have_content shipping_method1.name
expect(page).to have_content shipping_method2.name
expect(page).to have_checked_field "enterprise_shipping_method_ids_#{shipping_method2.id}"
expect(page).to have_unchecked_field "enterprise_shipping_method_ids_#{shipping_method1.id}"
end
end
end

View File

@@ -39,7 +39,7 @@ feature "Credit Cards", js: true do
it "passes the smoke test" do
visit "/account"
click_link I18n.t('spree.users.show.tabs.cards')
find("a", :text => %r{#{I18n.t('spree.users.show.tabs.cards')}}i).click
expect(page).to have_content I18n.t(:saved_cards)

View File

@@ -18,7 +18,7 @@ feature "Account Settings", js: true do
setup_email
login_as user
visit "/account"
click_link I18n.t('spree.users.show.tabs.settings')
find("a", :text => %r{#{I18n.t('spree.users.show.tabs.settings')}}i).click
expect(page).to have_content I18n.t('spree.users.form.account_settings')
end
@@ -37,7 +37,7 @@ feature "Account Settings", js: true do
user.reload
expect(user.email).to eq 'old@email.com'
expect(user.unconfirmed_email).to eq 'new@email.com'
click_link I18n.t('spree.users.show.tabs.settings')
find("a", :text => %r{#{I18n.t('spree.users.show.tabs.settings')}}i).click
expect(page).to have_content I18n.t('spree.users.show.unconfirmed_email',
unconfirmed_email: 'new@email.com')
end

View File

@@ -54,7 +54,7 @@ feature '
href: "#{distributor_credit.permalink}/shop", count: 1)
# Viewing transaction history
click_link I18n.t('spree.users.show.tabs.transactions')
find("a", :text => %r{#{I18n.t('spree.users.show.tabs.transactions')}}i).click
# It shows all hubs that have been ordered from with balance or credit
expect(page).to have_content distributor1.name
@@ -85,12 +85,12 @@ feature '
visit '/account'
expect(page).to have_content I18n.t('spree.users.orders.open_orders')
expect(page).to have_link d1o1.number, href: spree.order_path(d1o1)
expect(page).to have_link d1o2.number, href: spree.order_path(d1o2)
expect(page).to have_link d1o1.number, href: order_path(d1o1)
expect(page).to have_link d1o2.number, href: order_path(d1o2)
expect(page).to have_link(distributor1.name,
href: "#{distributor1.permalink}/shop", count: 2)
expect(page).to have_link I18n.t('spree.users.open_orders.cancel'), href: spree.cancel_order_path(d1o1)
expect(page).to have_link I18n.t('spree.users.open_orders.cancel'), href: spree.cancel_order_path(d1o2)
expect(page).to have_link I18n.t('spree.users.open_orders.cancel'), href: cancel_order_path(d1o1)
expect(page).to have_link I18n.t('spree.users.open_orders.cancel'), href: cancel_order_path(d1o2)
end
end
end

View File

@@ -44,16 +44,16 @@ feature "Order Management", js: true do
it "allows the user to see the details" do
# Cannot load the page without token
visit spree.order_path(order)
visit order_path(order)
expect(page).to_not be_confirmed_order_page
# Can load the page with token
visit spree.order_path(order, token: order.token)
visit order_path(order, token: order.token)
expect(page).to be_confirmed_order_page
# Can load the page even without the token, after loading the page with
# token.
visit spree.order_path(order)
visit order_path(order)
expect(page).to be_confirmed_order_page
end
end
@@ -66,7 +66,7 @@ feature "Order Management", js: true do
end
it "allows the user to see order details" do
visit spree.order_path(order)
visit order_path(order)
expect(page).to be_confirmed_order_page
end
end
@@ -76,7 +76,7 @@ feature "Order Management", js: true do
it "allows the user to see order details after login" do
# Cannot load the page without signing in
visit spree.order_path(order)
visit order_path(order)
expect(page).to_not be_confirmed_order_page
# Can load the page after signing in
@@ -115,7 +115,7 @@ feature "Order Management", js: true do
end
it 'shows the name of the shipping method' do
visit spree.order_path(order)
visit order_path(order)
expect(find('#order')).to have_content(shipping_method.name)
end
@@ -125,7 +125,7 @@ feature "Order Management", js: true do
end
it "doesn't show form elements for editing the order" do
visit spree.order_path(order)
visit order_path(order)
expect(find("tr.variant-#{item1.variant.id}")).to have_content item1.product.name
expect(find("tr.variant-#{item2.variant.id}")).to have_content item2.product.name
expect(find("tr.variant-#{item3.variant.id}")).to have_content item3.product.name
@@ -142,7 +142,7 @@ feature "Order Management", js: true do
end
it "allows quantity to be changed, items to be removed and the order to be cancelled" do
visit spree.order_path(order)
visit order_path(order)
expect(page).to have_button I18n.t(:order_saved), disabled: true
expect(page).to have_no_button I18n.t(:save_changes)

View File

@@ -4,20 +4,23 @@ describe "ShopVariantCtrl", ->
beforeEach ->
module 'Darkswarm'
scope =
$watchGroup: ->
variant: {
inject ($rootScope, $controller, $modal)->
scope = $rootScope.$new()
scope.$watchGroup = ->
scope.variant = {
on_demand: true
product: {group_buy: false}
product: {group_buy: true}
line_item: {
quantity: 0
max_quantity: 0
quantity: undefined
max_quantity: undefined
}
}
inject ($controller, $modal)->
ctrl = $controller 'ShopVariantCtrl', {$scope: scope, $modal: $modal, Cart: null}
it "initializes the quantity for shop display", ->
expect(scope.variant.line_item.quantity).toEqual 0
it "adds an item to the cart", ->
scope.add 1
expect(scope.variant.line_item.quantity).toEqual 1
@@ -27,30 +30,60 @@ describe "ShopVariantCtrl", ->
scope.add 5
expect(scope.variant.line_item.quantity).toEqual 6
it "adds to an invalid quantity", ->
scope.$apply ->
scope.variant.line_item.quantity = -5
scope.add 1
expect(scope.variant.line_item.quantity).toEqual 1
it "adds to an undefined quantity", ->
scope.$apply ->
scope.variant.line_item.quantity = undefined
scope.add 1
expect(scope.variant.line_item.quantity).toEqual 1
it "adds to the max quantity", ->
scope.addMax 5
expect(scope.variant.line_item.quantity).toEqual 0
expect(scope.variant.line_item.max_quantity).toEqual 5
it "adds to the max quantity to be at least min quantity", ->
scope.variant.product.group_buy = true
scope.variant.line_item.max_quantity = 2
it "adds to an undefined max quantity", ->
scope.variant.line_item.quantity = 3
scope.variant.line_item.max_quantity = undefined
scope.addMax 1
expect(scope.variant.line_item.max_quantity).toEqual 4
scope.add 3
it "adds to the max quantity to be at least min quantity", ->
scope.$apply ->
scope.variant.line_item.max_quantity = 2
scope.$apply ->
scope.add 3
expect(scope.variant.line_item.quantity).toEqual 3
expect(scope.variant.line_item.max_quantity).toEqual 3
it "decreases the min quantity to not exceed max quantity", ->
scope.variant.product.group_buy = true
scope.variant.line_item.quantity = 3
scope.variant.line_item.max_quantity = 5
scope.$apply ->
scope.variant.line_item.quantity = 3
scope.variant.line_item.max_quantity = 5
scope.addMax -3
scope.$apply ->
scope.addMax -3
expect(scope.variant.line_item.quantity).toEqual 2
expect(scope.variant.line_item.max_quantity).toEqual 2
it "caps at the available quantity", ->
scope.$apply ->
scope.variant.on_demand = false
scope.variant.on_hand = 3
scope.variant.line_item.quantity = 5
scope.variant.line_item.max_quantity = 7
expect(scope.variant.line_item.quantity).toEqual 3
expect(scope.variant.line_item.max_quantity).toEqual 3
it "allows adding when variant is on demand", ->
expect(scope.canAdd(5000)).toEqual true
@@ -72,6 +105,42 @@ describe "ShopVariantCtrl", ->
expect(scope.canAdd(2)).toEqual true
expect(scope.canAdd(3)).toEqual false
it "denies adding if quantity is too high", ->
scope.variant.on_demand = false
scope.variant.on_hand = 5
scope.variant.line_item.quantity = 7
scope.variant.line_item.max_quantity = 7
expect(scope.canAdd(1)).toEqual false
expect(scope.canAddMax(1)).toEqual false
it "allows decrease when quantity is too high", ->
scope.variant.on_demand = false
scope.variant.on_hand = 5
scope.variant.line_item.quantity = 7
scope.variant.line_item.max_quantity = 7
expect(scope.canAdd(-1)).toEqual true
expect(scope.canAddMax(-1)).toEqual true
it "allows increase when quantity is negative", ->
scope.variant.on_demand = false
scope.variant.on_hand = 5
scope.variant.line_item.quantity = -3
scope.variant.line_item.max_quantity = -3
expect(scope.canAdd(1)).toEqual true
expect(scope.canAddMax(1)).toEqual false
scope.variant.line_item.quantity = 1
expect(scope.canAddMax(1)).toEqual true
it "denies decrease when quantity is negative", ->
scope.variant.on_demand = false
scope.variant.on_hand = 5
scope.variant.line_item.quantity = -3
scope.variant.line_item.max_quantity = -3
expect(scope.canAdd(-1)).toEqual false
expect(scope.canAddMax(-1)).toEqual false
it "denies declaring max quantity before item is in cart", ->
expect(scope.canAddMax(1)).toEqual false

View File

@@ -7,60 +7,47 @@ module Spree
describe MailSettings do
let!(:subject) { MailSettings.new }
context "enable delivery" do
before { Config.enable_mail_delivery = true }
context "overrides appplication defaults" do
context "authentication method is none" do
before do
Config.mail_host = "smtp.example.com"
Config.mail_domain = "example.com"
Config.mail_port = 123
Config.mail_auth_type = MailSettings::SECURE_CONNECTION_TYPES[0]
Config.smtp_username = "schof"
Config.smtp_password = "hellospree!"
Config.secure_connection_type = "TLS"
subject.override!
end
it { expect(ActionMailer::Base.smtp_settings[:address]).to eq "smtp.example.com" }
it { expect(ActionMailer::Base.smtp_settings[:domain]).to eq "example.com" }
it { expect(ActionMailer::Base.smtp_settings[:port]).to eq 123 }
it { expect(ActionMailer::Base.smtp_settings[:authentication]).to eq "None" }
it { expect(ActionMailer::Base.smtp_settings[:enable_starttls_auto]).to be_truthy }
it "doesnt touch user name config" do
expect(ActionMailer::Base.smtp_settings[:user_name]).to be_nil
end
it "doesnt touch password config" do
expect(ActionMailer::Base.smtp_settings[:password]).to be_nil
end
end
end
context "when mail_auth_type is other than none" do
context "overrides appplication defaults" do
context "authentication method is none" do
before do
Config.mail_auth_type = "login"
Config.mail_host = "smtp.example.com"
Config.mail_domain = "example.com"
Config.mail_port = 123
Config.mail_auth_type = MailSettings::SECURE_CONNECTION_TYPES[0]
Config.smtp_username = "schof"
Config.smtp_password = "hellospree!"
Config.secure_connection_type = "TLS"
subject.override!
end
context "overrides user credentials" do
it { expect(ActionMailer::Base.smtp_settings[:user_name]).to eq "schof" }
it { expect(ActionMailer::Base.smtp_settings[:password]).to eq "hellospree!" }
it { expect(ActionMailer::Base.smtp_settings[:address]).to eq "smtp.example.com" }
it { expect(ActionMailer::Base.smtp_settings[:domain]).to eq "example.com" }
it { expect(ActionMailer::Base.smtp_settings[:port]).to eq 123 }
it { expect(ActionMailer::Base.smtp_settings[:authentication]).to eq "None" }
it { expect(ActionMailer::Base.smtp_settings[:enable_starttls_auto]).to be_truthy }
it "doesnt touch user name config" do
expect(ActionMailer::Base.smtp_settings[:user_name]).to be_nil
end
it "doesnt touch password config" do
expect(ActionMailer::Base.smtp_settings[:password]).to be_nil
end
end
end
context "do not enable delivery" do
context "when mail_auth_type is other than none" do
before do
Config.enable_mail_delivery = false
Config.mail_auth_type = "login"
Config.smtp_username = "schof"
Config.smtp_password = "hellospree!"
subject.override!
end
it { expect(ActionMailer::Base.perform_deliveries).to be_falsy }
context "overrides user credentials" do
it { expect(ActionMailer::Base.smtp_settings[:user_name]).to eq "schof" }
it { expect(ActionMailer::Base.smtp_settings[:password]).to eq "hellospree!" }
end
end
end
end

View File

@@ -47,7 +47,7 @@ describe SubscriptionMailer, type: :mailer do
end
describe "linking to order page" do
let(:order_link_href) { "href=\"#{spree.order_url(order)}\"" }
let(:order_link_href) { "href=\"#{order_url(order)}\"" }
let(:order_link_style) { "style='[^']+'" }
let(:shop) { create(:enterprise, allow_order_changes: true) }
@@ -113,7 +113,7 @@ describe SubscriptionMailer, type: :mailer do
end
describe "linking to order page" do
let(:order_link_href) { "href=\"#{spree.order_url(order)}\"" }
let(:order_link_href) { "href=\"#{order_url(order)}\"" }
let(:email) { SubscriptionMailer.deliveries.last }
let(:body) { email.body.encoded }
@@ -179,7 +179,7 @@ describe SubscriptionMailer, type: :mailer do
end
describe "linking to order page" do
let(:order_link_href) { "href=\"#{spree.order_url(order)}\"" }
let(:order_link_href) { "href=\"#{order_url(order)}\"" }
let(:email) { SubscriptionMailer.deliveries.last }
let(:body) { email.body.encoded }

View File

@@ -221,7 +221,7 @@ module Spree
end
it "does not crash when order data has been updated previously" do
order.price_adjustments.first.destroy
order.line_item_adjustments.first.destroy
tax_rate.adjust(order)
end
end

View File

@@ -0,0 +1,61 @@
# frozen_string_literal: true
require 'spec_helper'
describe CompleteOrdersWithBalance do
let(:complete_orders_with_balance) { described_class.new(user) }
describe '#query' do
let(:user) { order.user }
let(:outstanding_balance) { instance_double(OutstandingBalance) }
context 'when the user has complete orders' do
let(:order) do
create(:order, state: 'complete', total: 2.0, payment_total: 1.0, completed_at: 2.day.ago)
end
let!(:other_order) do
create(
:order,
user: user,
state: 'complete',
total: 2.0,
payment_total: 1.0,
completed_at: 1.days.ago
)
end
it 'calls OutstandingBalance#query' do
allow(OutstandingBalance).to receive(:new).and_return(outstanding_balance)
expect(outstanding_balance).to receive(:query)
complete_orders_with_balance.query
end
it 'returns complete orders including their balance' do
order = complete_orders_with_balance.query.first
expect(order[:balance_value]).to eq(-1.0)
end
it 'sorts them by their completed_at with the most recent first' do
orders = complete_orders_with_balance.query
expect(orders.pluck(:id)).to eq([other_order.id, order.id])
end
end
context 'when the user has no complete orders' do
let(:order) { create(:order) }
it 'calls OutstandingBalance' do
allow(OutstandingBalance).to receive(:new).and_return(outstanding_balance)
expect(outstanding_balance).to receive(:query)
complete_orders_with_balance.query
end
it 'returns an empty array' do
order = complete_orders_with_balance.query
expect(order).to be_empty
end
end
end
end

View File

@@ -9,6 +9,14 @@ describe CustomersWithBalance do
let(:customer) { create(:customer) }
let(:total) { 200.00 }
let(:order_total) { 100.00 }
let(:outstanding_balance) { instance_double(OutstandingBalance) }
it 'calls CustomersWithBalance#statement' do
allow(OutstandingBalance).to receive(:new).and_return(outstanding_balance)
expect(outstanding_balance).to receive(:statement)
customers_with_balance.query
end
context 'when orders are in cart state' do
before do
@@ -61,9 +69,9 @@ describe CustomersWithBalance do
context 'when no orders where paid' do
before do
order = create(:order, customer: customer, total: order_total, payment_total: 0)
order.update_attribute(:state, 'checkout')
order.update_attribute(:state, 'complete')
order = create(:order, customer: customer, total: order_total, payment_total: 0)
order.update_attribute(:state, 'checkout')
order.update_attribute(:state, 'complete')
end
it 'returns the customer balance' do
@@ -77,9 +85,9 @@ describe CustomersWithBalance do
before do
order = create(:order, customer: customer, total: order_total, payment_total: 0)
order.update_attribute(:state, 'checkout')
order.update_attribute(:state, 'complete')
order = create(:order, customer: customer, total: order_total, payment_total: payment_total)
order.update_attribute(:state, 'checkout')
order.update_attribute(:state, 'complete')
end
it 'returns the customer balance' do
@@ -94,7 +102,7 @@ describe CustomersWithBalance do
before do
order = create(:order, customer: customer, total: order_total, payment_total: 0)
order.update_attribute(:state, 'checkout')
order.update_attribute(:state, 'complete')
create(
:order,
customer: customer,
@@ -115,7 +123,7 @@ describe CustomersWithBalance do
before do
order = create(:order, customer: customer, total: order_total, payment_total: 0)
order.update_attribute(:state, 'checkout')
order.update_attribute(:state, 'complete')
order = create(:order, customer: customer, total: order_total, payment_total: payment_total)
order.update_attribute(:state, 'resumed')
end
@@ -131,7 +139,7 @@ describe CustomersWithBalance do
before do
order = create(:order, customer: customer, total: order_total, payment_total: 0)
order.update_attribute(:state, 'checkout')
order.update_attribute(:state, 'complete')
order = create(:order, customer: customer, total: order_total, payment_total: payment_total)
order.update_attribute(:state, 'payment')
end
@@ -147,7 +155,7 @@ describe CustomersWithBalance do
before do
order = create(:order, customer: customer, total: order_total, payment_total: 0)
order.update_attribute(:state, 'checkout')
order.update_attribute(:state, 'complete')
order = create(:order, customer: customer, total: order_total, payment_total: payment_total)
order.update_attribute(:state, 'awaiting_return')
end
@@ -164,7 +172,7 @@ describe CustomersWithBalance do
before do
order = create(:order, customer: customer, total: order_total, payment_total: 0)
order.update_attribute(:state, 'checkout')
order.update_attribute(:state, 'complete')
order = create(:order, customer: customer, total: order_total, payment_total: payment_total)
order.update_attribute(:state, 'returned')
end

View File

@@ -0,0 +1,197 @@
# frozen_string_literal: true
require 'spec_helper'
describe OutstandingBalance do
let(:outstanding_balance) { described_class.new(relation) }
describe '#statement' do
let(:relation) { Spree::Order.none }
it 'returns the CASE statement necessary to compute the order balance' do
normalized_sql_statement = normalize(outstanding_balance.statement)
expect(normalized_sql_statement).to eq(normalize(<<-SQL))
CASE WHEN state IN ('canceled', 'returned') THEN payment_total
WHEN state IS NOT NULL THEN payment_total - total
ELSE 0 END
SQL
end
def normalize(sql)
sql.strip_heredoc.gsub("\n", '').squeeze(' ')
end
end
describe '#query' do
let(:relation) { Spree::Order.all }
let(:total) { 200.00 }
let(:order_total) { 100.00 }
context 'when orders are in cart state' do
before do
create(:order, total: order_total, payment_total: 0, state: 'cart')
create(:order, total: order_total, payment_total: 0, state: 'cart')
end
it 'returns the order balance' do
order = outstanding_balance.query.first
expect(order.balance_value).to eq(-order_total)
end
end
context 'when orders are in address state' do
before do
create(:order, total: order_total, payment_total: 0, state: 'address')
create(:order, total: order_total, payment_total: 50, state: 'address')
end
it 'returns the order balance' do
order = outstanding_balance.query.first
expect(order.balance_value).to eq(-order_total)
end
end
context 'when orders are in delivery state' do
before do
create(:order, total: order_total, payment_total: 0, state: 'delivery')
create(:order, total: order_total, payment_total: 50, state: 'delivery')
end
it 'returns the order balance' do
order = outstanding_balance.query.first
expect(order.balance_value).to eq(-order_total)
end
end
context 'when orders are in payment state' do
before do
create(:order, total: order_total, payment_total: 0, state: 'payment')
create(:order, total: order_total, payment_total: 50, state: 'payment')
end
it 'returns the order balance' do
order = outstanding_balance.query.first
expect(order.balance_value).to eq(-order_total)
end
end
context 'when no orders where paid' do
before do
order = create(:order, total: order_total, payment_total: 0)
order.update_attribute(:state, 'complete')
order = create(:order, total: order_total, payment_total: 0)
order.update_attribute(:state, 'complete')
end
it 'returns the customer balance' do
order = outstanding_balance.query.first
expect(order.balance_value).to eq(-order_total)
end
end
context 'when an order was paid' do
let(:payment_total) { order_total }
before do
order = create(:order, total: order_total, payment_total: 0)
order.update_attribute(:state, 'complete')
order = create(:order, total: order_total, payment_total: payment_total)
order.update_attribute(:state, 'complete')
end
it 'returns the customer balance' do
order = outstanding_balance.query.first
expect(order.balance_value).to eq(payment_total - 200.0)
end
end
context 'when an order is canceled' do
let(:payment_total) { order_total }
let(:non_canceled_orders_total) { order_total }
before do
create(:order, total: order_total, payment_total: order_total, state: 'canceled')
order = create(:order, total: order_total, payment_total: 0)
order.update_attribute(:state, 'complete')
end
it 'returns the customer balance' do
order = outstanding_balance.query.first
expect(order.balance_value).to eq(payment_total)
end
end
context 'when an order is resumed' do
let(:payment_total) { order_total }
before do
order = create(:order, total: order_total, payment_total: 0)
order.update_attribute(:state, 'complete')
order = create(:order, total: order_total, payment_total: payment_total)
order.update_attribute(:state, 'resumed')
end
it 'returns the customer balance' do
order = outstanding_balance.query.first
expect(order.balance_value).to eq(payment_total - 200.0)
end
end
context 'when an order is in payment' do
let(:payment_total) { order_total }
before do
order = create(:order, total: order_total, payment_total: 0)
order.update_attribute(:state, 'complete')
order = create(:order, total: order_total, payment_total: payment_total)
order.update_attribute(:state, 'payment')
end
it 'returns the customer balance' do
order = outstanding_balance.query.first
expect(order.balance_value).to eq(payment_total - 200.0)
end
end
context 'when an order is awaiting_return' do
let(:payment_total) { order_total }
before do
order = create(:order, total: order_total, payment_total: 0)
order.update_attribute(:state, 'complete')
order = create(:order, total: order_total, payment_total: payment_total)
order.update_attribute(:state, 'awaiting_return')
end
it 'returns the customer balance' do
order = outstanding_balance.query.first
expect(order.balance_value).to eq(payment_total - 200.0)
end
end
context 'when an order is returned' do
let(:payment_total) { order_total }
let(:non_returned_orders_total) { order_total }
before do
order = create(:order, total: order_total, payment_total: payment_total)
order.update_attribute(:state, 'returned')
order = create(:order, total: order_total, payment_total: 0)
order.update_attribute(:state, 'complete')
end
it 'returns the customer balance' do
order = outstanding_balance.query.first
expect(order.balance_value).to eq(payment_total)
end
end
context 'when there are no orders' do
it 'returns the order balance' do
orders = outstanding_balance.query
expect(orders).to be_empty
end
end
end
end

View File

@@ -58,7 +58,7 @@ describe "checking out an order with a paypal express payment method", type: :re
get spree.confirm_paypal_path, params
# Processing was successful, order is complete
expect(response).to redirect_to spree.order_path(order, token: order.token)
expect(response).to redirect_to order_path(order, token: order.token)
expect(order.reload.complete?).to be true
# We have only one payment, and one transaction fee

View File

@@ -104,7 +104,7 @@ describe "checking out an order with a Stripe Connect payment method", type: :re
it "should process the payment without storing card details" do
put update_checkout_path, params
expect(json_response["path"]).to eq spree.order_path(order)
expect(json_response["path"]).to eq order_path(order)
expect(order.payments.completed.count).to be 1
card = order.payments.completed.first.source
@@ -161,7 +161,7 @@ describe "checking out an order with a Stripe Connect payment method", type: :re
it "should process the payment, and stores the card/customer details" do
put update_checkout_path, params
expect(json_response["path"]).to eq spree.order_path(order)
expect(json_response["path"]).to eq order_path(order)
expect(order.payments.completed.count).to be 1
card = order.payments.completed.first.source
@@ -263,7 +263,7 @@ describe "checking out an order with a Stripe Connect payment method", type: :re
it "should process the payment, and keep the profile ids and other card details" do
put update_checkout_path, params
expect(json_response["path"]).to eq spree.order_path(order)
expect(json_response["path"]).to eq order_path(order)
expect(order.payments.completed.count).to be 1
card = order.payments.completed.first.source

View File

@@ -130,7 +130,7 @@ describe "checking out an order with a Stripe SCA payment method", type: :reques
it "should process the payment without storing card details" do
put update_checkout_path, params
expect(json_response["path"]).to eq spree.order_path(order)
expect(json_response["path"]).to eq order_path(order)
expect(order.payments.completed.count).to be 1
card = order.payments.completed.first.source
@@ -218,7 +218,7 @@ describe "checking out an order with a Stripe SCA payment method", type: :reques
it "should process the payment, and store the card/customer details" do
put update_checkout_path, params
expect(json_response["path"]).to eq spree.order_path(order)
expect(json_response["path"]).to eq order_path(order)
expect(order.payments.completed.count).to be 1
card = order.payments.completed.first.source
@@ -303,7 +303,7 @@ describe "checking out an order with a Stripe SCA payment method", type: :reques
it "should process the payment, and keep the profile ids and other card details" do
put update_checkout_path, params
expect(json_response["path"]).to eq spree.order_path(order)
expect(json_response["path"]).to eq order_path(order)
expect(order.payments.completed.count).to be 1
card = order.payments.completed.first.source

View File

@@ -6,21 +6,55 @@ describe Api::OrderSerializer do
let(:serializer) { Api::OrderSerializer.new order }
let(:order) { create(:completed_order_with_totals) }
let!(:completed_payment) { create(:payment, order: order, state: 'completed', amount: order.total - 1) }
let!(:payment) { create(:payment, order: order, state: 'checkout', amount: 123.45) }
describe '#serializable_hash' do
let!(:completed_payment) do
create(:payment, order: order, state: 'completed', amount: order.total - 1)
end
let!(:payment) { create(:payment, order: order, state: 'checkout', amount: 123.45) }
it "serializes an order" do
expect(serializer.to_json).to match order.number.to_s
it "serializes an order" do
expect(serializer.serializable_hash[:number]).to eq(order.number)
end
it "convert the state attributes to translatable keys" do
hash = serializer.serializable_hash
expect(hash[:state]).to eq("complete")
expect(hash[:payment_state]).to eq("balance_due")
end
it "only serializes completed payments" do
hash = serializer.serializable_hash
expect(hash[:payments].first[:amount]).to eq(completed_payment.amount)
end
end
it "convert the state attributes to translatable keys" do
# byebug if serializer.to_json =~ /balance_due/
expect(serializer.to_json).to match "complete"
expect(serializer.to_json).to match "balance_due"
end
describe '#outstanding_balance' do
context 'when the customer_balance feature is enabled' do
before do
allow(OpenFoodNetwork::FeatureToggle)
.to receive(:enabled?).with(:customer_balance, order.user) { true }
it "only serializes completed payments" do
expect(serializer.to_json).to match completed_payment.amount.to_s
expect(serializer.to_json).to_not match payment.amount.to_s
allow(order).to receive(:balance_value).and_return(-1.23)
end
it "returns the object's balance_value from the users perspective" do
expect(serializer.serializable_hash[:outstanding_balance]).to eq(1.23)
end
end
context 'when the customer_balance is not enabled' do
before do
allow(OpenFoodNetwork::FeatureToggle)
.to receive(:enabled?).with(:customer_balance, order.user) { false }
allow(order).to receive(:outstanding_balance).and_return(123.0)
end
it 'calls #outstanding_balance on the object' do
expect(serializer.serializable_hash[:outstanding_balance]).to eq(123.0)
end
end
end
end