[Fix] Don't save user to DB when a custom field is invalid #7513
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
@RocketChat/core
To avoid a huge PR, this is the first PR of a series to fix issues with registration. This one deals with the API.
The problem is
Accounts.createUser
gets called before the customFields are validated and it inserts the user into the DB. Correcting the customFields and trying to create the user again will fail withemail already exists
. The same issue is present in the UI (I have another PR for it)Due to a limitation in Mocha, as described here https://demo.rocket.chat/channel/dev?msg=gHB4Gj2P9gN7zCm4c, the
it
are wrapped withdescribe
. I think it's a good restructure as it will make adding fail cases easier in the future.