Skip to content

Commit

Permalink
Merge pull request #2104 from HHS/kw-no-identical-merge
Browse files Browse the repository at this point in the history
[TTAHUB-2764] Roll-up the same goals without a creator
  • Loading branch information
kryswisnaskas authored Apr 23, 2024
2 parents 99fc827 + 471f4f1 commit b969e33
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 8 deletions.
9 changes: 7 additions & 2 deletions src/goalServices/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const goalFieldTransate = {
const findOrFailExistingGoal = (needle, haystack, translate = goalFieldTransate) => {
const needleCollaborators = (needle.collaborators || []).map(
(c) => c.goalCreatorName,
).filter(Boolean) ?? [];
).filter(Boolean);

const haystackCollaborators = haystack.flatMap(
(g) => (g.collaborators || []).map((c) => c.goalCreatorName).filter(Boolean),
Expand All @@ -22,7 +22,12 @@ const findOrFailExistingGoal = (needle, haystack, translate = goalFieldTransate)
&& g[translate.name].trim() === needle.name.trim()
&& g[translate.source] === needle.source
&& g[translate.responsesForComparison] === responsesForComparison(needle)
&& haystackCollaborators.some((c) => needleCollaborators.includes(c))
&& (
// Check if both needle and haystack goal have no valid collaborators
(needleCollaborators.length === 0 && (g.collaborators || [])
.every((c) => c.goalCreatorName === undefined))
|| haystackCollaborators.some((c) => needleCollaborators.includes(c))
)
));
};

Expand Down
25 changes: 19 additions & 6 deletions src/services/recipient.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -869,12 +869,12 @@ describe('Recipient DB service', () => {

it('properly de-duplicates based on responses', async () => {
const { goalRows } = await getGoalsByActivityRecipient(recipient.id, region, {});
expect(goalRows.length).toBe(4);
expect(goalRows.length).toBe(3);

const doubler = goalRows.find((r) => r.responsesForComparison === 'not sure,dont have to');
expect(doubler).toBeTruthy();

expect(doubler.ids.length).toBe(1);
expect(doubler.ids.length).toBe(2);

const singler = goalRows.find((r) => r.responsesForComparison === 'gotta');
expect(singler).toBeTruthy();
Expand All @@ -884,6 +884,19 @@ describe('Recipient DB service', () => {
expect(noResponse).toBeTruthy();
expect(noResponse.ids.length).toBe(1);
});

it('properly combines the same goals with no creators/collaborators', async () => {
// Remove other goals
goals[0].destroy();
goals[3].destroy();

const { goalRows } = await getGoalsByActivityRecipient(recipient.id, region, {});
expect(goalRows.length).toBe(1);
// Verify goal 2 and 3 have empty creators/collaborators
expect(goalRows[0].collaborators[0].goalCreator).toBe(undefined);
// Verify goal 2 and 3 are rolled up
expect(goalRows[0].ids.length).toBe(2);
});
});

describe('reduceObjectivesForRecipientRecord', () => {
Expand Down Expand Up @@ -1062,16 +1075,16 @@ describe('Recipient DB service', () => {
it('successfully reduces data without losing topics', async () => {
const goalsForRecord = await getGoalsByActivityRecipient(recipient.id, 5, {});

expect(goalsForRecord.count).toBe(2);
expect(goalsForRecord.goalRows.length).toBe(2);
expect(goalsForRecord.count).toBe(1);
expect(goalsForRecord.goalRows.length).toBe(1);
expect(goalsForRecord.allGoalIds.length).toBe(2);

const goal = goalsForRecord.goalRows[0];
expect(goal.reasons.length).toBe(0);
expect(goal.reasons.length).toBe(1);

expect(goal.objectives.length).toBe(1);
const objective = goal.objectives[0];
expect(objective.topics.length).toBe(1);
expect(objective.topics.length).toBe(4);
expect(objective.supportType).toBe('Planning');
});
});
Expand Down

0 comments on commit b969e33

Please sign in to comment.