-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* test: QBO complete export log * lint fix * test: qbo skipped export log component * rem failing assertions * updated tests and fixtures * fixed breaking tests * lint fixes * pr comments * test: qbo mapping * fixed assertions * lint fixes * test: qbo base mapping * lint fix * additional fixtures and test * fix conflicts * lint fixes * lint * lint fix
- Loading branch information
Showing
2 changed files
with
170 additions
and
7 deletions.
There are no files selected for viewing
160 changes: 154 additions & 6 deletions
160
...integrations/qbo/qbo-main/qbo-mapping/qbo-base-mapping/qbo-base-mapping.component.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); | ||
}); | ||
|
||
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 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(''); | ||
}); | ||
|
||
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(''); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters