-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FEATURE] Enregistrer la date de dernière connexion Pix par applicati…
- Loading branch information
Showing
16 changed files
with
311 additions
and
8 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
14 changes: 14 additions & 0 deletions
14
...ss-management/infrastructure/repositories/last-user-application-connections.repository.js
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 |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { knex } from '../../../../db/knex-database-connection.js'; | ||
const TABLE_NAME = 'last-user-application-connections'; | ||
|
||
async function upsert({ userId, application, lastLoggedAt }) { | ||
const existingConnection = await knex(TABLE_NAME).where({ userId, application }).first(); | ||
|
||
if (existingConnection) { | ||
return knex(TABLE_NAME).where({ userId, application }).update({ lastLoggedAt }); | ||
} | ||
|
||
return knex(TABLE_NAME).insert({ userId, application, lastLoggedAt }); | ||
} | ||
|
||
export const lastUserApplicationConnectionsRepository = { upsert }; |
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
73 changes: 73 additions & 0 deletions
73
...egration/infrastructure/repositories/last-user-application-connections.repository.test.js
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 |
---|---|---|
@@ -0,0 +1,73 @@ | ||
import { lastUserApplicationConnectionsRepository } from '../../../../../src/identity-access-management/infrastructure/repositories/last-user-application-connections.repository.js'; | ||
import { databaseBuilder, expect } from '../../../../test-helper.js'; | ||
|
||
describe('Integration | Identity Access Management | Infrastructure | Repository | last-user-application-connections', function () { | ||
describe('#upsert', function () { | ||
it('saves a last user application connection', async function () { | ||
// given | ||
const userId = databaseBuilder.factory.buildUser().id; | ||
const application = 'orga'; | ||
const lastLoggedAt = new Date(); | ||
await databaseBuilder.commit(); | ||
|
||
// when | ||
await lastUserApplicationConnectionsRepository.upsert({ | ||
userId, | ||
application, | ||
lastLoggedAt, | ||
}); | ||
|
||
// then | ||
const lastUserApplicationConnections = await databaseBuilder | ||
.knex('last-user-application-connections') | ||
.where({ userId, application }) | ||
.first(); | ||
|
||
expect(lastUserApplicationConnections).to.deep.equal({ | ||
id: lastUserApplicationConnections.id, | ||
userId, | ||
application, | ||
lastLoggedAt, | ||
}); | ||
}); | ||
|
||
context('when the last user application connection already exists', function () { | ||
it('updates the last user application connection', async function () { | ||
// given | ||
const userId = databaseBuilder.factory.buildUser().id; | ||
const application = 'orga'; | ||
const formerLastLoggedAt = new Date('2021-01-01'); | ||
const newLastLoggedAt = new Date('2021-01-02'); | ||
await databaseBuilder.commit(); | ||
|
||
await databaseBuilder.knex('last-user-application-connections').insert({ | ||
userId, | ||
application, | ||
lastLoggedAt: formerLastLoggedAt, | ||
}); | ||
|
||
// when | ||
await lastUserApplicationConnectionsRepository.upsert({ | ||
userId, | ||
application, | ||
lastLoggedAt: newLastLoggedAt, | ||
}); | ||
|
||
// then | ||
const lastUserApplicationConnections = await databaseBuilder | ||
.knex('last-user-application-connections') | ||
.where({ userId, application }); | ||
|
||
expect(lastUserApplicationConnections).to.have.lengthOf(1); | ||
expect(lastUserApplicationConnections).to.deep.equal([ | ||
{ | ||
id: lastUserApplicationConnections[0].id, | ||
userId, | ||
application, | ||
lastLoggedAt: newLastLoggedAt, | ||
}, | ||
]); | ||
}); | ||
}); | ||
}); | ||
}); |
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 |
---|---|---|
@@ -1,5 +1,6 @@ | ||
import { oidcProviderAdminController } from '../../../../src/identity-access-management/application/oidc-provider/oidc-provider.admin.controller.js'; | ||
import { usecases } from '../../../../src/identity-access-management/domain/usecases/index.js'; | ||
import { RequestedApplication } from '../../../../src/identity-access-management/infrastructure/utils/network.js'; | ||
import { DomainTransaction } from '../../../../src/shared/domain/DomainTransaction.js'; | ||
import { expect, hFake, sinon } from '../../../test-helper.js'; | ||
|
||
|
@@ -180,11 +181,22 @@ describe('Unit | Identity Access Management | Application | Controller | Admin | | |
email: '[email protected]', | ||
}, | ||
}; | ||
const requestedApplication = new RequestedApplication('admin'); | ||
|
||
const dependencies = { | ||
oidcAuthenticationServiceRegistry: oidcAuthenticationServiceRegistryStub, | ||
}; | ||
sinon.stub(usecases, 'reconcileOidcUserForAdmin').resolves('accessToken'); | ||
sinon | ||
.stub(usecases, 'reconcileOidcUserForAdmin') | ||
.withArgs({ | ||
email: '[email protected]', | ||
identityProvider, | ||
authenticationKey: '123abc', | ||
audience: 'https://admin.pix.fr', | ||
requestedApplication, | ||
oidcAuthenticationService: sinon.match.any, | ||
}) | ||
.resolves('accessToken'); | ||
|
||
// when | ||
const result = await oidcProviderAdminController.reconcileUserForAdmin(request, hFake, dependencies); | ||
|
Oops, something went wrong.