|
| 1 | +import { CampaignParticipationStatuses } from '../../../../src/prescription/shared/domain/constants.js'; |
| 2 | +import { |
| 3 | + fetchUserIds, |
| 4 | + PRODUCTION_SIXTH_GRADE_TARGET_PROFILE_IDS, |
| 5 | +} from '../../../../src/profile/scripts/sixth-grade-attestation-reward.js'; |
| 6 | +import { databaseBuilder, expect } from '../../../test-helper.js'; |
| 7 | + |
| 8 | +describe('Integration | Profile | Scripts | sixth-grade-attestation-reward', function () { |
| 9 | + describe('#fetchUsers', function () { |
| 10 | + it('should not return the user if the participation date is not included between the start date and the end date ', async function () { |
| 11 | + const { id: targetProfileId } = databaseBuilder.factory.buildTargetProfile({ |
| 12 | + id: PRODUCTION_SIXTH_GRADE_TARGET_PROFILE_IDS[0], |
| 13 | + }); |
| 14 | + const campaign = databaseBuilder.factory.buildCampaign({ targetProfileId }); |
| 15 | + const { userId } = databaseBuilder.factory.buildCampaignParticipation({ |
| 16 | + campaignId: campaign.id, |
| 17 | + status: CampaignParticipationStatuses.SHARED, |
| 18 | + createdAt: '2024-12-02T15:07:57.376Z', |
| 19 | + }); |
| 20 | + databaseBuilder.factory.buildCampaignParticipation({ |
| 21 | + campaignId: campaign.id, |
| 22 | + status: CampaignParticipationStatuses.SHARED, |
| 23 | + createdAt: '2024-12-07T15:07:57.376Z', |
| 24 | + }); |
| 25 | + databaseBuilder.factory.buildCampaignParticipation({ |
| 26 | + campaignId: campaign.id, |
| 27 | + status: CampaignParticipationStatuses.SHARED, |
| 28 | + createdAt: '2024-11-22T15:07:57.376Z', |
| 29 | + }); |
| 30 | + |
| 31 | + await databaseBuilder.commit(); |
| 32 | + const userIds = await fetchUserIds(); |
| 33 | + expect(userIds).to.have.lengthOf(1); |
| 34 | + expect(userIds).to.contains(userId); |
| 35 | + }); |
| 36 | + |
| 37 | + it('should not return the user if the participation status is different from started', async function () { |
| 38 | + const { id: targetProfileId } = databaseBuilder.factory.buildTargetProfile({ |
| 39 | + id: PRODUCTION_SIXTH_GRADE_TARGET_PROFILE_IDS[0], |
| 40 | + }); |
| 41 | + const campaign = databaseBuilder.factory.buildCampaign({ targetProfileId }); |
| 42 | + const { userId } = databaseBuilder.factory.buildCampaignParticipation({ |
| 43 | + campaignId: campaign.id, |
| 44 | + status: CampaignParticipationStatuses.STARTED, |
| 45 | + createdAt: '2024-12-02T15:07:57.376Z', |
| 46 | + }); |
| 47 | + databaseBuilder.factory.buildCampaignParticipation({ |
| 48 | + campaignId: campaign.id, |
| 49 | + status: CampaignParticipationStatuses.SHARED, |
| 50 | + createdAt: '2024-12-02T15:07:57.376Z', |
| 51 | + }); |
| 52 | + databaseBuilder.factory.buildCampaignParticipation({ |
| 53 | + campaignId: campaign.id, |
| 54 | + status: CampaignParticipationStatuses.TO_SHARE, |
| 55 | + createdAt: '2024-12-02T15:07:57.376Z', |
| 56 | + }); |
| 57 | + |
| 58 | + await databaseBuilder.commit(); |
| 59 | + const userIds = await fetchUserIds(); |
| 60 | + expect(userIds).to.have.lengthOf(2); |
| 61 | + expect(userIds).to.not.contains(userId); |
| 62 | + }); |
| 63 | + |
| 64 | + it('should not return the user if the campaign target profile is not included in targeted target profiles', async function () { |
| 65 | + const { id: targetProfileId1 } = databaseBuilder.factory.buildTargetProfile({ |
| 66 | + id: PRODUCTION_SIXTH_GRADE_TARGET_PROFILE_IDS[0], |
| 67 | + }); |
| 68 | + const { id: targetProfileId2 } = databaseBuilder.factory.buildTargetProfile({ |
| 69 | + id: PRODUCTION_SIXTH_GRADE_TARGET_PROFILE_IDS[1], |
| 70 | + }); |
| 71 | + const { id: targetProfileId3 } = databaseBuilder.factory.buildTargetProfile({ |
| 72 | + id: PRODUCTION_SIXTH_GRADE_TARGET_PROFILE_IDS[2], |
| 73 | + }); |
| 74 | + const { id: targetProfileId4 } = databaseBuilder.factory.buildTargetProfile(); |
| 75 | + const campaign1 = databaseBuilder.factory.buildCampaign({ targetProfileId: targetProfileId1 }); |
| 76 | + const campaign2 = databaseBuilder.factory.buildCampaign({ targetProfileId: targetProfileId2 }); |
| 77 | + const campaign3 = databaseBuilder.factory.buildCampaign({ targetProfileId: targetProfileId3 }); |
| 78 | + const campaign4 = databaseBuilder.factory.buildCampaign({ targetProfileId: targetProfileId4 }); |
| 79 | + const otherParameters = { status: CampaignParticipationStatuses.SHARED, createdAt: '2024-12-02T15:07:57.376Z' }; |
| 80 | + databaseBuilder.factory.buildCampaignParticipation({ |
| 81 | + campaignId: campaign1.id, |
| 82 | + ...otherParameters, |
| 83 | + }); |
| 84 | + databaseBuilder.factory.buildCampaignParticipation({ |
| 85 | + campaignId: campaign2.id, |
| 86 | + ...otherParameters, |
| 87 | + }); |
| 88 | + databaseBuilder.factory.buildCampaignParticipation({ |
| 89 | + campaignId: campaign3.id, |
| 90 | + ...otherParameters, |
| 91 | + }); |
| 92 | + const { userId: otherTargetProfileCampaignParticipationUserId } = |
| 93 | + databaseBuilder.factory.buildCampaignParticipation({ |
| 94 | + campaignId: campaign4.id, |
| 95 | + ...otherParameters, |
| 96 | + }); |
| 97 | + |
| 98 | + await databaseBuilder.commit(); |
| 99 | + const userIds = await fetchUserIds(); |
| 100 | + expect(userIds).to.have.lengthOf(3); |
| 101 | + expect(userIds).to.not.contains(otherTargetProfileCampaignParticipationUserId); |
| 102 | + }); |
| 103 | + |
| 104 | + it('should return expected users', async function () { |
| 105 | + const { id: targetProfileId1 } = databaseBuilder.factory.buildTargetProfile({ |
| 106 | + id: PRODUCTION_SIXTH_GRADE_TARGET_PROFILE_IDS[0], |
| 107 | + }); |
| 108 | + const { id: targetProfileId2 } = databaseBuilder.factory.buildTargetProfile({ |
| 109 | + id: PRODUCTION_SIXTH_GRADE_TARGET_PROFILE_IDS[1], |
| 110 | + }); |
| 111 | + const { id: targetProfileId3 } = databaseBuilder.factory.buildTargetProfile({ |
| 112 | + id: PRODUCTION_SIXTH_GRADE_TARGET_PROFILE_IDS[2], |
| 113 | + }); |
| 114 | + const campaign1 = databaseBuilder.factory.buildCampaign({ targetProfileId: targetProfileId1 }); |
| 115 | + const campaign2 = databaseBuilder.factory.buildCampaign({ targetProfileId: targetProfileId2 }); |
| 116 | + const campaign3 = databaseBuilder.factory.buildCampaign({ targetProfileId: targetProfileId3 }); |
| 117 | + databaseBuilder.factory.buildCampaignParticipation({ |
| 118 | + campaignId: campaign1.id, |
| 119 | + status: CampaignParticipationStatuses.SHARED, |
| 120 | + createdAt: '2024-12-01T00:00:01.000Z', |
| 121 | + }); |
| 122 | + databaseBuilder.factory.buildCampaignParticipation({ |
| 123 | + campaignId: campaign2.id, |
| 124 | + status: CampaignParticipationStatuses.TO_SHARE, |
| 125 | + createdAt: '2024-12-02T15:00:00.000Z', |
| 126 | + }); |
| 127 | + databaseBuilder.factory.buildCampaignParticipation({ |
| 128 | + campaignId: campaign3.id, |
| 129 | + status: CampaignParticipationStatuses.TO_SHARE, |
| 130 | + createdAt: '2024-12-03T23:59:58.000Z', |
| 131 | + }); |
| 132 | + |
| 133 | + await databaseBuilder.commit(); |
| 134 | + const userIds = await fetchUserIds(); |
| 135 | + expect(userIds).to.have.lengthOf(3); |
| 136 | + }); |
| 137 | + }); |
| 138 | + |
| 139 | + describe('#handle', function () { |
| 140 | + it('should reward expected users', async function () {}); |
| 141 | + }); |
| 142 | +}); |
0 commit comments