mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-05 22:26:07 +00:00
When a registering an enterprise with a non-unique name, display an error message.
This commit is contained in:
@@ -26,7 +26,11 @@ Darkswarm.factory "EnterpriseRegistrationService", ($http, RegistrationService,
|
||||
RegistrationService.select('about')
|
||||
).error((data) =>
|
||||
Loading.clear()
|
||||
alert('Failed to create your enterprise.\nPlease ensure all fields are completely filled out.')
|
||||
if data?.errors?
|
||||
errors = ("#{k.capitalize()} #{v[0]}" for k, v of data.errors when v.length > 0)
|
||||
alert "Failed to create your enterprise.\n" + errors.join('\n')
|
||||
else
|
||||
alert('Failed to create your enterprise.\nPlease ensure all fields are completely filled out.')
|
||||
)
|
||||
# RegistrationService.select('about')
|
||||
|
||||
|
||||
2
app/assets/javascripts/darkswarm/util.js.coffee
Normal file
2
app/assets/javascripts/darkswarm/util.js.coffee
Normal file
@@ -0,0 +1,2 @@
|
||||
String.prototype.capitalize = ->
|
||||
this.charAt(0).toUpperCase() + this.slice(1)
|
||||
@@ -56,6 +56,20 @@ describe "EnterpriseRegistrationService", ->
|
||||
it "does not move the user to the about page", ->
|
||||
expect(RegistrationServiceMock.select).not.toHaveBeenCalled
|
||||
|
||||
describe "failure due to duplicate name", ->
|
||||
beforeEach ->
|
||||
spyOn(RegistrationServiceMock, "select")
|
||||
spyOn(window, "alert")
|
||||
$httpBackend.expectPOST("/api/enterprises?token=keykeykeykey").respond 400, {"error": "Invalid resource. Please fix errors and try again.", "errors": {"name": ["has already been taken. If this is your enterprise and you would like to claim ownership, please contact the current manager of this profile at owner@example.com."], "permalink": [] }}
|
||||
EnterpriseRegistrationService.create()
|
||||
$httpBackend.flush()
|
||||
|
||||
it "alerts the user to failure", ->
|
||||
expect(window.alert).toHaveBeenCalledWith 'Failed to create your enterprise.\nName has already been taken. If this is your enterprise and you would like to claim ownership, please contact the current manager of this profile at owner@example.com.'
|
||||
|
||||
it "does not move the user to the about page", ->
|
||||
expect(RegistrationServiceMock.select).not.toHaveBeenCalled
|
||||
|
||||
|
||||
describe "updating an enterprise", ->
|
||||
beforeEach ->
|
||||
|
||||
Reference in New Issue
Block a user