-
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] Exposer une API afin de récupérer les informations d'une campa…
- Loading branch information
Showing
15 changed files
with
248 additions
and
83 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
9 changes: 9 additions & 0 deletions
9
api/lib/application/usecases/checkAuthorizationToAccessCampaign.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,9 @@ | ||
import * as prescriberRoleRepository from '../../infrastructure/repositories/prescriber-role-repository.js'; | ||
import { CampaignAuthorization } from '../preHandlers/models/CampaignAuthorization.js'; | ||
|
||
const execute = async function ({ userId, campaignId }) { | ||
const prescriberRole = await prescriberRoleRepository.getForCampaign({ userId, campaignId }); | ||
return CampaignAuthorization.isAllowedToAccess({ prescriberRole }); | ||
}; | ||
|
||
export { execute }; |
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
11 changes: 11 additions & 0 deletions
11
api/src/prescription/campaigns/application/api/Campaign.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,11 @@ | ||
export class Campaign { | ||
constructor({ id, code, name, title, createdAt, archivedAt, customLandingPageText }) { | ||
this.id = id; | ||
this.code = code; | ||
this.name = name; | ||
this.title = title; | ||
this.createdAt = createdAt; | ||
this.archivedAt = archivedAt; | ||
this.customLandingPageText = customLandingPageText; | ||
} | ||
} |
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
40 changes: 40 additions & 0 deletions
40
api/tests/integration/application/usecases/checkAuthorizationToAccessCampaign_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,40 @@ | ||
import { expect, databaseBuilder, catchErr } from '../../../test-helper.js'; | ||
import * as checkAuthorizationToAccessCampaign from '../../../../lib/application/usecases/checkAuthorizationToAccessCampaign.js'; | ||
|
||
describe('Integration | API | checkAuthorizationToAccessCampaign', function () { | ||
describe('when the user belongs to organization', function () { | ||
it('returns true', async function () { | ||
// given | ||
const organization = databaseBuilder.factory.buildOrganization(); | ||
const user = databaseBuilder.factory.buildUser(); | ||
databaseBuilder.factory.buildMembership({ userId: user.id, organizationId: organization.id }); | ||
const campaign = databaseBuilder.factory.buildCampaign({ organizationId: organization.id }); | ||
await databaseBuilder.commit(); | ||
|
||
// when | ||
const hasAccess = await checkAuthorizationToAccessCampaign.execute({ campaignId: campaign.id, userId: user.id }); | ||
|
||
// then | ||
expect(hasAccess).to.be.true; | ||
}); | ||
}); | ||
|
||
describe('when the user does not belong to organization', function () { | ||
it('throws', async function () { | ||
// given | ||
const organization = databaseBuilder.factory.buildOrganization(); | ||
const user = databaseBuilder.factory.buildUser(); | ||
const campaign = databaseBuilder.factory.buildCampaign({ organizationId: organization.id }); | ||
await databaseBuilder.commit(); | ||
|
||
// when | ||
const hasAccess = await catchErr(checkAuthorizationToAccessCampaign.execute)({ | ||
campaignId: campaign.id, | ||
userId: user.id, | ||
}); | ||
|
||
// then | ||
expect(hasAccess).to.throws; | ||
}); | ||
}); | ||
}); |
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
Oops, something went wrong.