Skip to content

Commit 5f24854

Browse files
test: intacct advanced settings utility functions (#1027)
* test: intacct advanced settings utility functions * refactor: typo * refactor: update type
1 parent eb8c678 commit 5f24854

File tree

2 files changed

+129
-14
lines changed

2 files changed

+129
-14
lines changed

src/app/integrations/intacct/intacct-shared/intacct-advanced-settings/intacct-advanced-settings.component.spec.ts

Lines changed: 110 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1+
/* eslint-disable dot-notation */
12
import { ComponentFixture, fakeAsync, TestBed, tick } from '@angular/core/testing';
2-
import { FormBuilder, ReactiveFormsModule, Validators } from '@angular/forms';
3+
import { FormBuilder, FormGroup, ReactiveFormsModule, Validators } from '@angular/forms';
34
import { provideRouter, Router } from '@angular/router';
45
import { of, throwError } from 'rxjs';
56
import { IntacctAdvancedSettingsComponent } from './intacct-advanced-settings.component';
@@ -9,12 +10,12 @@ import { TrackingService } from 'src/app/core/services/integration/tracking.serv
910
import { SiWorkspaceService } from 'src/app/core/services/si/si-core/si-workspace.service';
1011
import { SiMappingsService } from 'src/app/core/services/si/si-core/si-mappings.service';
1112
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';
13+
import { adminEmails, advancedSettings, configurationForAdvancedSettings, configurationWithFyleToIntacct, configurationWithIntacctToFyle, configurationWithOutSync, expenseFilter, groupedAttributes } from '../../intacct.fixture';
14+
import { Configuration, ExpenseFilterResponse } from 'src/app/core/models/intacct/intacct-configuration/advanced-settings.model';
1415
import { SharedModule } from 'src/app/shared/shared.module';
15-
import { PaymentSyncDirection } from 'src/app/core/models/enum/enum.model';
1616
import { IntacctOnboardingState, PaymentSyncDirection, ToastSeverity } from 'src/app/core/models/enum/enum.model';
1717
import { SkipExport } from 'src/app/core/models/intacct/misc/skip-export.model';
18+
import { DestinationAttribute } from 'src/app/core/models/db/destination-attribute.model';
1819

1920
describe('IntacctAdvancedSettingsComponent', () => {
2021
let component: IntacctAdvancedSettingsComponent;
@@ -65,7 +66,7 @@ describe('IntacctAdvancedSettingsComponent', () => {
6566
advancedSettingsService.getAdvancedSettings.and.returnValue(of(advancedSettings));
6667
advancedSettingsService.getExpenseFilter.and.returnValue(of(expenseFilter as ExpenseFilterResponse));
6768
mappingService.getGroupedDestinationAttributes.and.returnValue(of(groupedAttributes));
68-
mappingService.getConfiguration.and.returnValue(of(configurationForAddvancedSettings));
69+
mappingService.getConfiguration.and.returnValue(of(configurationForAdvancedSettings));
6970

7071
fixture = TestBed.createComponent(IntacctAdvancedSettingsComponent);
7172
component = fixture.componentInstance;
@@ -89,11 +90,11 @@ describe('IntacctAdvancedSettingsComponent', () => {
8990
expect(component.sageIntacctProjects).toEqual(groupedAttributes.PROJECT);
9091
expect(component.sageIntacctClasses).toEqual(groupedAttributes.CLASS);
9192
expect(component.sageIntacctPaymentAccount).toEqual(groupedAttributes.PAYMENT_ACCOUNT);
92-
expect(component.reimbursableExpense).toEqual(configurationForAddvancedSettings.reimbursable_expenses_object);
93-
expect(component.corporateCreditCardExpense).toEqual(configurationForAddvancedSettings.corporate_credit_card_expenses_object);
94-
expect(component.importVendorsAsMerchants).toEqual(configurationForAddvancedSettings.import_vendors_as_merchants);
95-
expect(component.useMerchantInJournalLine).toEqual(configurationForAddvancedSettings.use_merchant_in_journal_line);
96-
expect(component.employeeFieldMapping).toEqual(configurationForAddvancedSettings.employee_field_mapping);
93+
expect(component.reimbursableExpense).toEqual(configurationForAdvancedSettings.reimbursable_expenses_object);
94+
expect(component.corporateCreditCardExpense).toEqual(configurationForAdvancedSettings.corporate_credit_card_expenses_object);
95+
expect(component.importVendorsAsMerchants).toEqual(configurationForAdvancedSettings.import_vendors_as_merchants);
96+
expect(component.useMerchantInJournalLine).toEqual(configurationForAdvancedSettings.use_merchant_in_journal_line);
97+
expect(component.employeeFieldMapping).toEqual(configurationForAdvancedSettings.employee_field_mapping);
9798
}));
9899

99100
it('should initialize forms correctly', () => {
@@ -227,4 +228,103 @@ describe('IntacctAdvancedSettingsComponent', () => {
227228
expect(component.saveInProgress).toBeFalse();
228229
}));
229230
});
231+
232+
describe('Utility Functions', () => {
233+
describe('navigateToPreviousStep', () => {
234+
it('should navigate to the import settings page', () => {
235+
component.navigateToPreviousStep();
236+
expect(router.navigate).toHaveBeenCalledWith(['/integrations/intacct/onboarding/import_settings']);
237+
});
238+
});
239+
240+
describe('isOverflowing', () => {
241+
it('should return the mapping value if element is overflowing', () => {
242+
const element = { offsetWidth: 100, scrollWidth: 150 };
243+
const mapping = { value: 'test value' } as DestinationAttribute;
244+
expect(component.isOverflowing(element, mapping)).toBe('test value');
245+
});
246+
247+
it('should return an empty string if element is not overflowing', () => {
248+
const element = { offsetWidth: 150, scrollWidth: 100 };
249+
const mapping = { value: 'test value' } as DestinationAttribute;
250+
expect(component.isOverflowing(element, mapping)).toBe('');
251+
});
252+
});
253+
254+
describe('refreshDimensions', () => {
255+
it('should call refreshSageIntacctDimensions and refreshFyleDimensions', () => {
256+
mappingService.refreshSageIntacctDimensions.and.returnValue(of({}));
257+
mappingService.refreshFyleDimensions.and.returnValue(of({}));
258+
259+
component.refreshDimensions(true);
260+
261+
expect(mappingService.refreshSageIntacctDimensions).toHaveBeenCalled();
262+
expect(mappingService.refreshFyleDimensions).toHaveBeenCalled();
263+
expect(toastService.displayToastMessage).toHaveBeenCalledWith(ToastSeverity.SUCCESS, 'Syncing data dimensions from Sage Intacct');
264+
});
265+
});
266+
267+
describe('removeFilter', () => {
268+
it('should reset the form control', () => {
269+
const formGroup = new FormGroup({});
270+
const resetSpy = spyOn(formGroup, 'reset');
271+
272+
component.removeFilter(formGroup);
273+
274+
expect(resetSpy).toHaveBeenCalled();
275+
});
276+
});
277+
278+
describe('getPaymentSyncConfiguration', () => {
279+
it('should return FYLE_TO_INTACCT when sync_fyle_to_sage_intacct_payments is true', () => {
280+
expect(component['getPaymentSyncConfiguration'](configurationWithFyleToIntacct)).toBe(PaymentSyncDirection.FYLE_TO_INTACCT);
281+
});
282+
283+
it('should return INTACCT_TO_FYLE when sync_sage_intacct_to_fyle_payments is true', () => {
284+
expect(component['getPaymentSyncConfiguration'](configurationWithIntacctToFyle)).toBe(PaymentSyncDirection.INTACCT_TO_FYLE);
285+
});
286+
287+
it('should return an empty string when both sync options are false', () => {
288+
expect(component['getPaymentSyncConfiguration'](configurationWithOutSync)).toBe('');
289+
});
290+
});
291+
292+
describe('compareObjects', () => {
293+
it('should return true for identical objects', () => {
294+
const obj1 = { id: 1, name: 'Test' };
295+
const obj2 = { id: 1, name: 'Test' };
296+
expect(component.compareObjects(obj1, obj2)).toBe(true);
297+
});
298+
299+
it('should return false for different objects', () => {
300+
const obj1 = { id: 1, name: 'Test' };
301+
const obj2 = { id: 2, name: 'Different' };
302+
expect(component.compareObjects(obj1, obj2)).toBe(false);
303+
});
304+
});
305+
306+
describe('isCCT', () => {
307+
beforeEach(() => {
308+
fixture.detectChanges();
309+
});
310+
311+
it('should return true when autoSyncPayments is FYLE_TO_INTACCT', () => {
312+
component.advancedSettingsForm.patchValue({ autoSyncPayments: PaymentSyncDirection.FYLE_TO_INTACCT });
313+
expect(component.isCCT()).toBe(true);
314+
});
315+
316+
it('should return false when autoSyncPayments is not FYLE_TO_INTACCT', () => {
317+
component.advancedSettingsForm.patchValue({ autoSyncPayments: PaymentSyncDirection.INTACCT_TO_FYLE });
318+
expect(component.isCCT()).toBe(false);
319+
});
320+
});
321+
322+
describe('updateForm', () => {
323+
it('should update skipExportForm with the provided form', () => {
324+
const newForm = new FormGroup({});
325+
component.updateForm(newForm);
326+
expect(component.skipExportForm).toBe(newForm);
327+
});
328+
});
329+
});
230330
});

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

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ import { DependentFieldSetting, ImportSettingGet, MappingSetting } from 'src/app
1313
import { LocationEntityMapping } from 'src/app/core/models/intacct/db/location-entity-mapping.model';
1414
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";
16+
import { AdvancedSettingsGet, Configuration } from "src/app/core/models/intacct/intacct-configuration/advanced-settings.model";
17+
import { EmailOption } from "src/app/core/models/common/advanced-settings.model";
1818

1919
export const workspaceResponse: IntacctWorkspace[] = [{
2020
"id": 1,
@@ -949,7 +949,7 @@ export const customFieldFormValue = {
949949
export const adminEmails = [
950950
{ name: 'John Doe', email: '[email protected]' },
951951
{ name: 'Jane Smith', email: '[email protected]' }
952-
] as QBDEmailOptions[];
952+
] as EmailOption[];
953953

954954
export const advancedSettings = {
955955
workspace_schedules: {
@@ -993,10 +993,25 @@ export const groupedAttributes = {
993993
PAYMENT_ACCOUNT: [{ destination_id: 'ACC1', value: 'Account 1' }] as IntacctDestinationAttribute[]
994994
} as GroupedDestinationAttribute;
995995

996-
export const configurationForAddvancedSettings = {
996+
export const configurationForAdvancedSettings = {
997997
reimbursable_expenses_object: IntacctReimbursableExpensesObject.EXPENSE_REPORT,
998998
corporate_credit_card_expenses_object: IntacctCorporateCreditCardExpensesObject.CHARGE_CARD_TRANSACTION,
999999
import_vendors_as_merchants: false,
10001000
use_merchant_in_journal_line: true,
10011001
employee_field_mapping: FyleField.EMPLOYEE
10021002
} as IntacctConfiguration;
1003+
1004+
export const configurationWithFyleToIntacct = {
1005+
sync_fyle_to_sage_intacct_payments: true,
1006+
sync_sage_intacct_to_fyle_payments: false
1007+
} as unknown as Configuration;
1008+
1009+
export const configurationWithIntacctToFyle = {
1010+
sync_fyle_to_sage_intacct_payments: false,
1011+
sync_sage_intacct_to_fyle_payments: true
1012+
} as unknown as Configuration;
1013+
1014+
export const configurationWithOutSync = {
1015+
sync_fyle_to_sage_intacct_payments: false,
1016+
sync_sage_intacct_to_fyle_payments: false
1017+
} as unknown as Configuration;

0 commit comments

Comments
 (0)