mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-25 20:46:48 +00:00
Rewrite existing specs
This commit is contained in:
@@ -37,7 +37,7 @@ angular.module("admin.orders").controller "ordersCtrl", ($scope, $injector, Requ
|
||||
})
|
||||
|
||||
$scope.$watch 'sortOptions', (sort) ->
|
||||
if sort.predicate != ""
|
||||
if sort && sort.predicate != ""
|
||||
$scope.sorting = sort.predicate + ' desc' if sort.reverse
|
||||
$scope.sorting = sort.predicate + ' asc' if !sort.reverse
|
||||
$scope.fetchResults()
|
||||
|
||||
@@ -107,17 +107,16 @@ Spree::Admin::OrdersController.class_eval do
|
||||
private
|
||||
|
||||
def orders
|
||||
@search = if json_request?
|
||||
OpenFoodNetwork::Permissions.new(spree_current_user).editable_orders.ransack(params[:q])
|
||||
else
|
||||
Spree::Order.accessible_by(current_ability, :index).ransack(params[:q])
|
||||
end
|
||||
if json_request?
|
||||
@search = OpenFoodNetwork::Permissions.new(spree_current_user).editable_orders.ransack(params[:q])
|
||||
else
|
||||
@search = Spree::Order.accessible_by(current_ability, :index).ransack(params[:q])
|
||||
|
||||
# Replaced this search to filter orders to only show those distributed by current user (or all for admin user)
|
||||
@search.result.includes([:user, :shipments, :payments]).
|
||||
distributed_by_user(spree_current_user).
|
||||
page(params[:page]).
|
||||
per(params[:per_page] || Spree::Config[:orders_per_page])
|
||||
# Replaced this search to filter orders to only show those distributed by current user (or all for admin user)
|
||||
@search.result.includes([:user, :shipments, :payments]).distributed_by_user(spree_current_user)
|
||||
end
|
||||
|
||||
@search.result.page(params[:page]).per(params[:per_page] || Spree::Config[:orders_per_page])
|
||||
end
|
||||
|
||||
def require_distributor_abn
|
||||
|
||||
@@ -66,26 +66,27 @@ describe Spree::Admin::OrdersController, type: :controller do
|
||||
end
|
||||
|
||||
it "retrieves a list of orders with appropriate attributes, including line items with appropriate attributes" do
|
||||
keys = json_response.first.keys.map{ |key| key.to_sym }
|
||||
keys = json_response['orders'].first.keys.map{ |key| key.to_sym }
|
||||
order_attributes.all?{ |attr| keys.include? attr }.should == true
|
||||
end
|
||||
|
||||
it "sorts orders in ascending id order" do
|
||||
ids = json_response.map{ |order| order['id'] }
|
||||
ids[0].should < ids[1]
|
||||
ids[1].should < ids[2]
|
||||
it "sorts orders in descending id order" do
|
||||
ids = json_response['orders'].map{ |order| order['id'] }
|
||||
ids[0].should > ids[1]
|
||||
ids[1].should > ids[2]
|
||||
end
|
||||
|
||||
it "formats completed_at to 'yyyy-mm-dd hh:mm'" do
|
||||
json_response.map{ |order| order['completed_at'] }.all?{ |a| a.match("^\\d{4}-\\d{2}-\\d{2} \\d{2}:\\d{2}:\\d{2}$") }.should == true
|
||||
pp json_response
|
||||
json_response['orders'].map{ |order| order['completed_at'] }.all?{ |a| a == order1.completed_at.strftime('%B %d, %Y') }.should == true
|
||||
end
|
||||
|
||||
it "returns distributor object with id key" do
|
||||
json_response.map{ |order| order['distributor'] }.all?{ |d| d.has_key?('id') }.should == true
|
||||
json_response['orders'].map{ |order| order['distributor'] }.all?{ |d| d.has_key?('id') }.should == true
|
||||
end
|
||||
|
||||
it "retrieves the order number" do
|
||||
json_response.map{ |order| order['number'] }.all?{ |number| number.match("^R\\d{5,10}$") }.should == true
|
||||
json_response['orders'].map{ |order| order['number'] }.all?{ |number| number.match("^R\\d{5,10}$") }.should == true
|
||||
end
|
||||
end
|
||||
|
||||
@@ -120,7 +121,7 @@ describe Spree::Admin::OrdersController, type: :controller do
|
||||
end
|
||||
|
||||
it "retrieves a list of orders" do
|
||||
keys = json_response.first.keys.map{ |key| key.to_sym }
|
||||
keys = json_response['orders'].first.keys.map{ |key| key.to_sym }
|
||||
order_attributes.all?{ |attr| keys.include? attr }.should == true
|
||||
end
|
||||
end
|
||||
@@ -132,7 +133,7 @@ describe Spree::Admin::OrdersController, type: :controller do
|
||||
end
|
||||
|
||||
it "retrieves a list of orders" do
|
||||
keys = json_response.first.keys.map{ |key| key.to_sym }
|
||||
keys = json_response['orders'].first.keys.map{ |key| key.to_sym }
|
||||
order_attributes.all?{ |attr| keys.include? attr }.should == true
|
||||
end
|
||||
end
|
||||
|
||||
@@ -3,7 +3,7 @@ require "spec_helper"
|
||||
feature %q{
|
||||
As an administrator
|
||||
I want to manage adjustments on orders
|
||||
} do
|
||||
}, js: true do
|
||||
include AuthenticationWorkflow
|
||||
include WebHelper
|
||||
|
||||
@@ -30,7 +30,7 @@ feature %q{
|
||||
click_link 'New Adjustment'
|
||||
fill_in 'adjustment_amount', with: 110
|
||||
fill_in 'adjustment_label', with: 'Late fee'
|
||||
select 'GST', from: 'tax_rate_id'
|
||||
select2_select 'GST', from: 'tax_rate_id'
|
||||
click_button 'Continue'
|
||||
|
||||
# Then I should see the adjustment, with the correct tax
|
||||
@@ -51,11 +51,11 @@ feature %q{
|
||||
page.find('tr', text: 'Shipping').find('a.icon-edit').click
|
||||
|
||||
# Then I should see the uneditable included tax and our tax rate as the default
|
||||
page.should have_field :adjustment_included_tax, with: '10.00', disabled: true
|
||||
page.should have_select :tax_rate_id, selected: 'GST'
|
||||
expect(page).to have_field :adjustment_included_tax, with: '10.00', disabled: true
|
||||
expect(page).to have_select2 :tax_rate_id, selected: 'GST'
|
||||
|
||||
# When I edit the adjustment, removing the tax
|
||||
select 'Remove tax', from: :tax_rate_id
|
||||
select2_select 'Remove tax', from: :tax_rate_id
|
||||
click_button 'Continue'
|
||||
|
||||
# Then the adjustment tax should be cleared
|
||||
@@ -75,11 +75,11 @@ feature %q{
|
||||
page.find('tr', text: 'Shipping').find('a.icon-edit').click
|
||||
|
||||
# Then I should see the uneditable included tax and 'Remove tax' as the default tax rate
|
||||
page.should have_field :adjustment_included_tax, with: '0.00', disabled: true
|
||||
page.should have_select :tax_rate_id, selected: []
|
||||
expect(page).to have_field :adjustment_included_tax, with: '0.00', disabled: true
|
||||
expect(page).to have_select2 :tax_rate_id, selected: []
|
||||
|
||||
# When I edit the adjustment, setting a tax rate
|
||||
select 'GST', from: :tax_rate_id
|
||||
select2_select 'GST', from: :tax_rate_id
|
||||
click_button 'Continue'
|
||||
|
||||
# Then the adjustment tax should be recalculated
|
||||
|
||||
@@ -54,8 +54,8 @@ feature %q{
|
||||
|
||||
it "displays a column for order date" do
|
||||
expect(page).to have_selector "th.date", text: "ORDER DATE", :visible => true
|
||||
expect(page).to have_selector "td.date", text: o1.completed_at.strftime("%F %T"), :visible => true
|
||||
expect(page).to have_selector "td.date", text: o2.completed_at.strftime("%F %T"), :visible => true
|
||||
expect(page).to have_selector "td.date", text: o1.completed_at.strftime('%B %d, %Y'), :visible => true
|
||||
expect(page).to have_selector "td.date", text: o2.completed_at.strftime('%B %d, %Y'), :visible => true
|
||||
end
|
||||
|
||||
it "displays a column for producer" do
|
||||
|
||||
@@ -109,7 +109,7 @@ feature %q{
|
||||
quick_login_as_admin
|
||||
visit '/admin/orders'
|
||||
uncheck 'Only show complete orders'
|
||||
click_button 'Filter Results'
|
||||
page.find('a.icon-search').click
|
||||
|
||||
click_edit
|
||||
|
||||
|
||||
@@ -37,7 +37,7 @@ describe "LineItemsCtrl", ->
|
||||
order = { id: 9, order_cycle: { id: 4 }, distributor: { id: 5 }, number: "R123456" }
|
||||
lineItem = { id: 7, quantity: 3, order: { id: 9 }, supplier: { id: 1 } }
|
||||
|
||||
httpBackend.expectGET("/admin/orders.json?q%5Bcompleted_at_gteq%5D=SomeDate&q%5Bcompleted_at_lt%5D=SomeDate&q%5Bcompleted_at_not_null%5D=true&q%5Bstate_not_eq%5D=canceled").respond [order]
|
||||
httpBackend.expectGET("/admin/orders.json?q%5Bcompleted_at_gteq%5D=SomeDate&q%5Bcompleted_at_lt%5D=SomeDate&q%5Bcompleted_at_not_null%5D=true&q%5Bstate_not_eq%5D=canceled").respond {orders: [order], pagination: {page: 1, pages: 1, results: 1}}
|
||||
httpBackend.expectGET("/admin/bulk_line_items.json?q%5Border%5D%5Bcompleted_at_gteq%5D=SomeDate&q%5Border%5D%5Bcompleted_at_lt%5D=SomeDate&q%5Border%5D%5Bcompleted_at_not_null%5D=true&q%5Border%5D%5Bstate_not_eq%5D=canceled").respond [lineItem]
|
||||
httpBackend.expectGET("/admin/enterprises/visible.json?ams_prefix=basic&q%5Bsells_in%5D%5B%5D=own&q%5Bsells_in%5D%5B%5D=any").respond [distributor]
|
||||
httpBackend.expectGET("/admin/order_cycles.json?ams_prefix=basic&as=distributor&q%5Borders_close_at_gt%5D=SomeDate").respond [orderCycle]
|
||||
@@ -68,7 +68,7 @@ describe "LineItemsCtrl", ->
|
||||
|
||||
describe "initialisation", ->
|
||||
it "gets suppliers", ->
|
||||
expect(scope.suppliers).toDeepEqual [supplier ]
|
||||
expect(scope.suppliers).toDeepEqual [ supplier ]
|
||||
|
||||
it "gets distributors", ->
|
||||
expect(scope.distributors).toDeepEqual [ distributor ]
|
||||
|
||||
@@ -7,13 +7,25 @@ describe "ordersCtrl", ->
|
||||
{id: 10, name: 'Ten', status: 'open', distributors: [{id: 1, name: 'One'}]}
|
||||
{id: 20, name: 'Twenty', status: 'closed', distributors: [{id: 2, name: 'Two', status: 'closed'}]}
|
||||
]
|
||||
SortOptions = {
|
||||
predicate: "",
|
||||
reverse: false
|
||||
}
|
||||
|
||||
beforeEach ->
|
||||
scope = {}
|
||||
shops = []
|
||||
orderCycles = [
|
||||
{id: 10, name: 'Ten', status: 'open', distributors: [{id: 1, name: 'One'}]}
|
||||
{id: 20, name: 'Twenty', status: 'closed', distributors: [{id: 2, name: 'Two', status: 'closed'}]}
|
||||
]
|
||||
|
||||
module('admin.orders')
|
||||
inject ($controller) ->
|
||||
ctrl = $controller 'ordersCtrl', {$scope: scope, $attrs: attrs, shops: shops, orderCycles: orderCycles}
|
||||
module 'admin.orders', ($provide)->
|
||||
$provide.provider('shops', shops)
|
||||
$provide.provider('orderCycles', orderCycles)
|
||||
inject (_$injector_, $controller) ->
|
||||
$injector = _$injector_
|
||||
ctrl = $controller 'ordersCtrl', {$scope: scope, $attrs: attrs, $injector: $injector, SortOptions: SortOptions}
|
||||
|
||||
it "initialises name_and_status", ->
|
||||
expect(scope.orderCycles[0].name_and_status).toEqual "Ten (open)"
|
||||
|
||||
@@ -18,17 +18,17 @@ describe "Orders service", ->
|
||||
result = response = null
|
||||
|
||||
beforeEach ->
|
||||
response = [{ id: 5, name: 'Order 1'}]
|
||||
response = { orders: [{ id: 5, name: 'Order 1'}], pagination: {page: 1, pages: 1, results: 1} }
|
||||
$httpBackend.expectGET('/admin/orders.json').respond 200, response
|
||||
result = Orders.index()
|
||||
$httpBackend.flush()
|
||||
|
||||
it "stores returned data in @byID, with ids as keys", ->
|
||||
# OrderResource returns instances of Resource rather than raw objects
|
||||
expect(Orders.byID).toDeepEqual { 5: response[0] }
|
||||
expect(Orders.byID).toDeepEqual { 5: response.orders[0] }
|
||||
|
||||
it "stores returned data in @pristineByID, with ids as keys", ->
|
||||
expect(Orders.pristineByID).toDeepEqual { 5: response[0] }
|
||||
expect(Orders.pristineByID).toDeepEqual { 5: response.orders[0] }
|
||||
|
||||
it "returns an array of orders", ->
|
||||
expect(result).toDeepEqual response
|
||||
|
||||
Reference in New Issue
Block a user