Skip to content

Commit

Permalink
feat: ASAP-382 Leadership and membership count update (#4217)
Browse files Browse the repository at this point in the history
  • Loading branch information
peterstarling authored Mar 28, 2024
1 parent 56414ab commit 82e2fd5
Show file tree
Hide file tree
Showing 6 changed files with 288 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,17 @@ export class AnalyticsContentfulDataProvider implements AnalyticsDataProvider {
),
interestGroupMemberCount:
(!team.inactiveSince &&
team.linkedFrom?.interestGroupsCollection?.total) ||
getUniqueIdCount([
...(team.linkedFrom?.teamMembershipCollection?.items.flatMap(
(item) =>
item?.linkedFrom?.usersCollection?.items
.filter(filterOutAlumni)
.flatMap(flattenInterestGroupLeaders),
) || []),
...(team.linkedFrom?.interestGroupsCollection?.items.flatMap(
(interestGroup) => interestGroup?.sys.id,
) || []),
])) ||
0,
interestGroupPreviousLeadershipRoleCount: getUniqueIdCount(
team.linkedFrom?.teamMembershipCollection?.items.flatMap(
Expand All @@ -52,7 +62,17 @@ export class AnalyticsContentfulDataProvider implements AnalyticsDataProvider {
),
interestGroupPreviousMemberCount:
(team.inactiveSince &&
team.linkedFrom?.interestGroupsCollection?.total) ||
getUniqueIdCount([
...(team.linkedFrom?.teamMembershipCollection?.items.flatMap(
(item) =>
item?.linkedFrom?.usersCollection?.items
.filter(filterOutAlumni)
.flatMap(flattenInterestGroupLeaders),
) || []),
...(team.linkedFrom?.interestGroupsCollection?.items.flatMap(
(interestGroup) => interestGroup?.sys.id,
) || []),
])) ||
0,
workingGroupLeadershipRoleCount: getUniqueIdCount(
team.linkedFrom?.teamMembershipCollection?.items.flatMap(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -546,9 +546,27 @@ describe('Analytics Data Provider', () => {
});

describe('Interest Group Member Count', () => {
test('Should return 0 for interestGroupMemberCount when the client returns interestGroupsCollection items as an empty array', async () => {
test('Should return 0 for interestGroupMemberCount when the client returns interestGroupsCollection and interestGroupLeadersCollection items as empty arrays', async () => {
const contentfulGraphQLResponse = getAnalyticsTeamLeadershipQuery();
contentfulGraphQLResponse.teamsCollection!.items[0]!.linkedFrom!.interestGroupsCollection!.total = 0;
contentfulGraphQLResponse.teamsCollection!.items[0]!.linkedFrom!.teamMembershipCollection!.items[0]!.linkedFrom!.usersCollection!.items[0]!.linkedFrom!.interestGroupLeadersCollection!.items =
[];
contentfulGraphQLResponse.teamsCollection!.items[0]!.linkedFrom!.interestGroupsCollection!.items =
[];
contentfulGraphqlClientMock.request.mockResolvedValueOnce(
contentfulGraphQLResponse,
);

const result = await analyticsDataProvider.fetchTeamLeadership({});

expect(result.items[0]!.interestGroupMemberCount).toBe(0);
});

test('Should return 0 for interestGroupMemberCount when the client returns teamMembershipCollection and interestGroupLeadersCollection items as null', async () => {
const contentfulGraphQLResponse = getAnalyticsTeamLeadershipQuery();
contentfulGraphQLResponse.teamsCollection!.items[0]!.linkedFrom!.teamMembershipCollection =
null;
contentfulGraphQLResponse.teamsCollection!.items[0]!.linkedFrom!.interestGroupsCollection =
null;
contentfulGraphqlClientMock.request.mockResolvedValueOnce(
contentfulGraphQLResponse,
);
Expand All @@ -560,7 +578,83 @@ describe('Analytics Data Provider', () => {

test('Should return interestGroupMemberCount of 2 when the client returns a total of 2 interest groups associated with a team', async () => {
const contentfulGraphQLResponse = getAnalyticsTeamLeadershipQuery();
contentfulGraphQLResponse.teamsCollection!.items[0]!.linkedFrom!.interestGroupsCollection!.total = 2;
contentfulGraphQLResponse.teamsCollection!.items[0]!.linkedFrom!.interestGroupsCollection!.items =
[
{
sys: {
id: 'interest-group-1',
},
},
{
sys: {
id: 'interest-group-2',
},
},
];
contentfulGraphqlClientMock.request.mockResolvedValueOnce(
contentfulGraphQLResponse,
);

const result = await analyticsDataProvider.fetchTeamLeadership({});

expect(result.items[0]!.interestGroupMemberCount).toBe(2);
});

test('Should return interestGroupMemberCount of 3 when the client returns a total of 2 interest groups associated with a team and one leader of another interest group', async () => {
const contentfulGraphQLResponse = getAnalyticsTeamLeadershipQuery();
contentfulGraphQLResponse.teamsCollection!.items[0]!.linkedFrom!.interestGroupsCollection!.items =
[
{
sys: {
id: 'interest-group-1',
},
},
{
sys: {
id: 'interest-group-2',
},
},
];
contentfulGraphQLResponse.teamsCollection!.items[0]!.linkedFrom!.teamMembershipCollection!.items[0]!.linkedFrom!.usersCollection!.items[0]!.linkedFrom!.interestGroupLeadersCollection!.items[0]!.linkedFrom!.interestGroupsCollection!.items =
[
{
sys: {
id: 'interest-group-3',
},
},
];
contentfulGraphqlClientMock.request.mockResolvedValueOnce(
contentfulGraphQLResponse,
);

const result = await analyticsDataProvider.fetchTeamLeadership({});

expect(result.items[0]!.interestGroupMemberCount).toBe(3);
});

test('Should return interestGroupMemberCount of 2 when the client returns a total of 2 interest groups associated with a team and one leader of the same interest group', async () => {
const contentfulGraphQLResponse = getAnalyticsTeamLeadershipQuery();
contentfulGraphQLResponse.teamsCollection!.items[0]!.linkedFrom!.interestGroupsCollection!.items =
[
{
sys: {
id: 'interest-group-1',
},
},
{
sys: {
id: 'interest-group-2',
},
},
];
contentfulGraphQLResponse.teamsCollection!.items[0]!.linkedFrom!.teamMembershipCollection!.items[0]!.linkedFrom!.usersCollection!.items[0]!.linkedFrom!.interestGroupLeadersCollection!.items[0]!.linkedFrom!.interestGroupsCollection!.items =
[
{
sys: {
id: 'interest-group-2',
},
},
];
contentfulGraphqlClientMock.request.mockResolvedValueOnce(
contentfulGraphQLResponse,
);
Expand All @@ -574,7 +668,19 @@ describe('Analytics Data Provider', () => {
const contentfulGraphQLResponse = getAnalyticsTeamLeadershipQuery();
contentfulGraphQLResponse.teamsCollection!.items[0]!.inactiveSince =
pastDate;
contentfulGraphQLResponse.teamsCollection!.items[0]!.linkedFrom!.interestGroupsCollection!.total = 2;
contentfulGraphQLResponse.teamsCollection!.items[0]!.linkedFrom!.interestGroupsCollection!.items =
[
{
sys: {
id: 'interest-group-1',
},
},
{
sys: {
id: 'interest-group-2',
},
},
];
contentfulGraphqlClientMock.request.mockResolvedValueOnce(
contentfulGraphQLResponse,
);
Expand All @@ -586,11 +692,31 @@ describe('Analytics Data Provider', () => {
});

describe('Interest Group Previous Member Count', () => {
test('Should return 0 for interestGroupPreviousMemberCount when the client returns interestGroupsCollection items as an empty array and the team is inactive', async () => {
test('Should return 0 for interestGroupPreviousMemberCount when the client returns interestGroupsCollection and interestGroupLeadersCollection items as empty arrays and the team is inactive', async () => {
const contentfulGraphQLResponse = getAnalyticsTeamLeadershipQuery();
contentfulGraphQLResponse.teamsCollection!.items[0]!.inactiveSince =
pastDate;
contentfulGraphQLResponse.teamsCollection!.items[0]!.linkedFrom!.teamMembershipCollection!.items[0]!.linkedFrom!.usersCollection!.items[0]!.linkedFrom!.interestGroupLeadersCollection!.items =
[];
contentfulGraphQLResponse.teamsCollection!.items[0]!.linkedFrom!.interestGroupsCollection!.items =
[];
contentfulGraphqlClientMock.request.mockResolvedValueOnce(
contentfulGraphQLResponse,
);

const result = await analyticsDataProvider.fetchTeamLeadership({});

expect(result.items[0]!.interestGroupPreviousMemberCount).toBe(0);
});

test('Should return 0 for interestGroupPreviousMemberCount when the client returns interestGroupsCollection and interestGroupLeadersCollection items as null and the team is inactive', async () => {
const contentfulGraphQLResponse = getAnalyticsTeamLeadershipQuery();
contentfulGraphQLResponse.teamsCollection!.items[0]!.inactiveSince =
pastDate;
contentfulGraphQLResponse.teamsCollection!.items[0]!.linkedFrom!.interestGroupsCollection!.total = 0;
contentfulGraphQLResponse.teamsCollection!.items[0]!.linkedFrom!.teamMembershipCollection =
null;
contentfulGraphQLResponse.teamsCollection!.items[0]!.linkedFrom!.interestGroupsCollection =
null;
contentfulGraphqlClientMock.request.mockResolvedValueOnce(
contentfulGraphQLResponse,
);
Expand All @@ -604,7 +730,87 @@ describe('Analytics Data Provider', () => {
const contentfulGraphQLResponse = getAnalyticsTeamLeadershipQuery();
contentfulGraphQLResponse.teamsCollection!.items[0]!.inactiveSince =
pastDate;
contentfulGraphQLResponse.teamsCollection!.items[0]!.linkedFrom!.interestGroupsCollection!.total = 2;
contentfulGraphQLResponse.teamsCollection!.items[0]!.linkedFrom!.interestGroupsCollection!.items =
[
{
sys: {
id: 'interest-group-1',
},
},
{
sys: {
id: 'interest-group-2',
},
},
];
contentfulGraphqlClientMock.request.mockResolvedValueOnce(
contentfulGraphQLResponse,
);

const result = await analyticsDataProvider.fetchTeamLeadership({});

expect(result.items[0]!.interestGroupPreviousMemberCount).toBe(2);
});

test('Should return interestGroupPreviousMemberCount of 3 when the client returns a total of 2 interest groups associated with the team and one leader of another interest group and the team is inactive', async () => {
const contentfulGraphQLResponse = getAnalyticsTeamLeadershipQuery();
contentfulGraphQLResponse.teamsCollection!.items[0]!.inactiveSince =
pastDate;
contentfulGraphQLResponse.teamsCollection!.items[0]!.linkedFrom!.interestGroupsCollection!.items =
[
{
sys: {
id: 'interest-group-1',
},
},
{
sys: {
id: 'interest-group-2',
},
},
];
contentfulGraphQLResponse.teamsCollection!.items[0]!.linkedFrom!.teamMembershipCollection!.items[0]!.linkedFrom!.usersCollection!.items[0]!.linkedFrom!.interestGroupLeadersCollection!.items[0]!.linkedFrom!.interestGroupsCollection!.items =
[
{
sys: {
id: 'interest-group-3',
},
},
];
contentfulGraphqlClientMock.request.mockResolvedValueOnce(
contentfulGraphQLResponse,
);

const result = await analyticsDataProvider.fetchTeamLeadership({});

expect(result.items[0]!.interestGroupPreviousMemberCount).toBe(3);
});

test('Should return interestGroupPreviousMemberCount of 2 when the client returns a total of 2 interest groups associated with the team and one leader of the same interest group and the team is inactive', async () => {
const contentfulGraphQLResponse = getAnalyticsTeamLeadershipQuery();
contentfulGraphQLResponse.teamsCollection!.items[0]!.inactiveSince =
pastDate;
contentfulGraphQLResponse.teamsCollection!.items[0]!.linkedFrom!.interestGroupsCollection!.items =
[
{
sys: {
id: 'interest-group-1',
},
},
{
sys: {
id: 'interest-group-2',
},
},
];
contentfulGraphQLResponse.teamsCollection!.items[0]!.linkedFrom!.teamMembershipCollection!.items[0]!.linkedFrom!.usersCollection!.items[0]!.linkedFrom!.interestGroupLeadersCollection!.items[0]!.linkedFrom!.interestGroupsCollection!.items =
[
{
sys: {
id: 'interest-group-2',
},
},
];
contentfulGraphqlClientMock.request.mockResolvedValueOnce(
contentfulGraphQLResponse,
);
Expand All @@ -618,7 +824,19 @@ describe('Analytics Data Provider', () => {
const contentfulGraphQLResponse = getAnalyticsTeamLeadershipQuery();
contentfulGraphQLResponse.teamsCollection!.items[0]!.inactiveSince =
null;
contentfulGraphQLResponse.teamsCollection!.items[0]!.linkedFrom!.interestGroupsCollection!.total = 2;
contentfulGraphQLResponse.teamsCollection!.items[0]!.linkedFrom!.interestGroupsCollection!.items =
[
{
sys: {
id: 'interest-group-1',
},
},
{
sys: {
id: 'interest-group-2',
},
},
];
contentfulGraphqlClientMock.request.mockResolvedValueOnce(
contentfulGraphQLResponse,
);
Expand Down
8 changes: 7 additions & 1 deletion apps/crn-server/test/fixtures/analytics.fixtures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,13 @@ export const getAnalyticsTeamLeadershipQuery =
displayName: 'Team A',
linkedFrom: {
interestGroupsCollection: {
total: 1,
items: [
{
sys: {
id: 'interest-group-1',
},
},
],
},
teamMembershipCollection: {
items: [
Expand Down
Loading

0 comments on commit 82e2fd5

Please sign in to comment.