When a registering an enterprise with a non-unique name, display an error message.

This commit is contained in:
Rohan Mitchell
2015-06-24 10:08:34 +10:00
parent c5526c78d9
commit 2d79177bb5
3 changed files with 21 additions and 1 deletions

View File

@@ -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')

View File

@@ -0,0 +1,2 @@
String.prototype.capitalize = ->
this.charAt(0).toUpperCase() + this.slice(1)

View File

@@ -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 ->