Skip to content

Commit

Permalink
Enrich test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
DarkMenacer committed Feb 1, 2025
1 parent dd4c149 commit efe8dc3
Showing 1 changed file with 93 additions and 5 deletions.
98 changes: 93 additions & 5 deletions shared/src/utils/stats/RecipientStatsCalculator.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,27 @@ beforeAll(async () => {
});

test('totalRecipients(): Calculate total recipients', async () => {
expect(calculator.allStats().totalRecipients.total).toEqual(1);
expect(calculator.allStats().totalRecipients.total).toEqual(3);
});

test('totalRecipients(): Calculate active recipients', async () => {
expect(calculator.allStats().totalRecipients.active).toEqual(1);
});

test('totalRecipientsByOrganization(): Calculate total recipients for a particular organisation', async () => {
expect(calculator.allStats().totalRecipientsByOrganization['aurora'].total).toEqual(1);
expect(calculator.allStats().totalRecipientsByOrganization['aurora'].total).toEqual(2);
});

test('totalRecipientsByOrganization(): Calculate active recipients for a particular organisation', async () => {
expect(calculator.allStats().totalRecipientsByOrganization['aurora'].total).toEqual(1);
expect(calculator.allStats().totalRecipientsByOrganization['aurora'].active).toEqual(1);
});

test('totalRecipientsByOrganization(): Calculate suspended recipients for a particular organisation', async () => {
expect(calculator.allStats().totalRecipientsByOrganization['aurora'].suspended).toEqual(1);
});

test('totalRecipientsByOrganization(): Calculate recipients for a non-existing organisation', async () => {
expect(calculator.allStats().totalRecipientsByOrganization['socialincome']?.total).toEqual(undefined);
});

const org1: PartnerOrganisation = {
Expand All @@ -44,6 +52,12 @@ const org1: PartnerOrganisation = {
contactNumber: '123',
};

const org2: PartnerOrganisation = {
name: 'socialincome',
contactName: 'test2',
contactNumber: '456',
};

const recipient1: Recipient = {
birth_date: new Date('1990-05-15'),
calling_name: 'John',
Expand Down Expand Up @@ -72,13 +86,87 @@ const recipient1: Recipient = {
successor: 'Jane Doe',
};

const recipient2: Recipient = {
birth_date: new Date('1990-05-15'),
calling_name: 'Jane',
communication_mobile_phone: {
phone: 1234567890,
has_whatsapp: true,
whatsapp_activated: true,
},
email: '[email protected]',
first_name: 'Jane',
gender: 'female',
insta_handle: '@jane_doe',
last_name: 'Doe',
main_language: RecipientMainLanguage.English,
mobile_money_phone: {
phone: 9876543210,
has_whatsapp: true,
},
organisation: { id: 'aurora' } as DocumentReference<PartnerOrganisation>,
om_uid: 12345,
profession: 'Software Engineer',
progr_status: RecipientProgramStatus.Suspended,
si_start_date: new Timestamp(1609459200, 0),
test_recipient: false,
twitter_handle: '@john_doe_tech',
successor: 'Jane Doe',
};

const recipient3: Recipient = {
birth_date: new Date('1990-05-15'),
calling_name: 'Jack',
communication_mobile_phone: {
phone: 1234567890,
has_whatsapp: true,
whatsapp_activated: true,
},
email: '[email protected]',
first_name: 'Jack',
gender: 'male',
insta_handle: '@jack_doe',
last_name: 'Doe',
main_language: RecipientMainLanguage.English,
mobile_money_phone: {
phone: 9876543210,
has_whatsapp: true,
},
organisation: { id: 'socialincome' } as DocumentReference<PartnerOrganisation>,
om_uid: 12345,
profession: 'Software Engineer',
progr_status: RecipientProgramStatus.Waitlisted,
si_start_date: new Timestamp(1609459200, 0),
test_recipient: false,
twitter_handle: '@jack_doe_tech',
successor: 'Jane Doe',
};

const insertTestData = async () => {
await firestoreAdmin.collection<PartnerOrganisation>(PARTNER_ORGANISATION_FIRESTORE_PATH).doc('aurora').set(org1);
const recipientWithOrgRef: Recipient = {
await firestoreAdmin
.collection<PartnerOrganisation>(PARTNER_ORGANISATION_FIRESTORE_PATH)
.doc('socialincome')
.set(org2);
const recipient1WithOrgRef: Recipient = {
...recipient1,
organisation: firestoreAdmin
.collection<PartnerOrganisation>(PARTNER_ORGANISATION_FIRESTORE_PATH)
.doc('aurora') as DocumentReference<PartnerOrganisation>,
};
await firestoreAdmin.collection<Recipient>(RECIPIENT_FIRESTORE_PATH).add(recipientWithOrgRef);
const recipient2WithOrgRef: Recipient = {
...recipient2,
organisation: firestoreAdmin
.collection<PartnerOrganisation>(PARTNER_ORGANISATION_FIRESTORE_PATH)
.doc('aurora') as DocumentReference<PartnerOrganisation>,
};
const recipient3WithOrgRef: Recipient = {
...recipient3,
organisation: firestoreAdmin
.collection<PartnerOrganisation>(PARTNER_ORGANISATION_FIRESTORE_PATH)
.doc('socialincome') as DocumentReference<PartnerOrganisation>,
};
await firestoreAdmin.collection<Recipient>(RECIPIENT_FIRESTORE_PATH).add(recipient1WithOrgRef);
await firestoreAdmin.collection<Recipient>(RECIPIENT_FIRESTORE_PATH).add(recipient2WithOrgRef);
await firestoreAdmin.collection<Recipient>(RECIPIENT_FIRESTORE_PATH).add(recipient3WithOrgRef);
};

0 comments on commit efe8dc3

Please sign in to comment.