mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-04 22:16:08 +00:00
Merge branch 'master' into customers
Conflicts: app/assets/javascripts/admin/bulk_order_management.js.coffee app/assets/javascripts/admin/bulk_product_update.js.coffee app/assets/javascripts/admin/directives/line_item_upd_attr.js.coffee app/views/spree/admin/orders/bulk_management.html.haml db/schema.rb spec/javascripts/unit/bulk_order_management_spec.js.coffee
This commit is contained in:
@@ -0,0 +1,67 @@
|
||||
describe "unitsCtrl", ->
|
||||
ctrl = null
|
||||
scope = null
|
||||
product = null
|
||||
|
||||
beforeEach ->
|
||||
module('admin.products')
|
||||
inject ($rootScope, $controller, VariantUnitManager) ->
|
||||
scope = $rootScope
|
||||
ctrl = $controller 'unitsCtrl', {$scope: scope, VariantUnitManager: VariantUnitManager}
|
||||
|
||||
describe "interpretting variant_unit_with_scale", ->
|
||||
it "splits string with one underscore and stores the two parts", ->
|
||||
scope.product.variant_unit_with_scale = "weight_1000"
|
||||
scope.processVariantUnitWithScale()
|
||||
expect(scope.product.variant_unit).toEqual "weight"
|
||||
expect(scope.product.variant_unit_scale).toEqual 1000
|
||||
|
||||
it "interprets strings with no underscore as variant_unit", ->
|
||||
scope.product.variant_unit_with_scale = "items"
|
||||
scope.processVariantUnitWithScale()
|
||||
expect(scope.product.variant_unit).toEqual "items"
|
||||
expect(scope.product.variant_unit_scale).toEqual null
|
||||
|
||||
it "sets variant_unit and variant_unit_scale to null", ->
|
||||
scope.product.variant_unit_with_scale = null
|
||||
scope.processVariantUnitWithScale()
|
||||
expect(scope.product.variant_unit).toEqual null
|
||||
expect(scope.product.variant_unit_scale).toEqual null
|
||||
|
||||
describe "interpretting unit_value_with_description", ->
|
||||
beforeEach ->
|
||||
scope.product.master = {}
|
||||
|
||||
describe "when a variant_unit_scale is present", ->
|
||||
beforeEach ->
|
||||
scope.product.variant_unit_scale = 1
|
||||
|
||||
it "splits by whitespace in to unit_value and unit_description", ->
|
||||
scope.product.master.unit_value_with_description = "12 boxes"
|
||||
scope.processUnitValueWithDescription()
|
||||
expect(scope.product.master.unit_value).toEqual 12
|
||||
expect(scope.product.master.unit_description).toEqual "boxes"
|
||||
|
||||
it "uses whole string as unit_value when only numerical characters are present", ->
|
||||
scope.product.master.unit_value_with_description = "12345"
|
||||
scope.processUnitValueWithDescription()
|
||||
expect(scope.product.master.unit_value).toEqual 12345
|
||||
expect(scope.product.master.unit_description).toEqual ''
|
||||
|
||||
it "uses whole string as description when string does not start with a number", ->
|
||||
scope.product.master.unit_value_with_description = "boxes 12"
|
||||
scope.processUnitValueWithDescription()
|
||||
expect(scope.product.master.unit_value).toEqual null
|
||||
expect(scope.product.master.unit_description).toEqual "boxes 12"
|
||||
|
||||
it "does not require whitespace to split unit value and description", ->
|
||||
scope.product.master.unit_value_with_description = "12boxes"
|
||||
scope.processUnitValueWithDescription()
|
||||
expect(scope.product.master.unit_value).toEqual 12
|
||||
expect(scope.product.master.unit_description).toEqual "boxes"
|
||||
|
||||
it "once a whitespace occurs, all subsequent numerical characters are counted as description", ->
|
||||
scope.product.master.unit_value_with_description = "123 54 boxes"
|
||||
scope.processUnitValueWithDescription()
|
||||
expect(scope.product.master.unit_value).toEqual 123
|
||||
expect(scope.product.master.unit_description).toEqual "54 boxes"
|
||||
@@ -61,14 +61,14 @@ describe "BulkProducts service", ->
|
||||
clonedProduct =
|
||||
id: 17
|
||||
|
||||
spyOn(BulkProducts, "addProducts")
|
||||
spyOn(BulkProducts, "insertProductAfter")
|
||||
BulkProducts.products = [originalProduct]
|
||||
$httpBackend.expectGET("/admin/products/oranges/clone.json").respond 200,
|
||||
product: clonedProduct
|
||||
$httpBackend.expectGET("/api/products/17?template=bulk_show").respond 200, clonedProduct
|
||||
BulkProducts.cloneProduct BulkProducts.products[0]
|
||||
$httpBackend.flush()
|
||||
expect(BulkProducts.addProducts).toHaveBeenCalledWith [clonedProduct]
|
||||
expect(BulkProducts.insertProductAfter).toHaveBeenCalledWith originalProduct, clonedProduct
|
||||
|
||||
|
||||
describe "preparing products", ->
|
||||
|
||||
@@ -22,8 +22,8 @@ describe "AdminOrderMgmtCtrl", ->
|
||||
returnedOrderCycles = [ "oc1", "oc2", "oc3" ]
|
||||
httpBackend.expectGET("/api/users/authorise_api?token=API_KEY").respond success: "Use of API Authorised"
|
||||
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
|
||||
httpBackend.expectGET("/api/enterprises/accessible?template=bulk_index&q[sells_in][]=own&q[sells_in][]=any").respond returnedDistributors
|
||||
httpBackend.expectGET("/api/order_cycles/accessible?as=distributor&q[orders_close_at_gt]=SomeDate").respond returnedOrderCycles
|
||||
spyOn(scope, "initialiseVariables").andCallThrough()
|
||||
spyOn(scope, "fetchOrders").andReturn "nothing"
|
||||
#spyOn(returnedSuppliers, "unshift")
|
||||
@@ -43,7 +43,7 @@ describe "AdminOrderMgmtCtrl", ->
|
||||
describe "fetching orders", ->
|
||||
beforeEach ->
|
||||
scope.initialiseVariables()
|
||||
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"
|
||||
httpBackend.expectGET("/admin/orders/managed?template=bulk_index;page=1;per_page=500;q[state_not_eq]=canceled;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()
|
||||
@@ -350,6 +350,32 @@ describe "AdminOrderMgmtCtrl", ->
|
||||
spyOn(VariantUnitManager, "getUnitName").andReturn "kg"
|
||||
expect(scope.formattedValueWithUnitName(2000,unitsVariant)).toEqual "2 kg"
|
||||
|
||||
describe "updating the price upon updating the weight of a line item", ->
|
||||
|
||||
it "resets the weight if the weight is set to zero", ->
|
||||
scope.filteredLineItems = [
|
||||
{ units_variant: { unit_value: 100 }, price: 2, unit_value: 0 }
|
||||
]
|
||||
expect(scope.weightAdjustedPrice(scope.filteredLineItems[0], 100)).toEqual scope.filteredLineItems[0].price
|
||||
|
||||
it "updates the price if the weight is changed", ->
|
||||
scope.filteredLineItems = [
|
||||
{ units_variant: { unit_value: 100 }, price: 2, unit_value: 200 }
|
||||
]
|
||||
old_value = scope.filteredLineItems[0].units_variant.unit_value
|
||||
new_value = scope.filteredLineItems[0].unit_value
|
||||
sp = scope.filteredLineItems[0].price * new_value / old_value
|
||||
expect(scope.weightAdjustedPrice(scope.filteredLineItems[0], old_value)).toEqual sp
|
||||
|
||||
it "doesn't update the price if the weight is not changed", ->
|
||||
scope.filteredLineItems = [
|
||||
{ units_variant: { unit_value: 100 }, price: 2, unit_value: 100 }
|
||||
]
|
||||
old_value = scope.filteredLineItems[0].unit_value
|
||||
new_value = scope.filteredLineItems[0].unit_value
|
||||
sp = scope.filteredLineItems[0].price
|
||||
expect(scope.weightAdjustedPrice(scope.filteredLineItems[0], old_value)).toEqual sp
|
||||
|
||||
describe "Auxiliary functions", ->
|
||||
describe "getting a zero filled two digit number", ->
|
||||
it "returns the number as a string if its value is greater than or equal to 10", ->
|
||||
|
||||
@@ -215,6 +215,7 @@ describe "filtering products for submission to database", ->
|
||||
variant_unit_scale: 1
|
||||
variant_unit_name: 'loaf'
|
||||
available_on: available_on
|
||||
tax_category_id: null
|
||||
master_attributes:
|
||||
id: 2
|
||||
unit_value: 250
|
||||
@@ -238,6 +239,7 @@ describe "AdminProductEditCtrl", ->
|
||||
module ($provide)->
|
||||
$provide.value "producers", []
|
||||
$provide.value "taxons", []
|
||||
$provide.value "tax_categories", []
|
||||
$provide.value 'SpreeApiKey', 'API_KEY'
|
||||
null
|
||||
|
||||
@@ -777,22 +779,31 @@ describe "AdminProductEditCtrl", ->
|
||||
|
||||
|
||||
describe "deleting variants", ->
|
||||
describe "when the variant is the only one left on the product", ->
|
||||
it "alerts the user", ->
|
||||
spyOn(window, "alert")
|
||||
$scope.products = [
|
||||
{id: 1, variants: [{id: 1}]}
|
||||
]
|
||||
$scope.deleteVariant $scope.products[0], $scope.products[0].variants[0]
|
||||
expect(window.alert).toHaveBeenCalledWith "The last variant cannot be deleted!"
|
||||
|
||||
describe "when the variant has not been saved", ->
|
||||
it "removes the variant from products and dirtyProducts", ->
|
||||
spyOn(window, "confirm").andReturn true
|
||||
$scope.products = [
|
||||
{id: 1, variants: [{id: -1}]}
|
||||
{id: 1, variants: [{id: -1},{id: -2}]}
|
||||
]
|
||||
DirtyProducts.addVariantProperty 1, -1, "something", "something"
|
||||
DirtyProducts.addProductProperty 1, "something", "something"
|
||||
$scope.deleteVariant $scope.products[0], $scope.products[0].variants[0]
|
||||
expect($scope.products).toEqual([
|
||||
{id: 1, variants: []}
|
||||
{id: 1, variants: [{id: -2}]}
|
||||
])
|
||||
expect(DirtyProducts.all()).toEqual
|
||||
1: { id: 1, something: 'something'}
|
||||
|
||||
|
||||
|
||||
describe "when the variant has been saved", ->
|
||||
it "deletes variants with a http delete request to /api/products/product_permalink/variants/(variant_id)/soft_delete", ->
|
||||
spyOn(window, "confirm").andReturn true
|
||||
@@ -800,9 +811,14 @@ describe "AdminProductEditCtrl", ->
|
||||
{
|
||||
id: 9
|
||||
permalink_live: "apples"
|
||||
variants: [
|
||||
variants: [{
|
||||
id: 3
|
||||
price: 12
|
||||
},
|
||||
{
|
||||
id: 4
|
||||
price: 15
|
||||
}
|
||||
]
|
||||
}
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user