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

Create tests for ErrorMessage, ErrorHandling and Milestone services #290

Closed
wants to merge 11 commits into from

Conversation

MadLamprey
Copy link
Contributor

Summary:

Fixes part of #87

Type of change:

  • 🧪 Tests Update

Changes Made:

  • Added test cases for error-handling.service.ts, error-message.service.ts and milestone.service.ts

Proposed Commit Message:

Create tests for ErrorMessage, ErrorHandling and Milestone services

Currently, there are no tests written for ErrorMessage, ErrorHandling and Milestone services.

Let's create tests for ErrorMessage, ErrorHandling and Milestone services.

Comment on lines +5 to +116

describe('ErrorMessageService: invalidUrlMessage()', () => {
it('should return the correct message', () => {
expect(ErrorMessageService.invalidUrlMessage()).toBe(
'URL is invalid, or repository does not exist, please indicate the repository you wish to view to continue.'
);
});
});

describe('ErrorMessageService: unableToFetchIssuesMessage()', () => {
it('should return the correct message', () => {
expect(ErrorMessageService.unableToFetchIssuesMessage()).toBe('Failed to fetch issue.');
});
});

describe('ErrorMessageService: usesrsUnassignableMessage()', () => {
it('should return the correct message', () => {
expect(ErrorMessageService.usersUnassignableMessage('test')).toBe(
'Cannot assign test to the issue. Please check if test is authorized.'
);
});
});

describe('ErrorMessageService: unableToFetchMilestoneMessage()', () => {
it('should return the correct message', () => {
expect(ErrorMessageService.unableToFetchMilestoneMessage()).toBe('Failed to fetch milestones.');
});
});

describe('ErrorMessageService: unableToFetchLabelsMessage()', () => {
it('should return the correct message', () => {
expect(ErrorMessageService.unableToFetchLabelsMessage()).toBe('Failed to fetch labels.');
});
});

describe('ErrorMessageService: unableToFetchUsersMessage()', () => {
it('should return the correct message', () => {
expect(ErrorMessageService.unableToFetchUsersMessage()).toBe('Failed to fetch assignable users for repository');
});
});

describe('ErrorMessageService: unableToFetchDataFileMessage()', () => {
it('should return the correct message', () => {
expect(ErrorMessageService.unableToFetchDataFileMessage()).toBe('Failed to fetch data file.');
});
});

describe('ErrorMessageService: unableToFetchEventsMessage()', () => {
it('should return the correct message', () => {
expect(ErrorMessageService.unableToFetchEventsMessage()).toBe('Failed to fetch issue events for repository');
});
});

describe('ErrorMessageService: unableToFetchActivityEventsMessage()', () => {
it('should return the correct message', () => {
expect(ErrorMessageService.unableToFetchActivityEventsMessage()).toBe('Failed to fetch activity events for repository');
});
});

describe('ErrorMessageService: unableToFetchLatestRelease()', () => {
it('should return the correct message', () => {
expect(ErrorMessageService.unableToFetchLatestReleaseMessage()).toBe('Failed to fetch latest release.');
});
});

describe('ErrorMessageService: unableToFetchSettingsFileMessage()', () => {
it('should return the correct message', () => {
expect(ErrorMessageService.unableToFetchSettingsFileMessage()).toBe('Failed to fetch settings file.');
});
});

describe('ErrorMessageService: unableToFetchAuthenticatedUsersMessage()', () => {
it('should return the correct message', () => {
expect(ErrorMessageService.unableToFetchAuthenticatedUsersMessage()).toBe('Failed to fetch authenticated user.');
});
});

describe('ErrorMessageService: unableToOpenInBrowserMessage()', () => {
it('should return the correct message', () => {
expect(ErrorMessageService.unableToOpenInBrowserMessage()).toBe('Unable to open this issue in Browser');
});
});

describe('ErrorMessageService: applicationVersionOutdatedMessage()', () => {
it('should return the correct message', () => {
expect(ErrorMessageService.applicationVersionOutdatedMessage()).toBe('Please update to the latest version of WATcher.');
});
});

describe('ErrorMessageService: multipleDropdownOptionsErrorMessage()', () => {
it('should return the correct message', () => {
expect(ErrorMessageService.multipleDropdownOptionsErrorMessage()).toBe('Supply either Dropdown option number or text, not both.');
});
});

describe('ErrorMessageService: noDropdownOptionsErrorMessage()', () => {
it('should return the correct message', () => {
expect(ErrorMessageService.noDropdownOptionsErrorMessage()).toBe('No Dropdown identification parameters supplied.');
});
});
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure if there's any benefit to write test cases for the constant provider service. If test cases fail due to future changes in constant values, developers will likely just edit the test cases, resulting in duplicated changes. Also, I think that integration tests for services using these constants should suffice to catch any errors in those constant values.
@CATcher-org/2324s2 what do yall think?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah I'm in agreement with you, don't think we need tests for this.

Copy link
Contributor

@luminousleek luminousleek left a comment

Choose a reason for hiding this comment

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

Thanks for this PR! Some small changes needed, and as per Nereus's comment I don't think we need tests for ErrorMessageService.

Also, please split this PR into one PR for each service you are writing tests for.

Comment on lines +5 to +116

describe('ErrorMessageService: invalidUrlMessage()', () => {
it('should return the correct message', () => {
expect(ErrorMessageService.invalidUrlMessage()).toBe(
'URL is invalid, or repository does not exist, please indicate the repository you wish to view to continue.'
);
});
});

describe('ErrorMessageService: unableToFetchIssuesMessage()', () => {
it('should return the correct message', () => {
expect(ErrorMessageService.unableToFetchIssuesMessage()).toBe('Failed to fetch issue.');
});
});

describe('ErrorMessageService: usesrsUnassignableMessage()', () => {
it('should return the correct message', () => {
expect(ErrorMessageService.usersUnassignableMessage('test')).toBe(
'Cannot assign test to the issue. Please check if test is authorized.'
);
});
});

describe('ErrorMessageService: unableToFetchMilestoneMessage()', () => {
it('should return the correct message', () => {
expect(ErrorMessageService.unableToFetchMilestoneMessage()).toBe('Failed to fetch milestones.');
});
});

describe('ErrorMessageService: unableToFetchLabelsMessage()', () => {
it('should return the correct message', () => {
expect(ErrorMessageService.unableToFetchLabelsMessage()).toBe('Failed to fetch labels.');
});
});

describe('ErrorMessageService: unableToFetchUsersMessage()', () => {
it('should return the correct message', () => {
expect(ErrorMessageService.unableToFetchUsersMessage()).toBe('Failed to fetch assignable users for repository');
});
});

describe('ErrorMessageService: unableToFetchDataFileMessage()', () => {
it('should return the correct message', () => {
expect(ErrorMessageService.unableToFetchDataFileMessage()).toBe('Failed to fetch data file.');
});
});

describe('ErrorMessageService: unableToFetchEventsMessage()', () => {
it('should return the correct message', () => {
expect(ErrorMessageService.unableToFetchEventsMessage()).toBe('Failed to fetch issue events for repository');
});
});

describe('ErrorMessageService: unableToFetchActivityEventsMessage()', () => {
it('should return the correct message', () => {
expect(ErrorMessageService.unableToFetchActivityEventsMessage()).toBe('Failed to fetch activity events for repository');
});
});

describe('ErrorMessageService: unableToFetchLatestRelease()', () => {
it('should return the correct message', () => {
expect(ErrorMessageService.unableToFetchLatestReleaseMessage()).toBe('Failed to fetch latest release.');
});
});

describe('ErrorMessageService: unableToFetchSettingsFileMessage()', () => {
it('should return the correct message', () => {
expect(ErrorMessageService.unableToFetchSettingsFileMessage()).toBe('Failed to fetch settings file.');
});
});

describe('ErrorMessageService: unableToFetchAuthenticatedUsersMessage()', () => {
it('should return the correct message', () => {
expect(ErrorMessageService.unableToFetchAuthenticatedUsersMessage()).toBe('Failed to fetch authenticated user.');
});
});

describe('ErrorMessageService: unableToOpenInBrowserMessage()', () => {
it('should return the correct message', () => {
expect(ErrorMessageService.unableToOpenInBrowserMessage()).toBe('Unable to open this issue in Browser');
});
});

describe('ErrorMessageService: applicationVersionOutdatedMessage()', () => {
it('should return the correct message', () => {
expect(ErrorMessageService.applicationVersionOutdatedMessage()).toBe('Please update to the latest version of WATcher.');
});
});

describe('ErrorMessageService: multipleDropdownOptionsErrorMessage()', () => {
it('should return the correct message', () => {
expect(ErrorMessageService.multipleDropdownOptionsErrorMessage()).toBe('Supply either Dropdown option number or text, not both.');
});
});

describe('ErrorMessageService: noDropdownOptionsErrorMessage()', () => {
it('should return the correct message', () => {
expect(ErrorMessageService.noDropdownOptionsErrorMessage()).toBe('No Dropdown identification parameters supplied.');
});
});
Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah I'm in agreement with you, don't think we need tests for this.

expect(mockSnackBar.openFromComponent).toHaveBeenCalledWith(FormErrorComponent, { data: HTTP_422_ERROR });
});

it('should use the GeneralMessageErrorComponent when handling other http errors', () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Might want to test another HttpError to test the default case.

githubServiceSpy.fetchAllMilestones.and.returnValue(of(mockMilestones));
milestoneService.fetchMilestones().subscribe((response) => {
expect(githubServiceSpy.fetchAllMilestones).toHaveBeenCalled();
expect(response).toEqual(mockMilestones);
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think we need this line since you're already setting the return value ofr fetchAllMilestones as mockMilestones three lines above?

Copy link
Contributor

@NereusWB922 NereusWB922 left a comment

Choose a reason for hiding this comment

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

Great work on adding new test cases! Just a minor suggestion to ensure proper handling of asynchronous behavior in the test.

Comment on lines +16 to +25
it('should fetch all milestones', async () => {
const mockMilestones = [{ title: 'Milestone 1' }, { title: 'Milestone 2' }];
githubServiceSpy.fetchAllMilestones.and.returnValue(of(mockMilestones));
milestoneService.fetchMilestones().subscribe((response) => {
expect(githubServiceSpy.fetchAllMilestones).toHaveBeenCalled();
expect(response).toEqual(mockMilestones);
expect(milestoneService.milestones.length).toBe(3);
expect(milestoneService.milestones[0].title).toBe('Milestone 1');
expect(milestoneService.hasNoMilestones).toBeFalse();
});
Copy link
Contributor

Choose a reason for hiding this comment

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

Consider using Jasmine's done() callback at the end of the assertions. This is to ensure that the test doesn't complete before the value is emitted, which would lead to the assertions not being executed by Jasmine.

The same issue applies to the test case below.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I looked into this, and received an Error Log.

Screenshot 2024-03-15 at 2 11 33 PM

Copy link
Contributor

Choose a reason for hiding this comment

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

If I am not wrong, async/await cannot be used with done. You try remove the async keyword.

@MadLamprey MadLamprey closed this Mar 25, 2024
@MadLamprey
Copy link
Contributor Author

PR has been separated into #303 and #304.

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.

3 participants