Skip to content

Add unit tests for issues and PRs#505

Open
bipplane wants to merge 10 commits intoCATcher-org:mainfrom
bipplane:issue-model-tests
Open

Add unit tests for issues and PRs#505
bipplane wants to merge 10 commits intoCATcher-org:mainfrom
bipplane:issue-model-tests

Conversation

@bipplane
Copy link
Copy Markdown
Contributor

@bipplane bipplane commented Aug 10, 2025

Summary:

Fixes #453
Add test case coverage for issues and PRs, refactoring CATcher code into WATcher context during the process

Type of change:

  • 🧪 Tests Update
  • 🎨 Code Refactoring

Changes Made:

  • Created githubpullrequest.constants.ts with mock PR data for testing
  • Update issue and add PR unit test cases
  • Refactored tests from CATcher to WATcher context

Proposed Commit Message:

Add unit tests for issues and PRs

Added comprehensive unit tests for issue and PR functionality.

Fixed null author test case by adding proper fallback to 'ghost' 
placeholder.

Refactored test suite from CATcher bug reporting context to WATcher
issue monitoring context, and renamed outdated functions.

Checklist:

  • I have tested my changes thoroughly.
  • I have created tests for any new code files created in this PR or provided a link to a issue/PR that addresses this.
  • I have added or modified code comments to improve code readability where necessary.
  • I have updated the project's documentation as necessary.

Copy link
Copy Markdown
Contributor

@SAN-MUYUN SAN-MUYUN left a comment

Choose a reason for hiding this comment

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

Overall the code written is neat and concise. Appreciate the effort to add more test cases for Issues and PRs. 👍

There will be some merge conflicts or overwritten of code when PR #499(Refactor: split issue and pull request logic for improved clarity) is merged.

It would be good to separate testing for Issues and PRs for all the test cases. There are also some repetition in the testcases which you might want to re-consider.

}

public static createPhaseBugReportingIssue(githubIssue: GithubIssue): Issue {
public static createFromGithubIssue(githubIssue: GithubIssue): Issue {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Appreciate the effort to rename this method and make it more independent of CATcher. Take note that this may result in merge conflict with PR #499 .

const issueUpdatedEarlier: Issue = Issue.createPhaseBugReportingIssue(ISSUE_UPDATED_EARLIER);
const issueUpdatedLater: Issue = Issue.createPhaseBugReportingIssue(ISSUE_UPDATED_LATER);
const issueUpdatedEarlier: Issue = Issue.createFromGithubIssue(ISSUE_UPDATED_EARLIER);
const issueUpdatedLater: Issue = Issue.createFromGithubIssue(ISSUE_UPDATED_LATER);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Similar to above, the naming might cause merge conflicts with #499 .

expect(pr.assignees).toEqual([USER_ANUBHAV.loginId]);
});

it('should handle closed pull requests correctly', () => {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

For this test case, the testing seems fine to me, but the description can be more precise. Instead of saying "handle" closed PR correctly, which could be vague, it might be better to rephrase it as "creates" closed pull requests correctly

expect(pr.reviewDecision).toEqual(ReviewDecision.APPROVED);
});

it('should handle draft pull requests correctly', () => {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

similar as above


expect(pr.issueOrPr).toEqual('PullRequest');
expect(draftPr.issueOrPr).toEqual('PullRequest');
expect(issue.issueOrPr).toEqual('Issue');
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Good attempt to try testing if issues and PRs are created correctly. However, this test case seems a little repetitive with the previous ones since they both creates an Issue object and check for issueOrPr property of this object. It might be better to move this test case under the test file for filters, to check if pull requests can be correctly identified among several PRs and issues

const issue = Issue.createFromGithubIssue(ISSUE_WITH_EMPTY_DESCRIPTION);

expect(pr.headRepository).toEqual('testuser/WATcher-test');
expect(issue.headRepository).toBeUndefined();
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

It would be good if you can test issues and PRs separately, rather than mixing issues and PRs together. It might be fine to leave it for now, but it will need to be separated after #499 is merged.

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.

Create unit tests for issue model

2 participants