-
Notifications
You must be signed in to change notification settings - Fork 0
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: qbo base mapping #999
Changes from 21 commits
b60ada7
f39398f
99c9616
b10e91c
73eeb11
8ca2603
05eb9ec
706c453
0e8bc0c
00d8ff2
f452b5e
6cc811f
04a61a1
e15d05b
1f4340a
5822376
4785b1b
cdcbf92
1104254
d288097
109b602
c719e97
4b07445
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,171 @@ | ||
/* eslint-disable max-lines */ | ||
/* eslint-disable dot-notation */ | ||
import { ComponentFixture, TestBed } from '@angular/core/testing'; | ||
|
||
import { ActivatedRoute } from '@angular/router'; | ||
import { of, throwError } from 'rxjs'; | ||
import { QboBaseMappingComponent } from './qbo-base-mapping.component'; | ||
import { MappingService } from 'src/app/core/services/common/mapping.service'; | ||
import { IntegrationsToastService } from 'src/app/core/services/common/integrations-toast.service'; | ||
import { WorkspaceService } from 'src/app/core/services/common/workspace.service'; | ||
import { QboImportSettingsService } from 'src/app/core/services/qbo/qbo-configuration/qbo-import-settings.service'; | ||
import { AccountingDisplayName, AccountingField, FyleField, ToastSeverity } from 'src/app/core/models/enum/enum.model'; | ||
import { mockCreditCardAccounts, mockGeneralSettings, mockImportSettings, mockMappingSetting } from '../../../qbo.fixture'; | ||
import { QBOWorkspaceGeneralSetting } from 'src/app/core/models/qbo/db/workspace-general-setting.model'; | ||
import { MappingSetting } from 'src/app/core/models/db/mapping-setting.model'; | ||
import { QBOImportSettingGet } from 'src/app/core/models/qbo/qbo-configuration/qbo-import-setting.model'; | ||
|
||
xdescribe('QboBaseMappingComponent', () => { | ||
describe('QboBaseMappingComponent', () => { | ||
let component: QboBaseMappingComponent; | ||
let fixture: ComponentFixture<QboBaseMappingComponent>; | ||
let mockActivatedRoute: any; | ||
let mockMappingService: jasmine.SpyObj<MappingService>; | ||
let mockToastService: jasmine.SpyObj<IntegrationsToastService>; | ||
let mockWorkspaceService: jasmine.SpyObj<WorkspaceService>; | ||
let mockImportSettingsService: jasmine.SpyObj<QboImportSettingsService>; | ||
|
||
beforeEach(async () => { | ||
mockActivatedRoute = { | ||
params: of({ source_field: 'EMPLOYEE' }), | ||
snapshot: { | ||
params: { source_field: 'EMPLOYEE' } | ||
} | ||
}; | ||
|
||
mockMappingService = jasmine.createSpyObj('MappingService', ['triggerAutoMapEmployees', 'getMappingSettings', 'getPaginatedDestinationAttributes']); | ||
mockToastService = jasmine.createSpyObj('IntegrationsToastService', ['displayToastMessage']); | ||
mockWorkspaceService = jasmine.createSpyObj('WorkspaceService', ['getWorkspaceGeneralSettings']); | ||
mockImportSettingsService = jasmine.createSpyObj('QboImportSettingsService', ['getImportSettings']); | ||
|
||
await TestBed.configureTestingModule({ | ||
declarations: [ QboBaseMappingComponent ] | ||
}) | ||
.compileComponents(); | ||
declarations: [ QboBaseMappingComponent ], | ||
providers: [ | ||
{ provide: ActivatedRoute, useValue: mockActivatedRoute }, | ||
{ provide: MappingService, useValue: mockMappingService }, | ||
{ provide: IntegrationsToastService, useValue: mockToastService }, | ||
{ provide: WorkspaceService, useValue: mockWorkspaceService }, | ||
{ provide: QboImportSettingsService, useValue: mockImportSettingsService } | ||
] | ||
}).compileComponents(); | ||
|
||
fixture = TestBed.createComponent(QboBaseMappingComponent); | ||
component = fixture.componentInstance; | ||
fixture.detectChanges(); | ||
}); | ||
|
||
it('should create', () => { | ||
expect(component).toBeTruthy(); | ||
}); | ||
|
||
it('should trigger auto map employees successfully', () => { | ||
mockMappingService.triggerAutoMapEmployees.and.returnValue(of(null)); | ||
|
||
component.triggerAutoMapEmployees(); | ||
|
||
expect(component.isLoading).toBeFalse(); | ||
expect(mockToastService.displayToastMessage).toHaveBeenCalledWith(ToastSeverity.INFO, 'Auto mapping of employees may take few minutes'); | ||
}); | ||
|
||
it('should handle error when triggering auto map employees', () => { | ||
mockMappingService.triggerAutoMapEmployees.and.returnValue(throwError('Error')); | ||
|
||
component.triggerAutoMapEmployees(); | ||
|
||
expect(component.isLoading).toBeFalse(); | ||
expect(mockToastService.displayToastMessage).toHaveBeenCalledWith(ToastSeverity.ERROR, 'Something went wrong, please try again'); | ||
}); | ||
|
||
it('should handle route parameter changes', () => { | ||
mockWorkspaceService.getWorkspaceGeneralSettings.and.returnValue(of(mockGeneralSettings)); | ||
mockMappingService.getMappingSettings.and.returnValue(of({ count: 1, next: null, previous: null, results: mockImportSettings.mapping_settings })); | ||
mockImportSettingsService.getImportSettings.and.returnValue(of(mockImportSettings)); | ||
mockMappingService.getPaginatedDestinationAttributes.and.returnValue(of(mockCreditCardAccounts)); | ||
|
||
mockActivatedRoute.params = of({ source_field: 'Vendor' }); | ||
fixture.detectChanges(); | ||
|
||
expect(component.sourceField).toBe(FyleField.EMPLOYEE); | ||
expect(component.isLoading).toBeFalse(); | ||
}); | ||
|
||
it('should return employee_field_mapping when sourceField is EMPLOYEE', () => { | ||
component.sourceField = FyleField.EMPLOYEE; | ||
const workspaceGeneralSetting = { employee_field_mapping: 'VENDOR' } as QBOWorkspaceGeneralSetting; | ||
const mappingSettings: MappingSetting[] = []; | ||
|
||
const result = (component as any).getDestinationField(workspaceGeneralSetting, mappingSettings); | ||
expect(result).toBe('VENDOR'); | ||
}); | ||
Comment on lines
+89
to
+96
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove duplicate test cases for 'should return employee_field_mapping when sourceField is EMPLOYEE' The test case in lines 137-144 is a duplicate of the one in lines 89-96. Please remove the duplicate to avoid redundancy. Apply this diff to remove the duplicate test case: - it('should return employee_field_mapping when sourceField is EMPLOYEE', () => {
- component.sourceField = FyleField.EMPLOYEE;
- const workspaceGeneralSetting = { employee_field_mapping: 'VENDOR' } as QBOWorkspaceGeneralSetting;
- const mappingSettings: MappingSetting[] = [];
-
- const result = (component as any).getDestinationField(workspaceGeneralSetting, mappingSettings);
- expect(result).toBe('VENDOR');
- }); Also applies to: 137-144 |
||
|
||
it('should return ACCOUNT when sourceField is CATEGORY', () => { | ||
component.sourceField = FyleField.CATEGORY; | ||
const workspaceGeneralSetting = {} as QBOWorkspaceGeneralSetting; | ||
const mappingSettings: MappingSetting[] = []; | ||
|
||
const result = (component as any).getDestinationField(workspaceGeneralSetting, mappingSettings); | ||
expect(result).toBe(AccountingField.ACCOUNT); | ||
}); | ||
Comment on lines
+98
to
+105
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove duplicate test cases for 'should return ACCOUNT when sourceField is CATEGORY' The test case in lines 146-153 is duplicated from lines 98-105. Consider removing the duplicate to keep the test suite concise. Apply this diff to remove the duplicate test case: - it('should return ACCOUNT when sourceField is CATEGORY', () => {
- component.sourceField = FyleField.CATEGORY;
- const workspaceGeneralSetting = {} as QBOWorkspaceGeneralSetting;
- const mappingSettings: MappingSetting[] = [];
-
- const result = (component as any).getDestinationField(workspaceGeneralSetting, mappingSettings);
- expect(result).toBe(AccountingField.ACCOUNT);
- }); Also applies to: 146-153 |
||
|
||
it('should return destination_field from mappingSettings for other sourceFields', () => { | ||
component.sourceField = FyleField.CATEGORY; | ||
const workspaceGeneralSetting = {} as QBOWorkspaceGeneralSetting; | ||
const mappingSettings: MappingSetting[] = [ | ||
{ | ||
source_field: FyleField.CATEGORY, | ||
destination_field: AccountingField.ACCOUNT, | ||
id: 0, | ||
created_at: new Date(), | ||
updated_at: new Date(), | ||
workspace: 0, | ||
import_to_fyle: false, | ||
is_custom: false, | ||
source_placeholder: null | ||
} | ||
]; | ||
|
||
const result = (component as any).getDestinationField(workspaceGeneralSetting, mappingSettings); | ||
expect(result).toBe('ACCOUNT'); | ||
}); | ||
|
||
it('should return empty string if no matching mapping setting is found', () => { | ||
component.sourceField = FyleField.VENDOR; | ||
const workspaceGeneralSetting = {} as QBOWorkspaceGeneralSetting; | ||
const mappingSettings: MappingSetting[] = []; | ||
|
||
const result = (component as any).getDestinationField(workspaceGeneralSetting, mappingSettings); | ||
expect(result).toBe(''); | ||
}); | ||
Comment on lines
+128
to
+135
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove duplicate test cases for 'should return empty string if no matching mapping setting is found' The test case in lines 163-170 is a duplicate of the one in lines 128-135. Removing duplicates helps maintain clarity in your tests. Apply this diff to remove the duplicate test case: - it('should return empty string if no matching mapping setting is found', () => {
- component.sourceField = FyleField.VENDOR;
- const workspaceGeneralSetting = {} as QBOWorkspaceGeneralSetting;
- const mappingSettings: MappingSetting[] = [];
-
- const result = (component as any).getDestinationField(workspaceGeneralSetting, mappingSettings);
- expect(result).toBe('');
- }); Also applies to: 163-170 |
||
|
||
it('should return employee_field_mapping when sourceField is EMPLOYEE', () => { | ||
component.sourceField = FyleField.EMPLOYEE; | ||
const workspaceGeneralSetting = { employee_field_mapping: 'VENDOR' } as QBOWorkspaceGeneralSetting; | ||
const mappingSettings: MappingSetting[] = []; | ||
|
||
const result = (component as any).getDestinationField(workspaceGeneralSetting, mappingSettings); | ||
expect(result).toBe('VENDOR'); | ||
}); | ||
|
||
it('should return ACCOUNT when sourceField is CATEGORY', () => { | ||
component.sourceField = FyleField.CATEGORY; | ||
const workspaceGeneralSetting = {} as QBOWorkspaceGeneralSetting; | ||
const mappingSettings: MappingSetting[] = []; | ||
|
||
const result = (component as any).getDestinationField(workspaceGeneralSetting, mappingSettings); | ||
expect(result).toBe(AccountingField.ACCOUNT); | ||
}); | ||
|
||
it('should return destination_field from mappingSettings for VENDOR sourceField', () => { | ||
component.sourceField = FyleField.VENDOR; | ||
const workspaceGeneralSetting = {} as QBOWorkspaceGeneralSetting; | ||
|
||
const result = (component as any).getDestinationField(workspaceGeneralSetting, mockMappingSetting); | ||
expect(result).toBe(AccountingField.ACCOUNT); | ||
}); | ||
|
||
it('should return empty string if no matching mapping setting is found', () => { | ||
component.sourceField = FyleField.VENDOR; | ||
const workspaceGeneralSetting = {} as QBOWorkspaceGeneralSetting; | ||
const mappingSettings: MappingSetting[] = []; | ||
|
||
const result = (component as any).getDestinationField(workspaceGeneralSetting, mappingSettings); | ||
expect(result).toBe(''); | ||
}); | ||
}); |
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.
Correct the expectation in 'should handle route parameter changes' test
In this test, you're setting
mockActivatedRoute.params = of({ source_field: 'Vendor' });
(line 82), but the expectation on line 85 isexpect(component.sourceField).toBe(FyleField.EMPLOYEE);
. Shouldn'tcomponent.sourceField
reflect the updated route parameter and beFyleField.VENDOR
instead?Apply this diff to correct the expectation:
📝 Committable suggestion