|
| 1 | +import { CampaignParticipation } from '../../../../src/maddo/domain/models/CampaignParticipation.js'; |
| 2 | +import { CampaignParticipationStatuses } from '../../../../src/prescription/shared/domain/constants.js'; |
| 3 | +import { |
| 4 | + createMaddoServer, |
| 5 | + databaseBuilder, |
| 6 | + expect, |
| 7 | + generateValidRequestAuthorizationHeaderForApplication, |
| 8 | +} from '../../../test-helper.js'; |
| 9 | + |
| 10 | +describe('Acceptance | Maddo | Route | Campaigns', function () { |
| 11 | + let server; |
| 12 | + |
| 13 | + beforeEach(async function () { |
| 14 | + server = await createMaddoServer(); |
| 15 | + }); |
| 16 | + |
| 17 | + describe('GET /api/campaigns/{campaignId}/participations', function () { |
| 18 | + it('returns the list of all participations of campaign with an HTTP status code 200', async function () { |
| 19 | + // given |
| 20 | + const orgaInJurisdiction = databaseBuilder.factory.buildOrganization({ name: 'orga-in-jurisdiction' }); |
| 21 | + databaseBuilder.factory.buildOrganization({ name: 'orga-not-in-jurisdiction' }); |
| 22 | + |
| 23 | + const tag = databaseBuilder.factory.buildTag(); |
| 24 | + databaseBuilder.factory.buildOrganizationTag({ organizationId: orgaInJurisdiction.id, tagId: tag.id }); |
| 25 | + |
| 26 | + const clientId = 'client'; |
| 27 | + databaseBuilder.factory.buildClientApplication({ |
| 28 | + clientId: 'client', |
| 29 | + jurisdiction: { rules: [{ name: 'tags', value: [tag.name] }] }, |
| 30 | + }); |
| 31 | + |
| 32 | + const campaign = databaseBuilder.factory.buildCampaign({ organizationId: orgaInJurisdiction.id }); |
| 33 | + const participation1 = databaseBuilder.factory.buildCampaignParticipation({ campaignId: campaign.id }); |
| 34 | + const participation2 = databaseBuilder.factory.buildCampaignParticipation({ |
| 35 | + campaignId: campaign.id, |
| 36 | + status: CampaignParticipationStatuses.STARTED, |
| 37 | + }); |
| 38 | + |
| 39 | + await databaseBuilder.commit(); |
| 40 | + |
| 41 | + const options = { |
| 42 | + method: 'GET', |
| 43 | + url: `/api/campaigns/${campaign.id}/participations`, |
| 44 | + headers: { |
| 45 | + authorization: generateValidRequestAuthorizationHeaderForApplication(clientId, 'pix-client', 'campaigns'), |
| 46 | + }, |
| 47 | + }; |
| 48 | + |
| 49 | + // when |
| 50 | + const response = await server.inject(options); |
| 51 | + |
| 52 | + // then |
| 53 | + expect(response.statusCode).to.equal(200); |
| 54 | + expect(response.result).to.deep.equal([ |
| 55 | + new CampaignParticipation(participation1), |
| 56 | + new CampaignParticipation(participation2), |
| 57 | + ]); |
| 58 | + }); |
| 59 | + }); |
| 60 | +}); |
0 commit comments