-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
133 additions
and
156 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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
109 changes: 0 additions & 109 deletions
109
api/tests/acceptance/application/account-recovery/account-recovery-route_test.js
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
|
@@ -138,4 +138,103 @@ describe('Acceptance | Identity Access Management | Application | Route | accoun | |
}); | ||
}); | ||
}); | ||
|
||
describe('POST /api/account-recovery', function () { | ||
const studentInformation = { | ||
ineIna: '123456789aa', | ||
firstName: 'Jude', | ||
lastName: 'Law', | ||
birthdate: '2016-06-01', | ||
}; | ||
|
||
const createUserWithSeveralOrganizationLearners = async ({ email = '[email protected]' } = {}) => { | ||
const user = databaseBuilder.factory.buildUser.withRawPassword({ | ||
id: 8, | ||
firstName: 'Judy', | ||
lastName: 'Howl', | ||
email, | ||
username: 'jude.law0601', | ||
}); | ||
const organization = databaseBuilder.factory.buildOrganization({ | ||
id: 7, | ||
name: 'Collège Hollywoodien', | ||
}); | ||
const latestOrganization = databaseBuilder.factory.buildOrganization({ | ||
id: 2, | ||
name: 'Super Collège Hollywoodien', | ||
}); | ||
databaseBuilder.factory.buildOrganizationLearner({ | ||
userId: user.id, | ||
...studentInformation, | ||
nationalStudentId: studentInformation.ineIna.toUpperCase(), | ||
organizationId: organization.id, | ||
updatedAt: new Date('2005-01-01T15:00:00Z'), | ||
}); | ||
databaseBuilder.factory.buildOrganizationLearner({ | ||
userId: user.id, | ||
...studentInformation, | ||
nationalStudentId: studentInformation.ineIna.toUpperCase(), | ||
organizationId: latestOrganization.id, | ||
updatedAt: new Date('2010-01-01T15:00:00Z'), | ||
}); | ||
await databaseBuilder.commit(); | ||
}; | ||
|
||
it('returns 204 HTTP status code', async function () { | ||
// given | ||
await createUserWithSeveralOrganizationLearners(); | ||
const newEmail = '[email protected]'; | ||
|
||
const options = { | ||
method: 'POST', | ||
url: '/api/account-recovery', | ||
payload: { | ||
data: { | ||
attributes: { | ||
'ine-ina': studentInformation.ineIna, | ||
'first-name': studentInformation.firstName, | ||
'last-name': studentInformation.lastName, | ||
birthdate: studentInformation.birthdate, | ||
email: newEmail, | ||
}, | ||
}, | ||
}, | ||
}; | ||
|
||
// when | ||
const response = await server.inject(options); | ||
|
||
// then | ||
expect(response.statusCode).to.equal(204); | ||
}); | ||
|
||
it('returns 400 if email already exists', async function () { | ||
// given | ||
const newEmail = '[email protected]'; | ||
await createUserWithSeveralOrganizationLearners({ email: newEmail }); | ||
|
||
const options = { | ||
method: 'POST', | ||
url: '/api/account-recovery', | ||
payload: { | ||
data: { | ||
attributes: { | ||
'ine-ina': studentInformation.ineIna, | ||
'first-name': studentInformation.firstName, | ||
'last-name': studentInformation.lastName, | ||
birthdate: studentInformation.birthdate, | ||
email: newEmail, | ||
}, | ||
}, | ||
}, | ||
}; | ||
|
||
// when | ||
const response = await server.inject(options); | ||
|
||
// then | ||
expect(response.statusCode).to.equal(400); | ||
expect(response.result.errors[0].detail).to.equal('Cette adresse e-mail est déjà utilisée.'); | ||
}); | ||
}); | ||
}); |