mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-05 22:26:07 +00:00
Merge pull request #4780 from luisramos0/bulk_prod_errors
Fix javascript logic that parses server errors in the bulk product edit page
This commit is contained in:
@@ -710,13 +710,22 @@ describe "AdminProductEditCtrl", ->
|
||||
$httpBackend.flush()
|
||||
expect($scope.displayFailure).toHaveBeenCalled()
|
||||
|
||||
it "shows an alert with error information when post returns 400 with an errors array", ->
|
||||
spyOn(window, "alert")
|
||||
$scope.products = "updated list of products"
|
||||
$httpBackend.expectPOST("/admin/products/bulk_update").respond 400, { "errors": ["an error"] }
|
||||
$scope.updateProducts "updated list of products"
|
||||
$httpBackend.flush()
|
||||
expect(window.alert).toHaveBeenCalledWith("Saving failed with the following error(s):\nan error\n")
|
||||
describe "displaying the error information when post returns 400", ->
|
||||
beforeEach ->
|
||||
spyOn $scope, "displayFailure"
|
||||
$scope.products = "updated list of products"
|
||||
|
||||
it "displays errors in an array", ->
|
||||
$httpBackend.expectPOST("/admin/products/bulk_update").respond 400, { "errors": ["an error"] }
|
||||
$scope.updateProducts "updated list of products"
|
||||
$httpBackend.flush()
|
||||
expect($scope.displayFailure).toHaveBeenCalledWith("Saving failed with the following error(s):\nan error\n")
|
||||
|
||||
it "displays errors in a hash", ->
|
||||
$httpBackend.expectPOST("/admin/products/bulk_update").respond 400, { "errors": { "base": ["a basic error"] } }
|
||||
$scope.updateProducts "updated list of products"
|
||||
$httpBackend.flush()
|
||||
expect($scope.displayFailure).toHaveBeenCalledWith("Saving failed with the following error(s):\na basic error\n")
|
||||
|
||||
|
||||
describe "adding variants", ->
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
describe "ErrorsParser service", ->
|
||||
errorsParser = null
|
||||
|
||||
beforeEach ->
|
||||
module('admin.utils')
|
||||
inject (ErrorsParser) ->
|
||||
errorsParser = ErrorsParser
|
||||
|
||||
describe "toString", ->
|
||||
it "returns empty string for nil errors", ->
|
||||
expect(errorsParser.toString(null)).toEqual ""
|
||||
|
||||
it "returns the elements in the array if an array is provided", ->
|
||||
expect(errorsParser.toString(["1", "2"])).toEqual "1\n2\n"
|
||||
|
||||
it "returns the elements in the hash if a hash is provided", ->
|
||||
expect(errorsParser.toString({ "keyname": ["1", "2"] })).toEqual "1\n2\n"
|
||||
|
||||
it "returns all elements in all hash keys provided", ->
|
||||
expect(errorsParser.toString({ "keyname1": ["1", "2"], "keyname2": ["3", "4"] })).toEqual "1\n2\n3\n4\n"
|
||||
Reference in New Issue
Block a user