-
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.
[TECH] Mettre à jour des tests suite à la suppression de Bookshelf (P…
- Loading branch information
Showing
5 changed files
with
78 additions
and
138 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 |
---|---|---|
|
@@ -54,6 +54,17 @@ describe('Integration | Identity Access Management | Infrastructure | Repository | |
let membershipInDB; | ||
let certificationCenterInDB; | ||
|
||
let clock; | ||
const now = new Date('2022-12-24'); | ||
|
||
beforeEach(function () { | ||
clock = sinon.useFakeTimers({ now, toFake: ['Date'] }); | ||
}); | ||
|
||
afterEach(function () { | ||
clock.restore(); | ||
}); | ||
|
||
function _insertUserWithOrganizationsAndCertificationCenterAccesses() { | ||
organizationInDB = databaseBuilder.factory.buildOrganization({ | ||
type: 'PRO', | ||
|
@@ -797,7 +808,6 @@ describe('Integration | Identity Access Management | Infrastructure | Repository | |
|
||
it('should only return actives certification center membership associated to the user', async function () { | ||
// given | ||
const now = new Date(); | ||
const email = '[email protected]'; | ||
const user = databaseBuilder.factory.buildUser({ email }); | ||
const certificationCenter = databaseBuilder.factory.buildCertificationCenter(); | ||
|
@@ -1076,20 +1086,20 @@ describe('Integration | Identity Access Management | Infrastructure | Repository | |
describe('#getUserDetailsForAdmin', function () { | ||
it('should return the found user', async function () { | ||
// given | ||
const createdAt = new Date('2021-01-01'); | ||
const emailConfirmedAt = new Date('2022-01-01'); | ||
const lastTermsOfServiceValidatedAt = new Date('2022-01-02'); | ||
const lastPixOrgaTermsOfServiceValidatedAt = new Date('2022-01-03'); | ||
const lastLoggedAt = new Date('2022-01-04'); | ||
const now = new Date(); | ||
const userInDB = databaseBuilder.factory.buildUser({ | ||
firstName: 'Henri', | ||
lastName: 'Cochet', | ||
email: '[email protected]', | ||
cgu: true, | ||
lang: 'en', | ||
locale: 'en', | ||
createdAt: now, | ||
updatedAt: now, | ||
createdAt, | ||
updatedAt: createdAt, | ||
lastTermsOfServiceValidatedAt, | ||
lastPixOrgaTermsOfServiceValidatedAt, | ||
lastPixCertifTermsOfServiceValidatedAt: lastLoggedAt, | ||
|
@@ -1108,8 +1118,8 @@ describe('Integration | Identity Access Management | Infrastructure | Repository | |
expect(userDetailsForAdmin.lastName).to.equal('Cochet'); | ||
expect(userDetailsForAdmin.email).to.equal('[email protected]'); | ||
expect(userDetailsForAdmin.cgu).to.be.true; | ||
expect(userDetailsForAdmin.createdAt).to.deep.equal(now); | ||
expect(userDetailsForAdmin.updatedAt).to.deep.equal(now); | ||
expect(userDetailsForAdmin.createdAt).to.deep.equal(createdAt); | ||
expect(userDetailsForAdmin.updatedAt).to.deep.equal(createdAt); | ||
expect(userDetailsForAdmin.lang).to.equal('en'); | ||
expect(userDetailsForAdmin.locale).to.equal('en'); | ||
expect(userDetailsForAdmin.lastTermsOfServiceValidatedAt).to.deep.equal(lastTermsOfServiceValidatedAt); | ||
|
@@ -1315,17 +1325,6 @@ describe('Integration | Identity Access Management | Infrastructure | Repository | |
}); | ||
|
||
context('when user has login details', function () { | ||
let clock; | ||
const now = new Date('2022-02-02'); | ||
|
||
beforeEach(function () { | ||
clock = sinon.useFakeTimers({ now, toFake: ['Date'] }); | ||
}); | ||
|
||
afterEach(function () { | ||
clock.restore(); | ||
}); | ||
|
||
it('should return the user with his login details', async function () { | ||
// given | ||
const userInDB = databaseBuilder.factory.buildUser(userToInsert); | ||
|
@@ -1372,17 +1371,6 @@ describe('Integration | Identity Access Management | Infrastructure | Repository | |
|
||
describe('update user', function () { | ||
describe('#update', function () { | ||
let clock; | ||
const now = new Date('2021-01-02'); | ||
|
||
beforeEach(function () { | ||
clock = sinon.useFakeTimers({ now, toFake: ['Date'] }); | ||
}); | ||
|
||
afterEach(function () { | ||
clock.restore(); | ||
}); | ||
|
||
it('updates the given properties', async function () { | ||
// given | ||
const user = databaseBuilder.factory.buildUser(); | ||
|
@@ -1393,7 +1381,7 @@ describe('Integration | Identity Access Management | Infrastructure | Repository | |
const fetchedUser = await knex.from('users').where({ id: user.id }).first(); | ||
|
||
// then | ||
expect(fetchedUser.updatedAt).to.deep.equal(new Date('2021-01-02')); | ||
expect(fetchedUser.updatedAt).to.deep.equal(now); | ||
expect(fetchedUser.email).to.equal('[email protected]'); | ||
expect(fetchedUser.locale).to.equal('fr-BE'); | ||
}); | ||
|
@@ -1412,21 +1400,11 @@ describe('Integration | Identity Access Management | Infrastructure | Repository | |
// then | ||
expect(updatedUser).to.be.an.instanceOf(User); | ||
expect(updatedUser.email).to.equal(newEmail); | ||
expect(updatedUser.updatedAt).to.deep.equal(now); | ||
}); | ||
}); | ||
|
||
describe('#updateEmailConfirmed', function () { | ||
let clock; | ||
const now = new Date('2022-02-02'); | ||
|
||
beforeEach(function () { | ||
clock = sinon.useFakeTimers({ now, toFake: ['Date'] }); | ||
}); | ||
|
||
afterEach(function () { | ||
clock.restore(); | ||
}); | ||
|
||
it('marks the users’ email as confirmed by updating "emailConfirmedAt" to current date', async function () { | ||
// given | ||
const userId = databaseBuilder.factory.buildUser({ | ||
|
@@ -1443,6 +1421,7 @@ describe('Integration | Identity Access Management | Infrastructure | Repository | |
// then | ||
const user1 = await knex('users').where({ id: userId }).first(); | ||
expect(user1.emailConfirmedAt).to.deep.equal(now); | ||
expect(user1.updatedAt).to.deep.equal(now); | ||
|
||
const user2 = await knex('users').where({ id: user2Id }).first(); | ||
expect(user2.emailConfirmedAt).to.be.null; | ||
|
@@ -1474,6 +1453,7 @@ describe('Integration | Identity Access Management | Infrastructure | Repository | |
expect(updatedUser.emailConfirmedAt.toString()).to.equal(userAttributes.emailConfirmedAt.toString()); | ||
expect(updatedUser.email).to.equal(userAttributes.email); | ||
expect(updatedUser.cgu).to.equal(userAttributes.cgu); | ||
expect(updatedUser.updatedAt).to.deep.equal(now); | ||
}); | ||
|
||
it('should rollback the user email in case of error in transaction', async function () { | ||
|
@@ -1502,17 +1482,6 @@ describe('Integration | Identity Access Management | Infrastructure | Repository | |
}); | ||
|
||
describe('#updateUserDetailsForAdministration', function () { | ||
let clock; | ||
const now = new Date('2022-11-24'); | ||
|
||
beforeEach(async function () { | ||
clock = sinon.useFakeTimers({ now, toFake: ['Date'] }); | ||
}); | ||
|
||
afterEach(function () { | ||
clock.restore(); | ||
}); | ||
|
||
it('updates firstName, lastName, email, username and locale of the user', async function () { | ||
// given | ||
const userInDb = databaseBuilder.factory.buildUser(userToInsert); | ||
|
@@ -1542,7 +1511,7 @@ describe('Integration | Identity Access Management | Infrastructure | Repository | |
expect(updatedUser.email).to.equal('[email protected]'); | ||
expect(updatedUser.username).to.equal('username_123'); | ||
expect(updatedUser.locale).to.equal('fr-FR'); | ||
expect(updatedUser.updatedAt).to.deep.equal(new Date('2022-11-24')); | ||
expect(updatedUser.updatedAt).to.deep.equal(now); | ||
}); | ||
|
||
describe('when the preventUpdatedAt option is true', function () { | ||
|
@@ -1627,6 +1596,7 @@ describe('Integration | Identity Access Management | Infrastructure | Repository | |
// then | ||
expect(updatedUser).to.be.an.instanceOf(User); | ||
expect(updatedUser.username).to.equal(username); | ||
expect(updatedUser.updatedAt).to.deep.equal(now); | ||
}); | ||
|
||
it('should throw UserNotFoundError when user id not found', async function () { | ||
|
@@ -1646,17 +1616,6 @@ describe('Integration | Identity Access Management | Infrastructure | Repository | |
}); | ||
|
||
describe('#updatePixOrgaTermsOfServiceAcceptedToTrue', function () { | ||
let clock; | ||
const now = new Date('2021-01-02'); | ||
|
||
beforeEach(function () { | ||
clock = sinon.useFakeTimers({ now, toFake: ['Date'] }); | ||
}); | ||
|
||
afterEach(function () { | ||
clock.restore(); | ||
}); | ||
|
||
it('should return the model with pixOrgaTermsOfServiceAccepted flag updated to true', async function () { | ||
// given | ||
const userId = databaseBuilder.factory.buildUser({ pixOrgaTermsOfServiceAccepted: false }).id; | ||
|
@@ -1683,21 +1642,11 @@ describe('Integration | Identity Access Management | Infrastructure | Repository | |
|
||
// then | ||
expect(result.lastPixOrgaTermsOfServiceValidatedAt).to.deep.equal(now); | ||
expect(result.updatedAt).to.deep.equal(now); | ||
}); | ||
}); | ||
|
||
describe('#updatePixCertifTermsOfServiceAcceptedToTrue', function () { | ||
let clock; | ||
const now = new Date('2021-01-02'); | ||
|
||
beforeEach(function () { | ||
clock = sinon.useFakeTimers({ now, toFake: ['Date'] }); | ||
}); | ||
|
||
afterEach(function () { | ||
clock.restore(); | ||
}); | ||
|
||
it('should return the model with pixCertifTermsOfServiceAccepted flag updated to true', async function () { | ||
// given | ||
const userId = databaseBuilder.factory.buildUser({ pixCertifTermsOfServiceAccepted: false }).id; | ||
|
@@ -1724,6 +1673,7 @@ describe('Integration | Identity Access Management | Infrastructure | Repository | |
|
||
// then | ||
expect(actualUser.lastPixCertifTermsOfServiceValidatedAt).to.deep.equal(now); | ||
expect(actualUser.updatedAt).to.deep.equal(now); | ||
}); | ||
}); | ||
|
||
|
@@ -1738,6 +1688,7 @@ describe('Integration | Identity Access Management | Infrastructure | Repository | |
|
||
// then | ||
expect(actualUser.hasSeenAssessmentInstructions).to.be.true; | ||
expect(actualUser.updatedAt).to.deep.equal(now); | ||
}); | ||
}); | ||
|
||
|
@@ -1752,6 +1703,7 @@ describe('Integration | Identity Access Management | Infrastructure | Repository | |
|
||
// then | ||
expect(actualUser.hasSeenNewDashboardInfo).to.be.true; | ||
expect(actualUser.updatedAt).to.deep.equal(now); | ||
}); | ||
}); | ||
|
||
|
@@ -1773,6 +1725,7 @@ describe('Integration | Identity Access Management | Infrastructure | Repository | |
|
||
// then | ||
expect(actualUser.hasSeenFocusedChallengeTooltip).to.be.true; | ||
expect(actualUser.updatedAt).to.deep.equal(now); | ||
}); | ||
|
||
it('should return the model with hasSeenOtherChallengesTooltip flag updated to true', async function () { | ||
|
@@ -1782,6 +1735,7 @@ describe('Integration | Identity Access Management | Infrastructure | Repository | |
|
||
// then | ||
expect(actualUser.hasSeenOtherChallengesTooltip).to.be.true; | ||
expect(actualUser.updatedAt).to.deep.equal(now); | ||
}); | ||
}); | ||
}); | ||
|
@@ -1869,6 +1823,7 @@ describe('Integration | Identity Access Management | Infrastructure | Repository | |
expect(actualUser.lastTermsOfServiceValidatedAt).to.be.exist; | ||
expect(actualUser.lastTermsOfServiceValidatedAt).to.be.a('Date'); | ||
expect(actualUser.mustValidateTermsOfService).to.be.false; | ||
expect(actualUser.updatedAt).to.deep.equal(now); | ||
}); | ||
}); | ||
|
||
|
@@ -1899,17 +1854,6 @@ describe('Integration | Identity Access Management | Infrastructure | Repository | |
}); | ||
|
||
describe('#updateLastDataProtectionPolicySeenAt', function () { | ||
let clock; | ||
const now = new Date('2022-12-24'); | ||
|
||
beforeEach(function () { | ||
clock = sinon.useFakeTimers({ now, toFake: ['Date'] }); | ||
}); | ||
|
||
afterEach(function () { | ||
clock.restore(); | ||
}); | ||
|
||
it('should update the last data protection policy to now', async function () { | ||
// given | ||
const user = databaseBuilder.factory.buildUser(); | ||
|
@@ -1922,6 +1866,7 @@ describe('Integration | Identity Access Management | Infrastructure | Repository | |
// then | ||
expect(result).to.be.an.instanceOf(User); | ||
expect(result.lastDataProtectionPolicySeenAt).to.deep.equal(now); | ||
expect(result.updatedAt).to.deep.equal(now); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.