This repository has been archived by the owner on Aug 5, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Ajoute la fonctionnalité : maj de l'adresse principale (#971)
* Added update primary email api * Added interface to change primary email * Refacto canChangeSecondaryEmail/canChangePrimaryEmail to one boolean * Update src/controllers/usersController.ts Co-authored-by: Alejandro M Guillén <[email protected]> Co-authored-by: Alejandro M Guillén <[email protected]>
- Loading branch information
1 parent
33991df
commit 07641a9
Showing
8 changed files
with
155 additions
and
17 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
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
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 |
---|---|---|
|
@@ -600,9 +600,6 @@ describe('User', () => { | |
done(); | ||
}); | ||
|
||
// fixme: this test test nothing since it fail silently on chai.request | ||
// because user.canChangeSecondaryEmail is false. It should be tested with | ||
// a valid BetaGouvUser | ||
it('should add secondary email', async () => { | ||
const username = 'membre.nouveau'; | ||
const secondaryEmail = '[email protected]'; | ||
|
@@ -637,11 +634,6 @@ describe('User', () => { | |
.update({ | ||
secondary_email: secondaryEmail, | ||
}) | ||
const dbRes = await knex('users') | ||
.select() | ||
.where({ username }) | ||
.first() | ||
dbRes.secondary_email.should.equal(secondaryEmail); | ||
await chai.request(app) | ||
.post(`/users/${username}/secondary_email/`) | ||
.set('Cookie', `token=${utils.getJWT('membre.nouveau')}`) | ||
|
@@ -657,6 +649,72 @@ describe('User', () => { | |
secondary_email: null | ||
}) | ||
}); | ||
|
||
it('should not update primary email if user is not current user', async() => { | ||
const username = 'membre.nouveau'; | ||
const primaryEmail = '[email protected]'; | ||
const isPublicServiceEmailStub = sinon | ||
.stub(controllerUtils, 'isPublicServiceEmail') | ||
.returns(Promise.resolve(false)); | ||
|
||
await chai.request(app) | ||
.post(`/users/${username}/primary_email/`) | ||
.set('Cookie', `token=${utils.getJWT('julien.dauphant')}`) | ||
.type('form') | ||
.send({ | ||
username, | ||
primaryEmail: primaryEmail, | ||
}); | ||
isPublicServiceEmailStub.called.should.be.false; | ||
isPublicServiceEmailStub.restore(); | ||
}); | ||
|
||
it('should not update primary email if email is not public service email', async() => { | ||
const isPublicServiceEmailStub = sinon | ||
.stub(controllerUtils, 'isPublicServiceEmail') | ||
.returns(Promise.resolve(false)); | ||
const username = 'membre.nouveau'; | ||
const primaryEmail = '[email protected]'; | ||
|
||
await chai.request(app) | ||
.post(`/users/${username}/primary_email/`) | ||
.type('form') | ||
.set('Cookie', `token=${utils.getJWT('membre.nouveau')}`) | ||
.send({ | ||
username, | ||
primaryEmail: primaryEmail, | ||
}); | ||
const dbNewRes = await knex('users').select().where({ username: 'membre.nouveau' }) | ||
dbNewRes.length.should.equal(1); | ||
dbNewRes[0].primary_email.should.not.equal(primaryEmail); | ||
isPublicServiceEmailStub.called.should.be.true; | ||
isPublicServiceEmailStub.restore() | ||
}); | ||
|
||
it('should update primary email', async() => { | ||
const isPublicServiceEmailStub = sinon | ||
.stub(controllerUtils, 'isPublicServiceEmail') | ||
.returns(Promise.resolve(true)); | ||
const username = 'membre.nouveau'; | ||
const primaryEmail = '[email protected]'; | ||
|
||
await chai.request(app) | ||
.post(`/users/${username}/primary_email/`) | ||
.type('form') | ||
.set('Cookie', `token=${utils.getJWT('membre.nouveau')}`) | ||
.send({ | ||
username, | ||
primaryEmail: primaryEmail, | ||
}); | ||
const dbNewRes = await knex('users').select().where({ username: 'membre.nouveau' }) | ||
dbNewRes.length.should.equal(1); | ||
dbNewRes[0].primary_email.should.equal(primaryEmail); | ||
await knex('users').where({ username: 'membre.nouveau' }).update({ | ||
primary_email: `${username}@${config.domain}` | ||
}) | ||
isPublicServiceEmailStub.called.should.be.true; | ||
isPublicServiceEmailStub.restore() | ||
}); | ||
}); | ||
|
||
describe('POST /users/:username/redirections/:email/delete authenticated', () => { | ||
|
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