mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-12 23:27:48 +00:00
Merge master into cleanup
This commit is contained in:
10
spec/javascripts/application_spec.js
Normal file
10
spec/javascripts/application_spec.js
Normal file
@@ -0,0 +1,10 @@
|
||||
//= require angular
|
||||
//= require angular-resource
|
||||
//= require angular-animate
|
||||
//= require angular-mocks
|
||||
//= require angular-cookies
|
||||
//= require angular-backstretch.js
|
||||
//= require angular-flash.min.js
|
||||
//= require moment
|
||||
|
||||
angular.module('templates', [])
|
||||
@@ -18,30 +18,29 @@ describe "AdminOrderMgmtCtrl", ->
|
||||
returnedDistributors = ["list of distributors"]
|
||||
returnedOrderCycles = [ "oc1", "oc2", "oc3" ]
|
||||
httpBackend.expectGET("/api/users/authorise_api?token=api_key").respond success: "Use of API Authorised"
|
||||
httpBackend.expectGET("/api/enterprises/managed?template=bulk_index&q[is_primary_producer_eq]=true").respond returnedSuppliers
|
||||
httpBackend.expectGET("/api/enterprises/managed?template=bulk_index&q[is_distributor_eq]=true").respond returnedDistributors
|
||||
httpBackend.expectGET("/api/order_cycles/managed").respond returnedOrderCycles
|
||||
httpBackend.expectGET("/api/enterprises/accessible?template=bulk_index&q[is_primary_producer_eq]=true").respond returnedSuppliers
|
||||
httpBackend.expectGET("/api/enterprises/accessible?template=bulk_index&q[is_distributor_eq]=true").respond returnedDistributors
|
||||
httpBackend.expectGET("/api/order_cycles/accessible").respond returnedOrderCycles
|
||||
spyOn(scope, "initialiseVariables").andCallThrough()
|
||||
spyOn(scope, "fetchOrders").andReturn "nothing"
|
||||
spyOn(returnedSuppliers, "unshift")
|
||||
spyOn(returnedDistributors, "unshift")
|
||||
spyOn(returnedOrderCycles, "unshift")
|
||||
#spyOn(returnedSuppliers, "unshift")
|
||||
#spyOn(returnedDistributors, "unshift")
|
||||
#spyOn(returnedOrderCycles, "unshift")
|
||||
scope.initialise "api_key"
|
||||
httpBackend.flush()
|
||||
expect(scope.suppliers).toEqual ["list of suppliers"]
|
||||
expect(scope.distributors).toEqual ["list of distributors"]
|
||||
expect(scope.orderCycles).toEqual [ "oc1", "oc2", "oc3" ]
|
||||
expect(scope.initialiseVariables.calls.length).toEqual 1
|
||||
expect(scope.fetchOrders.calls.length).toEqual 1
|
||||
expect(returnedSuppliers.unshift.calls.length).toEqual 1
|
||||
expect(returnedDistributors.unshift.calls.length).toEqual 1
|
||||
expect(returnedOrderCycles.unshift.calls.length).toEqual 1
|
||||
expect(scope.spree_api_key_ok).toEqual true
|
||||
|
||||
expect(scope.suppliers).toEqual [{ id : '', name : 'All' }, 'list of suppliers']
|
||||
expect(scope.distributors).toEqual [ { id : '', name : 'All' }, 'list of distributors' ]
|
||||
expect(scope.orderCycles).toEqual [ { id : '', name : 'All' }, 'oc1', 'oc2', 'oc3' ]
|
||||
|
||||
expect(scope.initialiseVariables.calls.length).toBe 1
|
||||
expect(scope.fetchOrders.calls.length).toBe 1
|
||||
expect(scope.spree_api_key_ok).toBe true
|
||||
|
||||
describe "fetching orders", ->
|
||||
beforeEach ->
|
||||
scope.initialiseVariables()
|
||||
httpBackend.expectGET("/api/orders/managed?template=bulk_index&q[completed_at_not_null]=true&q[completed_at_gt]=SomeDate&q[completed_at_lt]=SomeDate").respond "list of orders"
|
||||
httpBackend.expectGET("/api/orders/managed?template=bulk_index;page=1;per_page=500;q[completed_at_not_null]=true;q[completed_at_gt]=SomeDate;q[completed_at_lt]=SomeDate").respond "list of orders"
|
||||
|
||||
it "makes a call to dataFetcher, with current start and end date parameters", ->
|
||||
scope.fetchOrders()
|
||||
@@ -625,4 +624,4 @@ describe "Auxiliary functions", ->
|
||||
expect(formatDate(date)).toEqual "2010-06-15"
|
||||
|
||||
it "returns a time formatted as hh-MM:ss", ->
|
||||
expect(formatTime(date)).toEqual "05:10:30"
|
||||
expect(formatTime(date)).toEqual "05:10:30"
|
||||
|
||||
@@ -1100,7 +1100,7 @@ describe "AdminProductEditCtrl", ->
|
||||
|
||||
|
||||
describe "when the variant has been saved", ->
|
||||
it "deletes variants with a http delete request to /api/products/product_id/variants/(variant_id)", ->
|
||||
it "deletes variants with a http delete request to /api/products/product_permalink/variants/(variant_id)", ->
|
||||
spyOn(window, "confirm").andReturn true
|
||||
scope.products = [
|
||||
{
|
||||
@@ -1117,7 +1117,7 @@ describe "AdminProductEditCtrl", ->
|
||||
}
|
||||
]
|
||||
scope.dirtyProducts = {}
|
||||
httpBackend.expectDELETE("/api/products/9/variants/3").respond 200, "data"
|
||||
httpBackend.expectDELETE("/api/products/apples/variants/3/soft_delete").respond 200, "data"
|
||||
scope.deleteVariant scope.products[0], scope.products[0].variants[0]
|
||||
httpBackend.flush()
|
||||
|
||||
@@ -1159,7 +1159,7 @@ describe "AdminProductEditCtrl", ->
|
||||
id: 13
|
||||
name: "P1"
|
||||
|
||||
httpBackend.expectDELETE("/api/products/9/variants/3").respond 200, "data"
|
||||
httpBackend.expectDELETE("/api/products/apples/variants/3/soft_delete").respond 200, "data"
|
||||
scope.deleteVariant scope.products[0], scope.products[0].variants[0]
|
||||
httpBackend.flush()
|
||||
expect(scope.products[0].variants).toEqual [
|
||||
@@ -1434,4 +1434,4 @@ describe "Taxons service", ->
|
||||
$httpBackend.expectGET("/admin/taxons/search?q=lala").respond 200, response
|
||||
taxons = Taxons.findByTerm("lala")
|
||||
$httpBackend.flush()
|
||||
expect(angular.equals(taxons,response)).toBe true
|
||||
expect(angular.equals(taxons,response)).toBe true
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
describe "DetailsCtrl", ->
|
||||
ctrl = null
|
||||
scope = null
|
||||
order = null
|
||||
|
||||
beforeEach ->
|
||||
module("Darkswarm")
|
||||
inject ($controller, $rootScope) ->
|
||||
scope = $rootScope.$new()
|
||||
ctrl = $controller 'DetailsCtrl', {$scope: scope}
|
||||
|
||||
|
||||
it "finds a field by path", ->
|
||||
scope.details =
|
||||
path: "test"
|
||||
expect(scope.field('path')).toEqual "test"
|
||||
|
||||
it "tests validity", ->
|
||||
scope.details =
|
||||
path:
|
||||
$dirty: true
|
||||
$invalid: true
|
||||
expect(scope.fieldValid('path')).toEqual false
|
||||
|
||||
it "returns errors by path", ->
|
||||
scope.Order =
|
||||
errors: ->
|
||||
scope.details =
|
||||
path:
|
||||
$error:
|
||||
email: true
|
||||
required: true
|
||||
expect(scope.fieldErrors('path')).toEqual ["must be email address", "can't be blank"].join ", "
|
||||
|
||||
|
||||
@@ -1,34 +1,28 @@
|
||||
describe "CheckoutCtrl", ->
|
||||
ctrl = null
|
||||
scope = null
|
||||
order = null
|
||||
Order = null
|
||||
|
||||
beforeEach ->
|
||||
module("Darkswarm")
|
||||
order =
|
||||
id: 3102
|
||||
shipping_method_id: "7"
|
||||
ship_address_same_as_billing: true
|
||||
payment_method_id: null
|
||||
shipping_methods:
|
||||
7:
|
||||
require_ship_address: true
|
||||
price: 0.0
|
||||
|
||||
25:
|
||||
require_ship_address: false
|
||||
price: 13
|
||||
inject ($controller) ->
|
||||
scope = {}
|
||||
ctrl = $controller 'CheckoutCtrl', {$scope: scope, order: order}
|
||||
|
||||
|
||||
it 'Gets the ship address automatically', ->
|
||||
expect(scope.require_ship_address).toEqual true
|
||||
|
||||
it 'Gets the current shipping price', ->
|
||||
expect(scope.shippingPrice()).toEqual 0.0
|
||||
scope.order.shipping_method_id = 25
|
||||
expect(scope.shippingPrice()).toEqual 13
|
||||
|
||||
angular.module('Darkswarm').value('user', {})
|
||||
Order = {
|
||||
submit: ->
|
||||
navigate: ->
|
||||
order:
|
||||
id: 1
|
||||
}
|
||||
inject ($controller, $rootScope) ->
|
||||
scope = $rootScope.$new()
|
||||
ctrl = $controller 'CheckoutCtrl', {$scope: scope, Order: Order}
|
||||
|
||||
it "defaults the user accordion to visible", ->
|
||||
expect(scope.accordion.user).toEqual true
|
||||
|
||||
it "delegates to the service on submit", ->
|
||||
event = {
|
||||
preventDefault: ->
|
||||
}
|
||||
spyOn(Order, "submit")
|
||||
scope.purchase(event)
|
||||
expect(Order.submit).toHaveBeenCalled()
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
describe "HubNodeCtrl", ->
|
||||
ctrl = null
|
||||
scope = null
|
||||
hub = null
|
||||
CurrentHub = null
|
||||
|
||||
beforeEach ->
|
||||
module 'Darkswarm'
|
||||
scope =
|
||||
hub: {}
|
||||
CurrentHub =
|
||||
id: 99
|
||||
|
||||
inject ($controller, $location)->
|
||||
ctrl = $controller 'HubNodeCtrl', {$scope: scope, CurrentHub: CurrentHub, $location : $location}
|
||||
|
||||
it "knows whether the controlled hub is current", ->
|
||||
scope.hub = {id: 1}
|
||||
expect(scope.current()).toEqual false
|
||||
scope.hub = {id: 99}
|
||||
expect(scope.current()).toEqual true
|
||||
|
||||
it "knows whether selecting this hub will empty the cart", ->
|
||||
CurrentHub.id = undefined
|
||||
expect(scope.emptiesCart()).toEqual false
|
||||
|
||||
CurrentHub.id = 99
|
||||
scope.hub.id = 99
|
||||
expect(scope.emptiesCart()).toEqual false
|
||||
|
||||
scope.hub.id = 1
|
||||
expect(scope.emptiesCart()).toEqual true
|
||||
@@ -14,5 +14,5 @@ describe 'OrderCycleCtrl', ->
|
||||
scope = {}
|
||||
ctrl = $controller 'OrderCycleCtrl', {$scope: scope, OrderCycle: OrderCycle}
|
||||
|
||||
it "puts the order cycle in scope", ->
|
||||
expect(scope.order_cycle).toEqual "test"
|
||||
#it "puts the order cycle in scope", ->
|
||||
#expect(scope.order_cycle).toEqual "test"
|
||||
|
||||
@@ -12,11 +12,3 @@ describe "SidebarCtrl", ->
|
||||
scope = $rootScope
|
||||
ctrl = $controller 'SidebarCtrl', {$scope: scope, $location: location}
|
||||
scope.$apply()
|
||||
|
||||
it 'is active when a location is set', ->
|
||||
expect(scope.active()).toEqual true
|
||||
|
||||
it 'is inactive no location is set', ->
|
||||
location.path = ->
|
||||
null
|
||||
expect(scope.active()).toEqual false
|
||||
|
||||
@@ -39,6 +39,6 @@ describe 'OrderCycle service', ->
|
||||
it "tells us when no order cycle is selected", ->
|
||||
OrderCycle.order_cycle = null
|
||||
expect(OrderCycle.selected()).toEqual false
|
||||
OrderCycle.order_cycle = {test: "blah"}
|
||||
OrderCycle.order_cycle = {orders_close_at: "10 days ago"}
|
||||
expect(OrderCycle.selected()).toEqual true
|
||||
|
||||
@@ -0,0 +1,88 @@
|
||||
describe 'Order service', ->
|
||||
Order = null
|
||||
orderData = null
|
||||
$httpBackend = null
|
||||
CheckoutFormState = null
|
||||
Navigation = null
|
||||
flash = null
|
||||
|
||||
beforeEach ->
|
||||
orderData = {
|
||||
id: 3102
|
||||
payment_method_id: null
|
||||
bill_address: {test: "foo"}
|
||||
ship_address: {test: "bar"}
|
||||
shipping_methods:
|
||||
7:
|
||||
require_ship_address: true
|
||||
price: 0.0
|
||||
|
||||
25:
|
||||
require_ship_address: false
|
||||
price: 13
|
||||
payment_methods:
|
||||
99:
|
||||
test: "foo"
|
||||
}
|
||||
angular.module('Darkswarm').value('order', orderData)
|
||||
module 'Darkswarm'
|
||||
inject ($injector, _$httpBackend_)->
|
||||
$httpBackend = _$httpBackend_
|
||||
Order = $injector.get("Order")
|
||||
Navigation = $injector.get("Navigation")
|
||||
flash = $injector.get("flash")
|
||||
CheckoutFormState = $injector.get("CheckoutFormState")
|
||||
spyOn(Navigation, "go") # Stubbing out writes to window.location
|
||||
|
||||
it "defaults the shipping method to the first", ->
|
||||
expect(Order.order.shipping_method_id).toEqual 7
|
||||
expect(Order.shippingMethod()).toEqual { require_ship_address : true, price : 0 }
|
||||
|
||||
# This is now handled via localStorage defaults
|
||||
xit "defaults to 'same as billing' for address", ->
|
||||
expect(Order.order.ship_address_same_as_billing).toEqual true
|
||||
|
||||
it 'Tracks whether a ship address is required', ->
|
||||
expect(Order.requireShipAddress()).toEqual true
|
||||
Order.order.shipping_method_id = 25
|
||||
expect(Order.requireShipAddress()).toEqual false
|
||||
|
||||
it 'Gets the current shipping price', ->
|
||||
expect(Order.shippingPrice()).toEqual 0.0
|
||||
Order.order.shipping_method_id = 25
|
||||
expect(Order.shippingPrice()).toEqual 13
|
||||
|
||||
it 'Gets the current payment method', ->
|
||||
expect(Order.paymentMethod()).toEqual null
|
||||
Order.order.payment_method_id = 99
|
||||
expect(Order.paymentMethod()).toEqual {test: "foo"}
|
||||
|
||||
it "Posts the Order to the server", ->
|
||||
$httpBackend.expectPUT("/shop/checkout", {order: Order.preprocess()}).respond 200, {path: "test"}
|
||||
Order.submit()
|
||||
$httpBackend.flush()
|
||||
|
||||
it "sends flash messages to the flash service", ->
|
||||
$httpBackend.expectPUT("/shop/checkout").respond 400, {flash: {error: "frogs"}}
|
||||
Order.submit()
|
||||
$httpBackend.flush()
|
||||
expect(flash.error).toEqual "frogs"
|
||||
|
||||
it "puts errors into the scope", ->
|
||||
$httpBackend.expectPUT("/shop/checkout").respond 400, {errors: {error: "frogs"}}
|
||||
Order.submit()
|
||||
$httpBackend.flush()
|
||||
expect(Order.errors).toEqual {error: "frogs"}
|
||||
|
||||
|
||||
it "Munges the order attributes to add _attributes as Rails needs", ->
|
||||
expect(Order.preprocess().bill_address_attributes).not.toBe(undefined)
|
||||
expect(Order.preprocess().bill_address).toBe(undefined)
|
||||
expect(Order.preprocess().ship_address_attributes).not.toBe(undefined)
|
||||
expect(Order.preprocess().ship_address).toBe(undefined)
|
||||
|
||||
it "Munges the order attributes to clone ship address from bill address", ->
|
||||
CheckoutFormState.ship_address_same_as_billing = false
|
||||
expect(Order.preprocess().ship_address_attributes).toEqual(orderData.ship_address)
|
||||
CheckoutFormState.ship_address_same_as_billing = true
|
||||
expect(Order.preprocess().ship_address_attributes).toEqual(orderData.bill_address)
|
||||
@@ -0,0 +1,37 @@
|
||||
describe "Sidebar", ->
|
||||
location = null
|
||||
Sidebar = null
|
||||
Navigation = null
|
||||
|
||||
beforeEach ->
|
||||
module("Darkswarm")
|
||||
inject (_Sidebar_, $location, _Navigation_) ->
|
||||
Sidebar = _Sidebar_
|
||||
Navigation = _Navigation_
|
||||
location = $location
|
||||
Sidebar.paths = ["/test", "/frogs"]
|
||||
|
||||
|
||||
it 'is active when a location in paths is set', ->
|
||||
spyOn(location, "path").andReturn "/test"
|
||||
expect(Sidebar.active()).toEqual true
|
||||
|
||||
it 'is inactive if location is set', ->
|
||||
spyOn(location, "path").andReturn null
|
||||
expect(Sidebar.active()).toEqual false
|
||||
|
||||
describe "Toggling on/off", ->
|
||||
it 'toggles the current sidebar path', ->
|
||||
expect(Sidebar.active()).toEqual false
|
||||
Navigation.path = "/frogs"
|
||||
Sidebar.toggle()
|
||||
expect(Sidebar.active()).toEqual true
|
||||
|
||||
it 'If current navigation path is not in the sidebar, it toggles the first sidebar path', ->
|
||||
Navigation.path = "/donkeys"
|
||||
spyOn(Navigation, 'navigate')
|
||||
Sidebar.toggle()
|
||||
expect(Navigation.navigate).toHaveBeenCalledWith("/test")
|
||||
|
||||
|
||||
|
||||
@@ -401,10 +401,12 @@ describe 'OrderCycle services', ->
|
||||
it 'loads enterprise fees', ->
|
||||
enterprise_fees = EnterpriseFee.index()
|
||||
$httpBackend.flush()
|
||||
expect(enterprise_fees).toEqual [
|
||||
expected_fees = [
|
||||
new EnterpriseFee.EnterpriseFee({id: 1, name: "Yayfee", enterprise_id: 1})
|
||||
new EnterpriseFee.EnterpriseFee({id: 2, name: "FeeTwo", enterprise_id: 2})
|
||||
]
|
||||
for fee, i in enterprise_fees
|
||||
expect(fee.id).toEqual(expected_fees[i].id)
|
||||
|
||||
it 'reports its loadedness', ->
|
||||
expect(EnterpriseFee.loaded).toBe(false)
|
||||
@@ -828,4 +830,4 @@ describe 'OrderCycle services', ->
|
||||
expect(order_cycle.outgoing_exchanges[0].enterprise_fees).toEqual [{id: 3}, {id: 4}]
|
||||
expect(order_cycle.incoming_exchanges[0].enterprise_fee_ids).toBeUndefined()
|
||||
expect(order_cycle.outgoing_exchanges[0].enterprise_fee_ids).toBeUndefined()
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user