Skip to content

Commit f4767e6

Browse files
test: intacct advanced settings initialization (#1024)
1 parent 9d4d709 commit f4767e6

File tree

2 files changed

+163
-10
lines changed

2 files changed

+163
-10
lines changed
Lines changed: 104 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,119 @@
1-
import { ComponentFixture, TestBed } from '@angular/core/testing';
2-
1+
import { ComponentFixture, fakeAsync, TestBed, tick } from '@angular/core/testing';
2+
import { FormBuilder, ReactiveFormsModule, Validators } from '@angular/forms';
3+
import { provideRouter, Router } from '@angular/router';
4+
import { of } from 'rxjs';
35
import { IntacctAdvancedSettingsComponent } from './intacct-advanced-settings.component';
6+
import { SiAdvancedSettingService } from 'src/app/core/services/si/si-configuration/si-advanced-setting.service';
7+
import { IntegrationsToastService } from 'src/app/core/services/common/integrations-toast.service';
8+
import { TrackingService } from 'src/app/core/services/integration/tracking.service';
9+
import { SiWorkspaceService } from 'src/app/core/services/si/si-core/si-workspace.service';
10+
import { SiMappingsService } from 'src/app/core/services/si/si-core/si-mappings.service';
11+
import { SkipExportComponent } from 'src/app/shared/components/si/helper/skip-export/skip-export.component';
12+
import { adminEmails, advancedSettings, configurationForAddvancedSettings, expenseFilter, groupedAttributes } from '../../intacct.fixture';
13+
import { ExpenseFilterResponse } from 'src/app/core/models/intacct/intacct-configuration/advanced-settings.model';
14+
import { SharedModule } from 'src/app/shared/shared.module';
415

5-
xdescribe('IntacctAdvancedSettingsComponent', () => {
16+
describe('IntacctAdvancedSettingsComponent', () => {
617
let component: IntacctAdvancedSettingsComponent;
718
let fixture: ComponentFixture<IntacctAdvancedSettingsComponent>;
19+
let advancedSettingsService: jasmine.SpyObj<SiAdvancedSettingService>;
20+
let router: Router;
21+
let toastService: jasmine.SpyObj<IntegrationsToastService>;
22+
let trackingService: jasmine.SpyObj<TrackingService>;
23+
let workspaceService: jasmine.SpyObj<SiWorkspaceService>;
24+
let mappingService: jasmine.SpyObj<SiMappingsService>;
25+
826

927
beforeEach(async () => {
28+
const advancedSettingsServiceSpy = jasmine.createSpyObj('SiAdvancedSettingService', ['getAdvancedSettings', 'getExpenseFilter', 'getAdditionalEmails']);
29+
const toastServiceSpy = jasmine.createSpyObj('IntegrationsToastService', ['displayToastMessage']);
30+
const trackingServiceSpy = jasmine.createSpyObj('TrackingService', ['trackTimeSpent', 'integrationsOnboardingCompletion', 'intacctUpdateEvent']);
31+
const workspaceServiceSpy = jasmine.createSpyObj('SiWorkspaceService', ['getIntacctOnboardingState', 'setIntacctOnboardingState']);
32+
const mappingServiceSpy = jasmine.createSpyObj('SiMappingsService', ['getGroupedDestinationAttributes', 'getConfiguration', 'refreshSageIntacctDimensions', 'refreshFyleDimensions']);
1033
await TestBed.configureTestingModule({
11-
declarations: [ IntacctAdvancedSettingsComponent ]
12-
})
13-
.compileComponents();
34+
declarations: [ IntacctAdvancedSettingsComponent, SkipExportComponent ],
35+
imports: [ SharedModule, ReactiveFormsModule ],
36+
providers: [
37+
FormBuilder,
38+
{ provide: SiAdvancedSettingService, useValue: advancedSettingsServiceSpy },
39+
{ provide: IntegrationsToastService, useValue: toastServiceSpy },
40+
{ provide: TrackingService, useValue: trackingServiceSpy },
41+
{ provide: SiWorkspaceService, useValue: workspaceServiceSpy },
42+
{ provide: SiMappingsService, useValue: mappingServiceSpy },
43+
provideRouter([])
44+
]
45+
}).compileComponents();
46+
47+
advancedSettingsService = TestBed.inject(SiAdvancedSettingService) as jasmine.SpyObj<SiAdvancedSettingService>;
48+
toastService = TestBed.inject(IntegrationsToastService) as jasmine.SpyObj<IntegrationsToastService>;
49+
trackingService = TestBed.inject(TrackingService) as jasmine.SpyObj<TrackingService>;
50+
workspaceService = TestBed.inject(SiWorkspaceService) as jasmine.SpyObj<SiWorkspaceService>;
51+
mappingService = TestBed.inject(SiMappingsService) as jasmine.SpyObj<SiMappingsService>;
52+
router = TestBed.inject(Router);
53+
54+
advancedSettingsService.getAdditionalEmails.and.returnValue(of(adminEmails));
55+
advancedSettingsService.getAdvancedSettings.and.returnValue(of(advancedSettings));
56+
advancedSettingsService.getExpenseFilter.and.returnValue(of(expenseFilter as ExpenseFilterResponse));
57+
mappingService.getGroupedDestinationAttributes.and.returnValue(of(groupedAttributes));
58+
mappingService.getConfiguration.and.returnValue(of(configurationForAddvancedSettings));
1459

1560
fixture = TestBed.createComponent(IntacctAdvancedSettingsComponent);
1661
component = fixture.componentInstance;
17-
fixture.detectChanges();
1862
});
1963

2064
it('should create', () => {
2165
expect(component).toBeTruthy();
2266
});
23-
});
67+
68+
it('should initialize with correct data', fakeAsync(() => {
69+
fixture.detectChanges();
70+
tick();
71+
72+
expect(component.isLoading).toBeFalse();
73+
expect(component.adminEmails).toEqual(adminEmails.concat(advancedSettings.workspace_schedules.additional_email_options));
74+
expect(component.advancedSettings).toEqual(advancedSettings);
75+
expect(component.sageIntacctLocations).toEqual(groupedAttributes.LOCATION);
76+
expect(component.sageIntacctDefaultItem).toEqual(groupedAttributes.ITEM);
77+
expect(component.sageIntacctDepartments).toEqual(groupedAttributes.DEPARTMENT);
78+
expect(component.sageIntacctProjects).toEqual(groupedAttributes.PROJECT);
79+
expect(component.sageIntacctClasses).toEqual(groupedAttributes.CLASS);
80+
expect(component.sageIntacctPaymentAccount).toEqual(groupedAttributes.PAYMENT_ACCOUNT);
81+
expect(component.reimbursableExpense).toEqual(configurationForAddvancedSettings.reimbursable_expenses_object);
82+
expect(component.corporateCreditCardExpense).toEqual(configurationForAddvancedSettings.corporate_credit_card_expenses_object);
83+
expect(component.importVendorsAsMerchants).toEqual(configurationForAddvancedSettings.import_vendors_as_merchants);
84+
expect(component.useMerchantInJournalLine).toEqual(configurationForAddvancedSettings.use_merchant_in_journal_line);
85+
expect(component.employeeFieldMapping).toEqual(configurationForAddvancedSettings.employee_field_mapping);
86+
}));
87+
88+
it('should initialize forms correctly', () => {
89+
fixture.detectChanges();
90+
91+
expect(component.advancedSettingsForm).toBeDefined();
92+
expect(component.skipExportForm).toBeDefined();
93+
94+
expect(component.advancedSettingsForm.get('exportSchedule')?.value).toBeTrue();
95+
expect(component.advancedSettingsForm.get('exportScheduleFrequency')?.value).toBe(12);
96+
expect(component.advancedSettingsForm.get('setDescriptionField')?.value).toEqual(['employee_email', 'merchant', 'purpose']);
97+
});
98+
99+
it('should handle onboarding state correctly', () => {
100+
spyOnProperty(router, 'url').and.returnValue('/integrations/intacct/onboarding/advanced_settings');
101+
fixture.detectChanges();
102+
103+
expect(component.isOnboarding).toBeTrue();
104+
});
105+
106+
it('should handle non-onboarding state correctly', () => {
107+
spyOnProperty(router, 'url').and.returnValue('/integrations/intacct/advanced_settings');
108+
fixture.detectChanges();
109+
110+
expect(component.isOnboarding).toBeFalse();
111+
});
112+
113+
it('should create memo preview correctly', () => {
114+
fixture.detectChanges();
115+
116+
const expectedPreview = '[email protected] - Pizza Hut - Client Meeting';
117+
expect(component.memoPreviewText).toBe(expectedPreview);
118+
});
119+
});

src/app/integrations/intacct/intacct.fixture.ts

Lines changed: 59 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,10 @@ import { SkipExportLogResponse } from "src/app/core/models/intacct/db/expense-gr
1111
import { ExpenseField } from 'src/app/core/models/intacct/db/expense-field.model';
1212
import { DependentFieldSetting, ImportSettingGet, MappingSetting } from 'src/app/core/models/intacct/intacct-configuration/import-settings.model';
1313
import { LocationEntityMapping } from 'src/app/core/models/intacct/db/location-entity-mapping.model';
14-
import { GroupedDestinationAttribute } from "src/app/core/models/intacct/db/destination-attribute.model";
14+
import { GroupedDestinationAttribute, IntacctDestinationAttribute } from "src/app/core/models/intacct/db/destination-attribute.model";
1515
import { IntacctConfiguration } from "src/app/core/models/db/configuration.model";
16+
import { QBDEmailOptions } from "src/app/core/models/qbd/qbd-configuration/qbd-advanced-setting.model";
17+
import { AdvancedSettingsGet } from "src/app/core/models/intacct/intacct-configuration/advanced-settings.model";
1618

1719
export const workspaceResponse: IntacctWorkspace[] = [{
1820
"id": 1,
@@ -942,4 +944,59 @@ export const blankMapping: MappingSetting = {
942944
export const customFieldFormValue = {
943945
attribute_type: 'TEST',
944946
source_placeholder: 'TEST_PLACEHOLDER'
945-
};
947+
};
948+
949+
export const adminEmails = [
950+
{ name: 'John Doe', email: '[email protected]' },
951+
{ name: 'Jane Smith', email: '[email protected]' }
952+
] as QBDEmailOptions[];
953+
954+
export const advancedSettings = {
955+
workspace_schedules: {
956+
enabled: true,
957+
interval_hours: 12,
958+
emails_selected: ['[email protected]'],
959+
additional_email_options: [
960+
{ name: 'Additional User', email: '[email protected]' }
961+
]
962+
},
963+
configurations: {
964+
sync_fyle_to_sage_intacct_payments: true,
965+
sync_sage_intacct_to_fyle_payments: false,
966+
auto_create_destination_entity: true,
967+
change_accounting_period: true,
968+
memo_structure: ['employee_email', 'merchant', 'purpose'],
969+
auto_create_merchants_as_vendors: false
970+
},
971+
general_mappings: {
972+
default_location: { id: 'LOC1' },
973+
default_department: { id: 'DEP1' },
974+
default_project: { id: 'PRJ1' },
975+
default_class: { id: 'CLS1' },
976+
default_item: { id: 'ITEM1' },
977+
payment_account: { id: 'ACC1' },
978+
use_intacct_employee_locations: true,
979+
use_intacct_employee_departments: true
980+
}
981+
} as unknown as AdvancedSettingsGet;
982+
983+
export const expenseFilter = {
984+
count: 0
985+
};
986+
987+
export const groupedAttributes = {
988+
LOCATION: [{ destination_id: 'LOC1', value: 'Location 1' }] as IntacctDestinationAttribute[],
989+
DEPARTMENT: [{ destination_id: 'DEP1', value: 'Department 1' }] as IntacctDestinationAttribute[],
990+
PROJECT: [{ destination_id: 'PRJ1', value: 'Project 1' }] as IntacctDestinationAttribute[],
991+
CLASS: [{ destination_id: 'CLS1', value: 'Class 1' }] as IntacctDestinationAttribute[],
992+
ITEM: [{ destination_id: 'ITEM1', value: 'Item 1' }] as IntacctDestinationAttribute[],
993+
PAYMENT_ACCOUNT: [{ destination_id: 'ACC1', value: 'Account 1' }] as IntacctDestinationAttribute[]
994+
} as GroupedDestinationAttribute;
995+
996+
export const configurationForAddvancedSettings = {
997+
reimbursable_expenses_object: IntacctReimbursableExpensesObject.EXPENSE_REPORT,
998+
corporate_credit_card_expenses_object: IntacctCorporateCreditCardExpensesObject.CHARGE_CARD_TRANSACTION,
999+
import_vendors_as_merchants: false,
1000+
use_merchant_in_journal_line: true,
1001+
employee_field_mapping: FyleField.EMPLOYEE
1002+
} as IntacctConfiguration;

0 commit comments

Comments
 (0)