-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Show custom alert message for duplicate email address (#912)
Closes getodk/central#144.
- Loading branch information
1 parent
ecc02c9
commit 294323e
Showing
5 changed files
with
130 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -96,6 +96,51 @@ describe('UserEditBasicDetails', () => { | |
}); | ||
}); | ||
|
||
describe('custom alert messages', () => { | ||
beforeEach(() => { | ||
mockLogin({ email: '[email protected]' }); | ||
}); | ||
|
||
it('shows a custom message for a duplicate email', () => | ||
mockHttp() | ||
.mount(UserEditBasicDetails, mountOptions()) | ||
.request(async (component) => { | ||
await component.get('input[type="email"]').setValue('[email protected]'); | ||
return component.get('form').trigger('submit'); | ||
}) | ||
.respondWithProblem({ | ||
code: 409.3, | ||
message: 'A resource already exists with email,deleted value(s) of [email protected],false.', | ||
details: { | ||
fields: ['email', 'deleted'], | ||
values: ['[email protected]', false] | ||
} | ||
}) | ||
.afterResponse(modal => { | ||
modal.should.alert('danger', (message) => { | ||
message.should.startWith('You cannot change your email to [email protected]'); | ||
}); | ||
})); | ||
|
||
// I don't think a different uniqueness violation is currently possible. | ||
// This is mostly about future-proofing. | ||
it('shows the default message for a different uniqueness violation', () => | ||
mockHttp() | ||
.mount(UserEditBasicDetails, mountOptions()) | ||
.request(async (component) => { | ||
await component.get('input[type="email"]').setValue('[email protected]'); | ||
return component.get('form').trigger('submit'); | ||
}) | ||
.respondWithProblem({ | ||
code: 409.3, | ||
message: 'A resource already exists with foo value(s) of bar.', | ||
details: { fields: ['foo'], values: ['bar'] } | ||
}) | ||
.afterResponse(modal => { | ||
modal.should.alert('danger', 'A resource already exists with foo value(s) of bar.'); | ||
})); | ||
}); | ||
|
||
describe('after a successful response', () => { | ||
beforeEach(() => { | ||
mockLogin({ displayName: 'Old Name' }); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -69,12 +69,12 @@ describe('UserNew', () => { | |
await modal.get('input[type="email"]').setValue('[email protected]'); | ||
return modal.get('form').trigger('submit'); | ||
}) | ||
.beforeEachResponse((_, { method, url, data }) => { | ||
method.should.equal('POST'); | ||
url.should.equal('/v1/users'); | ||
data.should.eql({ email: '[email protected]' }); | ||
}) | ||
.respondWithProblem()); | ||
.respondWithProblem() | ||
.testRequests([{ | ||
method: 'POST', | ||
url: '/v1/users', | ||
data: { email: '[email protected]' } | ||
}])); | ||
|
||
it('sends the display name if there is one', () => | ||
mockHttp() | ||
|
@@ -107,6 +107,51 @@ describe('UserNew', () => { | |
modal: true | ||
})); | ||
|
||
describe('custom alert messages', () => { | ||
it('shows a custom message for a duplicate email', () => | ||
mockHttp() | ||
.mount(UserNew, { | ||
props: { state: true } | ||
}) | ||
.request(async (modal) => { | ||
await modal.get('input[type="email"]').setValue('[email protected]'); | ||
return modal.get('form').trigger('submit'); | ||
}) | ||
.respondWithProblem({ | ||
code: 409.3, | ||
message: 'A resource already exists with email,deleted value(s) of [email protected],false.', | ||
details: { | ||
fields: ['email', 'deleted'], | ||
values: ['[email protected]', false] | ||
} | ||
}) | ||
.afterResponse(modal => { | ||
modal.should.alert('danger', (message) => { | ||
message.should.startWith('It looks like [email protected] already has an account.'); | ||
}); | ||
})); | ||
|
||
// I don't think a different uniqueness violation is currently possible. | ||
// This is mostly about future-proofing. | ||
it('shows the default message for a different uniqueness violation', () => | ||
mockHttp() | ||
.mount(UserNew, { | ||
props: { state: true } | ||
}) | ||
.request(async (modal) => { | ||
await modal.get('input[type="email"]').setValue('[email protected]'); | ||
return modal.get('form').trigger('submit'); | ||
}) | ||
.respondWithProblem({ | ||
code: 409.3, | ||
message: 'A resource already exists with foo value(s) of bar.', | ||
details: { fields: ['foo'], values: ['bar'] } | ||
}) | ||
.afterResponse(modal => { | ||
modal.should.alert('danger', 'A resource already exists with foo value(s) of bar.'); | ||
})); | ||
}); | ||
|
||
describe('after a successful response', () => { | ||
const submitWithSuccess = () => load('/users', { root: false }) | ||
.complete() | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters