Skip to content

Commit

Permalink
[TECH] Ne pas vérifier la présence du créateur dans l'organisation su…
Browse files Browse the repository at this point in the history
…r la création de campagnes en masse (PIX-9490)
  • Loading branch information
pix-service-auto-merge authored Oct 2, 2023
2 parents f60b5a4 + 8e134af commit 4a43412
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ const createCampaigns = async function ({
userId: campaign.creatorId,
organizationId: campaign.organizationId,
shouldOwnerBeFromOrganization: false,
shouldCreatorBeFromOrganization: false,
});

return campaignCreator.createCampaign({
Expand Down
12 changes: 10 additions & 2 deletions api/lib/infrastructure/repositories/campaign-creator-repository.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,16 @@ import { knex } from '../../../db/knex-database-connection.js';
import { CampaignCreator } from '../../../lib/domain/models/CampaignCreator.js';
import { UserNotAuthorizedToCreateCampaignError } from '../../domain/errors.js';

async function get({ userId, organizationId, ownerId, shouldOwnerBeFromOrganization = true }) {
await _checkUserIsAMemberOfOrganization({ organizationId, userId });
async function get({
userId,
organizationId,
ownerId,
shouldOwnerBeFromOrganization = true,
shouldCreatorBeFromOrganization = true,
}) {
if (shouldCreatorBeFromOrganization) {
await _checkUserIsAMemberOfOrganization({ organizationId, userId });
}
if (shouldOwnerBeFromOrganization) {
await _checkOwnerIsAMemberOfOrganization({ organizationId, ownerId });
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,29 @@ describe('Integration | Repository | CampaignCreatorRepository', function () {
expect(error).to.be.instanceOf(UserNotAuthorizedToCreateCampaignError);
expect(error.message).to.equal(`User does not have an access to the organization ${organizationId}`);
});

it('return the campaign creator', async function () {
// given
const userId = databaseBuilder.factory.buildUser().id;
const ownerId = databaseBuilder.factory.buildUser().id;

const organizationId = databaseBuilder.factory.buildOrganization().id;
databaseBuilder.factory.buildMembership({ organizationId, userId: ownerId });
const shouldCreatorBeFromOrganization = false;

await databaseBuilder.commit();

// when
const result = await campaignCreatorRepository.get({
userId,
organizationId,
ownerId,
shouldCreatorBeFromOrganization,
});

// then
expect(result).to.be.instanceOf(CampaignCreator);
});
});

context('when the owner is not a member of the organization', function () {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,15 @@ describe('Unit | UseCase | campaign-administration | create-campaign', function
userId: campaignsToCreate[0].creatorId,
organizationId: campaignsToCreate[0].organizationId,
shouldOwnerBeFromOrganization: false,
shouldCreatorBeFromOrganization: false,
})
.resolves(campaignCreatorPOJO);
campaignCreatorRepositoryStub.get
.withArgs({
userId: campaignsToCreate[1].creatorId,
organizationId: campaignsToCreate[1].organizationId,
shouldOwnerBeFromOrganization: false,
shouldCreatorBeFromOrganization: false,
})
.resolves(campaignCreatorPOJO);

Expand Down

0 comments on commit 4a43412

Please sign in to comment.