-
Notifications
You must be signed in to change notification settings - Fork 0
test: intacct import settings utility functions #1013
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
test: intacct import settings utility functions #1013
Conversation
|
Caution Review failedThe pull request is closed. WalkthroughThe pull request introduces modifications to the test suite of the Changes
Possibly related PRs
Suggested labels
Suggested reviewers
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
|
PR title must start with "fix:", "feat:", "chore:", "refactor", or "test:" (case-insensitive) |
|
PR title must start with "fix:", "feat:", "chore:", "refactor", or "test:" (case-insensitive) |
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.
Actionable comments posted: 6
🧹 Outside diff range and nitpick comments (2)
src/app/integrations/intacct/intacct.fixture.ts (1)
867-879: LGTM! Consider adding comments for clarity.The new constants
customFieldValueandcustomFieldare well-structured and consistent with the existing code style. They provide clear templates for custom field mapping and test field definition, which will be useful for testing scenarios involving custom fields.To improve clarity, consider adding brief comments explaining the purpose of these constants, especially if they are used in specific test cases. For example:
// Template for custom field mapping export const customFieldValue = { // ... (existing code) }; // Definition of a test custom field export const customField = { // ... (existing code) };src/app/integrations/intacct/intacct-shared/intacct-import-settings/intacct-import-settings.component.spec.ts (1)
426-436: Remove Unnecessary Initialtick()CallIn the test
refreshDimensions should call refresh services and show toast, the initialtick()call before any asynchronous operation is unnecessary and can be removed to simplify the test.- tick(); component.refreshDimensions(true);
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
📒 Files selected for processing (2)
- src/app/integrations/intacct/intacct-shared/intacct-import-settings/intacct-import-settings.component.spec.ts (6 hunks)
- src/app/integrations/intacct/intacct.fixture.ts (1 hunks)
🧰 Additional context used
🔇 Additional comments (1)
src/app/integrations/intacct/intacct-shared/intacct-import-settings/intacct-import-settings.component.spec.ts (1)
85-86: Ensure Correct Handling of Refresh Service ResponsesThe
refreshSageIntacctDimensionsandrefreshFyleDimensionsservices are being stubbed to return an observable of an empty string (of('')). Confirm that the component correctly handles these responses, especially if the services might return different types or error responses in real scenarios.To verify the response handling, consider checking if the component adequately processes the actual responses from these services, and that any potential errors are gracefully managed.
| const mockStartTime = new Date(); | ||
| component['sessionStartTime'] = mockStartTime; | ||
| siImportSettingService.postImportSettings.and.returnValue(of(importSettings)); | ||
|
|
||
| component.ngOnInit(); | ||
| tick(); | ||
|
|
||
| component.save(); | ||
| tick(); | ||
|
|
||
| expect(trackingService.trackTimeSpent).toHaveBeenCalledWith( | ||
| TrackingApp.INTACCT, | ||
| Page.IMPORT_SETTINGS_INTACCT, | ||
| mockStartTime | ||
| ); | ||
| })); |
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.
🛠️ Refactor suggestion
Avoid Using Actual Dates in Time Tracking Tests
Using new Date() in tests can lead to inconsistent results due to time variations. Consider mocking the date or using a fixed timestamp to ensure consistent and reliable test outcomes.
You can use jasmine.clock() to mock the date:
beforeEach(() => {
jasmine.clock().install();
const baseTime = new Date(2021, 0, 1);
jasmine.clock().mockDate(baseTime);
});
afterEach(() => {
jasmine.clock().uninstall();
});| component.sageIntacctFields = []; | ||
| expect(component.showOrHideAddButton()).toBeTrue(); | ||
|
|
||
| for (let i = 0; i < component.importSettingsForm.controls.expenseFields.value.length; i++) { | ||
| component.sageIntacctFields.push({} as ExpenseField); | ||
| } | ||
| expect(component.showOrHideAddButton()).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.
🛠️ Refactor suggestion
Simplify Logic in showOrHideAddButton Method
The showOrHideAddButton method uses a loop to determine the return value. This can be simplified by directly comparing the lengths of sageIntacctFields and expenseFields.
Simplify the method as follows:
showOrHideAddButton(): boolean {
return this.sageIntacctFields.length > this.importSettingsForm.controls.expenseFields.value.length;
}| source_field: [MappingSourceField.PROJECT], | ||
| destination_field: ['TEST_FIELD'], | ||
| import_to_fyle: [false], | ||
| is_custom: [false] | ||
| }); | ||
| expenseFieldsArray.push(newExpenseField); | ||
|
|
||
| component.acceptDependentFieldWarning(false); | ||
|
|
||
| expect(newExpenseField.get('import_to_fyle')?.value).toBeTrue(); | ||
| expect(component.importSettingsForm.get('isDependentImportEnabled')?.value).toBeTrue(); | ||
| expect(component.importSettingsForm.get('costCodes')?.disabled).toBeTrue(); | ||
| expect(component.importSettingsForm.get('costTypes')?.disabled).toBeTrue(); | ||
| }); |
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.
Clarify Logic in acceptDependentFieldWarning Test
In the test acceptDependentFieldWarning should handle warning being rejected, the effect of passing false to acceptDependentFieldWarning might be counterintuitive. Ensure the test accurately reflects the expected behavior, and consider adding comments or renaming variables for clarity.
Consider updating the test to make the logic clearer:
component.acceptDependentFieldWarning(false); // User rejects the warning
expect(newExpenseField.get('import_to_fyle')?.value).toBeTrue(); // import_to_fyle is set to true despite rejectionEnsure that the component's logic aligns with user expectations when warnings are accepted or rejected.
| it('should handle dependent field creation', () => { | ||
| component.customFieldForDependentField = true; | ||
| component.customFieldForm = component['formBuilder'].group({ | ||
| attribute_type: ['Test Field'], | ||
| source_placeholder: ['Test Placeholder'] | ||
| }); | ||
| component['isCostCodeFieldSelected'] = true; | ||
| component.customFieldControl = component.importSettingsForm.get('costCodes') as AbstractControl; | ||
|
|
||
| component.saveCustomField(); | ||
|
|
||
| expect(component.costCodeFieldOption.length).toBeGreaterThan(1); | ||
| expect(component.showDialog).toBeFalse(); | ||
| }); | ||
|
|
||
| it('should handle non-dependent field creation', () => { | ||
| component.customFieldForDependentField = false; | ||
| component.customFieldForm = component['formBuilder'].group({ | ||
| attribute_type: ['Test Field'], | ||
| source_placeholder: ['Test Placeholder'] | ||
| }); | ||
| spyOn(component.customFieldForm, 'reset').and.callThrough(); | ||
| component.customFieldControl = component['createFormGroup'](customFieldValue); | ||
|
|
||
| component.saveCustomField(); | ||
|
|
||
| expect(component.customField).toEqual(customField); | ||
| expect(component.fyleFields[component.fyleFields.length - 2]).toEqual(customField); | ||
| expect(component.fyleFields[component.fyleFields.length - 1]).toEqual(component.customFieldOption[0]); | ||
| expect(component.customFieldForm.reset).toHaveBeenCalled(); | ||
| }); |
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.
🛠️ Refactor suggestion
Consolidate Duplicate Test Setup in saveCustomField Tests
The two tests within describe('saveCustomField') share similar setup code. Consider extracting the common setup into a beforeEach block or a helper function to reduce duplication and improve maintainability.
Example:
beforeEach(() => {
component.customFieldForm = component['formBuilder'].group({
attribute_type: ['Test Field'],
source_placeholder: ['Test Placeholder']
});
});| siImportSettingService.postImportSettings.and.returnValue(throwError(() => new Error())); | ||
|
|
||
| component.ngOnInit(); | ||
| tick(); | ||
|
|
||
| component.save(); | ||
| tick(); | ||
|
|
||
| expect(siImportSettingService.postImportSettings).toHaveBeenCalled(); | ||
| expect(toastService.displayToastMessage).toHaveBeenCalledWith( | ||
| ToastSeverity.ERROR, | ||
| 'Error saving import settings, please try again later' | ||
| ); | ||
| expect(component.saveInProgress).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.
🛠️ Refactor suggestion
Use Specific Error Objects in Error Handling Tests
In the test case should handle error when saving import settings, a generic Error object is thrown without specific context. Using a more detailed error object helps ensure that the component correctly handles various error scenarios.
Modify the test to use a specific error:
- siImportSettingService.postImportSettings.and.returnValue(throwError(() => new Error()));
+ const errorResponse = new Error('Network error');
+ siImportSettingService.postImportSettings.and.returnValue(throwError(() => errorResponse));📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| siImportSettingService.postImportSettings.and.returnValue(throwError(() => new Error())); | |
| component.ngOnInit(); | |
| tick(); | |
| component.save(); | |
| tick(); | |
| expect(siImportSettingService.postImportSettings).toHaveBeenCalled(); | |
| expect(toastService.displayToastMessage).toHaveBeenCalledWith( | |
| ToastSeverity.ERROR, | |
| 'Error saving import settings, please try again later' | |
| ); | |
| expect(component.saveInProgress).toBeFalse(); | |
| })); | |
| const errorResponse = new Error('Network error'); | |
| siImportSettingService.postImportSettings.and.returnValue(throwError(() => errorResponse)); | |
| component.ngOnInit(); | |
| tick(); | |
| component.save(); | |
| tick(); | |
| expect(siImportSettingService.postImportSettings).toHaveBeenCalled(); | |
| expect(toastService.displayToastMessage).toHaveBeenCalledWith( | |
| ToastSeverity.ERROR, | |
| 'Error saving import settings, please try again later' | |
| ); | |
| expect(component.saveInProgress).toBeFalse(); | |
| })); |
| it('should update validators when importTaxCodes value changes', () => { | ||
| const taxCodesControl = component.importSettingsForm.get('sageIntacctTaxCodes'); | ||
|
|
||
| component.importSettingsForm.patchValue({ | ||
| importTaxCodes: true | ||
| }); | ||
| expect(taxCodesControl?.hasValidator(Validators.required)).toBeTrue(); | ||
|
|
||
| component.importSettingsForm.patchValue({ | ||
| importTaxCodes: false | ||
| }); | ||
| expect(taxCodesControl?.hasValidator(Validators.required)).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.
Trigger Validator Updates After Form Value Changes
In the test should update validators when importTaxCodes value changes, after changing the form values with patchValue, the validators may not update immediately. To ensure the validators are re-evaluated, call updateValueAndValidity() on the control.
Update the test as follows:
component.importSettingsForm.patchValue({
importTaxCodes: true
});
+ taxCodesControl?.updateValueAndValidity();
expect(taxCodesControl?.hasValidator(Validators.required)).toBeTrue();
component.importSettingsForm.patchValue({
importTaxCodes: false
});
+ taxCodesControl?.updateValueAndValidity();
expect(taxCodesControl?.hasValidator(Validators.required)).toBeFalse();📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| it('should update validators when importTaxCodes value changes', () => { | |
| const taxCodesControl = component.importSettingsForm.get('sageIntacctTaxCodes'); | |
| component.importSettingsForm.patchValue({ | |
| importTaxCodes: true | |
| }); | |
| expect(taxCodesControl?.hasValidator(Validators.required)).toBeTrue(); | |
| component.importSettingsForm.patchValue({ | |
| importTaxCodes: false | |
| }); | |
| expect(taxCodesControl?.hasValidator(Validators.required)).toBeFalse(); | |
| }); | |
| it('should update validators when importTaxCodes value changes', () => { | |
| const taxCodesControl = component.importSettingsForm.get('sageIntacctTaxCodes'); | |
| component.importSettingsForm.patchValue({ | |
| importTaxCodes: true | |
| }); | |
| taxCodesControl?.updateValueAndValidity(); | |
| expect(taxCodesControl?.hasValidator(Validators.required)).toBeTrue(); | |
| component.importSettingsForm.patchValue({ | |
| importTaxCodes: false | |
| }); | |
| taxCodesControl?.updateValueAndValidity(); | |
| expect(taxCodesControl?.hasValidator(Validators.required)).toBeFalse(); | |
| }); |
Clickup
https://app.clickup.com/t/86cwh86d3
Summary by CodeRabbit
New Features
Bug Fixes
Documentation