-
Notifications
You must be signed in to change notification settings - Fork 25
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
Conversation
|
||
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.'); | ||
}); | ||
}); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this 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.
|
||
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.'); | ||
}); | ||
}); |
There was a problem hiding this comment.
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', () => { |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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?
There was a problem hiding this 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.
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(); | ||
}); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
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.
Summary:
Fixes part of #87
Type of change:
Changes Made:
error-handling.service.ts
,error-message.service.ts
andmilestone.service.ts
Proposed Commit Message: