Skip to content

Commit

Permalink
test: intacct advanced settings utility functions (#1027)
Browse files Browse the repository at this point in the history
* test: intacct advanced settings utility functions

* refactor: typo

* refactor: update type
  • Loading branch information
1 parent eb8c678 commit 5f24854
Show file tree
Hide file tree
Showing 2 changed files with 129 additions and 14 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/* eslint-disable dot-notation */
import { ComponentFixture, fakeAsync, TestBed, tick } from '@angular/core/testing';
import { FormBuilder, ReactiveFormsModule, Validators } from '@angular/forms';
import { FormBuilder, FormGroup, ReactiveFormsModule, Validators } from '@angular/forms';
import { provideRouter, Router } from '@angular/router';
import { of, throwError } from 'rxjs';
import { IntacctAdvancedSettingsComponent } from './intacct-advanced-settings.component';
Expand All @@ -9,12 +10,12 @@ import { TrackingService } from 'src/app/core/services/integration/tracking.serv
import { SiWorkspaceService } from 'src/app/core/services/si/si-core/si-workspace.service';
import { SiMappingsService } from 'src/app/core/services/si/si-core/si-mappings.service';
import { SkipExportComponent } from 'src/app/shared/components/si/helper/skip-export/skip-export.component';
import { adminEmails, advancedSettings, configurationForAddvancedSettings, expenseFilter, groupedAttributes } from '../../intacct.fixture';
import { ExpenseFilterResponse } from 'src/app/core/models/intacct/intacct-configuration/advanced-settings.model';
import { adminEmails, advancedSettings, configurationForAdvancedSettings, configurationWithFyleToIntacct, configurationWithIntacctToFyle, configurationWithOutSync, expenseFilter, groupedAttributes } from '../../intacct.fixture';
import { Configuration, ExpenseFilterResponse } from 'src/app/core/models/intacct/intacct-configuration/advanced-settings.model';
import { SharedModule } from 'src/app/shared/shared.module';
import { PaymentSyncDirection } from 'src/app/core/models/enum/enum.model';
import { IntacctOnboardingState, PaymentSyncDirection, ToastSeverity } from 'src/app/core/models/enum/enum.model';
import { SkipExport } from 'src/app/core/models/intacct/misc/skip-export.model';
import { DestinationAttribute } from 'src/app/core/models/db/destination-attribute.model';

describe('IntacctAdvancedSettingsComponent', () => {
let component: IntacctAdvancedSettingsComponent;
Expand Down Expand Up @@ -65,7 +66,7 @@ describe('IntacctAdvancedSettingsComponent', () => {
advancedSettingsService.getAdvancedSettings.and.returnValue(of(advancedSettings));
advancedSettingsService.getExpenseFilter.and.returnValue(of(expenseFilter as ExpenseFilterResponse));
mappingService.getGroupedDestinationAttributes.and.returnValue(of(groupedAttributes));
mappingService.getConfiguration.and.returnValue(of(configurationForAddvancedSettings));
mappingService.getConfiguration.and.returnValue(of(configurationForAdvancedSettings));

fixture = TestBed.createComponent(IntacctAdvancedSettingsComponent);
component = fixture.componentInstance;
Expand All @@ -89,11 +90,11 @@ describe('IntacctAdvancedSettingsComponent', () => {
expect(component.sageIntacctProjects).toEqual(groupedAttributes.PROJECT);
expect(component.sageIntacctClasses).toEqual(groupedAttributes.CLASS);
expect(component.sageIntacctPaymentAccount).toEqual(groupedAttributes.PAYMENT_ACCOUNT);
expect(component.reimbursableExpense).toEqual(configurationForAddvancedSettings.reimbursable_expenses_object);
expect(component.corporateCreditCardExpense).toEqual(configurationForAddvancedSettings.corporate_credit_card_expenses_object);
expect(component.importVendorsAsMerchants).toEqual(configurationForAddvancedSettings.import_vendors_as_merchants);
expect(component.useMerchantInJournalLine).toEqual(configurationForAddvancedSettings.use_merchant_in_journal_line);
expect(component.employeeFieldMapping).toEqual(configurationForAddvancedSettings.employee_field_mapping);
expect(component.reimbursableExpense).toEqual(configurationForAdvancedSettings.reimbursable_expenses_object);
expect(component.corporateCreditCardExpense).toEqual(configurationForAdvancedSettings.corporate_credit_card_expenses_object);
expect(component.importVendorsAsMerchants).toEqual(configurationForAdvancedSettings.import_vendors_as_merchants);
expect(component.useMerchantInJournalLine).toEqual(configurationForAdvancedSettings.use_merchant_in_journal_line);
expect(component.employeeFieldMapping).toEqual(configurationForAdvancedSettings.employee_field_mapping);
}));

it('should initialize forms correctly', () => {
Expand Down Expand Up @@ -227,4 +228,103 @@ describe('IntacctAdvancedSettingsComponent', () => {
expect(component.saveInProgress).toBeFalse();
}));
});

describe('Utility Functions', () => {
describe('navigateToPreviousStep', () => {
it('should navigate to the import settings page', () => {
component.navigateToPreviousStep();
expect(router.navigate).toHaveBeenCalledWith(['/integrations/intacct/onboarding/import_settings']);
});
});

describe('isOverflowing', () => {
it('should return the mapping value if element is overflowing', () => {
const element = { offsetWidth: 100, scrollWidth: 150 };
const mapping = { value: 'test value' } as DestinationAttribute;
expect(component.isOverflowing(element, mapping)).toBe('test value');
});

it('should return an empty string if element is not overflowing', () => {
const element = { offsetWidth: 150, scrollWidth: 100 };
const mapping = { value: 'test value' } as DestinationAttribute;
expect(component.isOverflowing(element, mapping)).toBe('');
});
});

describe('refreshDimensions', () => {
it('should call refreshSageIntacctDimensions and refreshFyleDimensions', () => {
mappingService.refreshSageIntacctDimensions.and.returnValue(of({}));
mappingService.refreshFyleDimensions.and.returnValue(of({}));

component.refreshDimensions(true);

expect(mappingService.refreshSageIntacctDimensions).toHaveBeenCalled();
expect(mappingService.refreshFyleDimensions).toHaveBeenCalled();
expect(toastService.displayToastMessage).toHaveBeenCalledWith(ToastSeverity.SUCCESS, 'Syncing data dimensions from Sage Intacct');
});
});

describe('removeFilter', () => {
it('should reset the form control', () => {
const formGroup = new FormGroup({});
const resetSpy = spyOn(formGroup, 'reset');

component.removeFilter(formGroup);

expect(resetSpy).toHaveBeenCalled();
});
});

describe('getPaymentSyncConfiguration', () => {
it('should return FYLE_TO_INTACCT when sync_fyle_to_sage_intacct_payments is true', () => {
expect(component['getPaymentSyncConfiguration'](configurationWithFyleToIntacct)).toBe(PaymentSyncDirection.FYLE_TO_INTACCT);
});

it('should return INTACCT_TO_FYLE when sync_sage_intacct_to_fyle_payments is true', () => {
expect(component['getPaymentSyncConfiguration'](configurationWithIntacctToFyle)).toBe(PaymentSyncDirection.INTACCT_TO_FYLE);
});

it('should return an empty string when both sync options are false', () => {
expect(component['getPaymentSyncConfiguration'](configurationWithOutSync)).toBe('');
});
});

describe('compareObjects', () => {
it('should return true for identical objects', () => {
const obj1 = { id: 1, name: 'Test' };
const obj2 = { id: 1, name: 'Test' };
expect(component.compareObjects(obj1, obj2)).toBe(true);
});

it('should return false for different objects', () => {
const obj1 = { id: 1, name: 'Test' };
const obj2 = { id: 2, name: 'Different' };
expect(component.compareObjects(obj1, obj2)).toBe(false);
});
});

describe('isCCT', () => {
beforeEach(() => {
fixture.detectChanges();
});

it('should return true when autoSyncPayments is FYLE_TO_INTACCT', () => {
component.advancedSettingsForm.patchValue({ autoSyncPayments: PaymentSyncDirection.FYLE_TO_INTACCT });
expect(component.isCCT()).toBe(true);
});

it('should return false when autoSyncPayments is not FYLE_TO_INTACCT', () => {
component.advancedSettingsForm.patchValue({ autoSyncPayments: PaymentSyncDirection.INTACCT_TO_FYLE });
expect(component.isCCT()).toBe(false);
});
});

describe('updateForm', () => {
it('should update skipExportForm with the provided form', () => {
const newForm = new FormGroup({});
component.updateForm(newForm);
expect(component.skipExportForm).toBe(newForm);
});
});
});
});
23 changes: 19 additions & 4 deletions src/app/integrations/intacct/intacct.fixture.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import { DependentFieldSetting, ImportSettingGet, MappingSetting } from 'src/app
import { LocationEntityMapping } from 'src/app/core/models/intacct/db/location-entity-mapping.model';
import { GroupedDestinationAttribute, IntacctDestinationAttribute } from "src/app/core/models/intacct/db/destination-attribute.model";
import { IntacctConfiguration } from "src/app/core/models/db/configuration.model";
import { QBDEmailOptions } from "src/app/core/models/qbd/qbd-configuration/qbd-advanced-setting.model";
import { AdvancedSettingsGet } from "src/app/core/models/intacct/intacct-configuration/advanced-settings.model";
import { AdvancedSettingsGet, Configuration } from "src/app/core/models/intacct/intacct-configuration/advanced-settings.model";
import { EmailOption } from "src/app/core/models/common/advanced-settings.model";

export const workspaceResponse: IntacctWorkspace[] = [{
"id": 1,
Expand Down Expand Up @@ -949,7 +949,7 @@ export const customFieldFormValue = {
export const adminEmails = [
{ name: 'John Doe', email: '[email protected]' },
{ name: 'Jane Smith', email: '[email protected]' }
] as QBDEmailOptions[];
] as EmailOption[];

export const advancedSettings = {
workspace_schedules: {
Expand Down Expand Up @@ -993,10 +993,25 @@ export const groupedAttributes = {
PAYMENT_ACCOUNT: [{ destination_id: 'ACC1', value: 'Account 1' }] as IntacctDestinationAttribute[]
} as GroupedDestinationAttribute;

export const configurationForAddvancedSettings = {
export const configurationForAdvancedSettings = {
reimbursable_expenses_object: IntacctReimbursableExpensesObject.EXPENSE_REPORT,
corporate_credit_card_expenses_object: IntacctCorporateCreditCardExpensesObject.CHARGE_CARD_TRANSACTION,
import_vendors_as_merchants: false,
use_merchant_in_journal_line: true,
employee_field_mapping: FyleField.EMPLOYEE
} as IntacctConfiguration;

export const configurationWithFyleToIntacct = {
sync_fyle_to_sage_intacct_payments: true,
sync_sage_intacct_to_fyle_payments: false
} as unknown as Configuration;

export const configurationWithIntacctToFyle = {
sync_fyle_to_sage_intacct_payments: false,
sync_sage_intacct_to_fyle_payments: true
} as unknown as Configuration;

export const configurationWithOutSync = {
sync_fyle_to_sage_intacct_payments: false,
sync_sage_intacct_to_fyle_payments: false
} as unknown as Configuration;

0 comments on commit 5f24854

Please sign in to comment.