Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TTAHUB-3541] Add code coverage for src/services/recipient.js #2591

Merged
merged 10 commits into from
Jan 15, 2025

Conversation

kryswisnaskas
Copy link
Collaborator

@kryswisnaskas kryswisnaskas commented Jan 10, 2025

Description of change

Adds test coverage for src/services/recipient.js

image

How to test

Verify the test coverage for src/services/recipient.js is above 90%

Issue(s)

Checklists

Every PR

  • Meets issue criteria
  • JIRA ticket status updated
  • Code is meaningfully tested
  • [n/a] Meets accessibility standards (WCAG 2.1 Levels A, AA)
  • [n/a] API Documentation updated
  • [n/a] Boundary diagram updated
  • [n/a] Logical Data Model updated
  • [n/a] Architectural Decision Records written for major infrastructure decisions
  • [n/a] UI review complete
  • [n/a] QA review complete

Before merge to main

  • [n/a] OHS demo complete
  • Ready to create production PR

Production Deploy

  • Staging smoke test completed

After merge/deploy

  • Update JIRA ticket status

@kryswisnaskas kryswisnaskas changed the title [TTAHUB-3541] Add code coverage for recipient.js [TTAHUB-3541] Add code coverage for src/services/recipient.js Jan 10, 2025
@kryswisnaskas kryswisnaskas marked this pull request as ready for review January 10, 2025 18:41
Comment on lines 392 to 394
export function ensureArray(input) {
return Array.isArray(input) ? input : [];
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just a thought, but maybe we could move this function to constants or somewhere else

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved.

Comment on lines 353 to 373
const newTopics = uniq((topics || null)
.filter((topic) => topic !== null && topic !== undefined).map((topic) => {
if (typeof topic === 'string') {
return topic;
}

if (topic.name) {
return topic.name;
}
if (typeof topic === 'object' && topic.name) {
return topic.name.trim();
}

return topic;
}));
return topic;
}));

newTopics.sort();
newTopics.sort((a, b) => {
if (typeof a === 'string' && typeof b === 'string') {
return a.localeCompare(b);
}
if (typeof a === 'string') return -1;
if (typeof b === 'string') return 1;
return 0;
});
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This wont reduce it as expected, the unique or similar functionality needs to be last or twice. topcis = ['apples', { name: "apples"}] => ["apples", "apples"]

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are good here as is for the case topics = ['apples', { name: "apples"}] => ["apples", "apples"]. The second 'apples' topic is already handled by this logic:

      if (typeof topic === 'object' && topic.name) {
        return topic.name.trim();
      }

and deduplicated via uniq

Additionally, the existing test case on line 1024, it('should handle mixed strings and objects with "name"', () => { already tests and confirms it.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Its interesting that you are using multiple methods to unique the values, lodash.unique and [...new Set()].

I don't see how the code would do that?

const newTopics = uniq((topics || null)  /// the only unique is on the initial input, which will not handle the string /object case.
    .filter((topic) => topic !== null && topic !== undefined) // this filters out the empty cases, but not the empty string case.
    .map((topic) => {
      if (typeof topic === 'string') {
        return topic;  // return if its a string, even empty or space padded.
      }

      if (typeof topic === 'object' && topic.name) {
        return topic.name.trim(); // return the trimed value only when it was an object
      }

      return topic; // return what ever, random objects
    }));

the result in newTopics can have duplicates, and space padded values if they came in a strings.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see the issue with how I was reading it now. the map is within the uniq.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The values from the string path do still need to be trimmed

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Its interesting that you are using multiple methods to unique the values, lodash.unique and [...new Set()].

Good catch! I prefer using native JavaScript functions like Set to avoid relying on external libraries, but since the code works fine as-is, I don’t see a big reason to refactor it right now. If we end up revisiting this file later, I’d be up for cleaning it up to use native methods.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The values from the string path do still need to be trimmed

trim() was added.

@GarrettEHill GarrettEHill dismissed their stale review January 14, 2025 01:02

After further reading the main issue was a mistake in how I was reading the code, and not the code it self

@kryswisnaskas kryswisnaskas merged commit 079ee5e into main Jan 15, 2025
10 checks passed
@kryswisnaskas kryswisnaskas deleted the kw-ttahub-3541 branch January 15, 2025 17:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants