mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-03-18 04:39:14 +00:00
WIP: BOM loads with orders filtered by default date restrictions
This commit is contained in:
@@ -68,8 +68,8 @@ orderManagementModule.controller "AdminOrderMgmtCtrl", [
|
||||
($scope, $http, dataFetcher, blankEnterprise, pendingChanges) ->
|
||||
|
||||
now = new Date
|
||||
start = new Date( now.getTime() - ( 7 * (1440 * 60 * 1000) ) - ( now.getTime() % ( 1440 * 60 * 1000 ) - now.getTimezoneOffset() * 60 * 1000 ) )
|
||||
end = new Date( now.getTime() - ( now.getTime() % ( 1440 * 60 * 1000 ) - now.getTimezoneOffset() * 60 * 1000 ) + ( 1 * ( 1440 * 60 * 1000 ) ) )
|
||||
start = new Date( now.getTime() - ( 7 * (1440 * 60 * 1000) ) - (now.getTime() - now.getTimezoneOffset() * 60 * 1000) % (1440 * 60 * 1000) )
|
||||
end = new Date( now.getTime() - (now.getTime() - now.getTimezoneOffset() * 60 * 1000) % (1440 * 60 * 1000) + ( 1 * ( 1440 * 60 * 1000 ) ) )
|
||||
$scope.lineItems = []
|
||||
$scope.confirmDelete = true
|
||||
$scope.startDate = formatDate start
|
||||
@@ -98,7 +98,7 @@ orderManagementModule.controller "AdminOrderMgmtCtrl", [
|
||||
api_error_msg = "You don't have an API key yet. An attempt was made to generate one, but you are currently not authorised, please contact your site administrator for access."
|
||||
|
||||
$scope.fetchOrders = ->
|
||||
dataFetcher("/api/orders?template=bulk_index&q[completed_at_not_null]=true").then (data) ->
|
||||
dataFetcher("/api/orders?template=bulk_index&q[completed_at_not_null]=true&q[completed_at_gt]=#{$scope.startDate}&q[completed_at_lt]=#{$scope.endDate}").then (data) ->
|
||||
$scope.resetOrders data
|
||||
|
||||
$scope.resetOrders = (data) ->
|
||||
|
||||
@@ -204,10 +204,12 @@ feature %q{
|
||||
end
|
||||
|
||||
context "using date restriction controls" do
|
||||
let!(:o1) { FactoryGirl.create(:order, state: 'complete', completed_at: Time.now ) }
|
||||
let!(:o1) { FactoryGirl.create(:order, state: 'complete', completed_at: (Date.today - 8).strftime("%F %T") ) }
|
||||
let!(:o2) { FactoryGirl.create(:order, state: 'complete', completed_at: Time.now ) }
|
||||
let!(:o3) { FactoryGirl.create(:order, state: 'complete', completed_at: (Date.today + 2).strftime("%F %T") ) }
|
||||
let!(:li1) { FactoryGirl.create(:line_item, order: o1 ) }
|
||||
let!(:li2) { FactoryGirl.create(:line_item, order: o2 ) }
|
||||
let!(:li3) { FactoryGirl.create(:line_item, order: o3 ) }
|
||||
|
||||
before :each do
|
||||
visit '/admin/orders/bulk_management'
|
||||
@@ -219,6 +221,12 @@ feature %q{
|
||||
page.should have_field "start_date_filter", with: one_week_ago
|
||||
page.should have_field "end_date_filter", with: tonight
|
||||
end
|
||||
|
||||
it "only loads line items whose orders meet the date restriction criteria" do
|
||||
page.should_not have_selector "td.id", text: li1.id.to_s, visible: true
|
||||
page.should have_selector "td.id", text: li2.id.to_s, visible: true
|
||||
page.should_not have_selector "td.id", text: li3.id.to_s, visible: true
|
||||
end
|
||||
end
|
||||
|
||||
context "using action buttons" do
|
||||
|
||||
@@ -7,6 +7,7 @@ describe "AdminOrderMgmtCtrl", ->
|
||||
scope = $rootScope.$new()
|
||||
ctrl = $controller
|
||||
httpBackend = $httpBackend
|
||||
spyOn(window, "formatDate").andReturn "SomeDate"
|
||||
|
||||
ctrl "AdminOrderMgmtCtrl", {$scope: scope}
|
||||
)
|
||||
@@ -32,9 +33,9 @@ describe "AdminOrderMgmtCtrl", ->
|
||||
|
||||
describe "fetching orders", ->
|
||||
beforeEach ->
|
||||
httpBackend.expectGET("/api/orders?template=bulk_index&q[completed_at_not_null]=true").respond "list of orders"
|
||||
httpBackend.expectGET("/api/orders?template=bulk_index&q[completed_at_not_null]=true&q[completed_at_gt]=SomeDate&q[completed_at_lt]=SomeDate").respond "list of orders"
|
||||
|
||||
it "makes a standard call to dataFetcher", ->
|
||||
it "makes a call to dataFetcher, with current start and end date parameters", ->
|
||||
scope.fetchOrders()
|
||||
|
||||
it "calls resetOrders after data has been received", ->
|
||||
|
||||
Reference in New Issue
Block a user