Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,23 +1,119 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';

import { ComponentFixture, fakeAsync, TestBed, tick } from '@angular/core/testing';
import { FormBuilder, ReactiveFormsModule, Validators } from '@angular/forms';
import { provideRouter, Router } from '@angular/router';
import { of } from 'rxjs';
import { IntacctAdvancedSettingsComponent } from './intacct-advanced-settings.component';
import { SiAdvancedSettingService } from 'src/app/core/services/si/si-configuration/si-advanced-setting.service';
import { IntegrationsToastService } from 'src/app/core/services/common/integrations-toast.service';
import { TrackingService } from 'src/app/core/services/integration/tracking.service';
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 { SharedModule } from 'src/app/shared/shared.module';

xdescribe('IntacctAdvancedSettingsComponent', () => {
describe('IntacctAdvancedSettingsComponent', () => {
let component: IntacctAdvancedSettingsComponent;
let fixture: ComponentFixture<IntacctAdvancedSettingsComponent>;
let advancedSettingsService: jasmine.SpyObj<SiAdvancedSettingService>;
let router: Router;
let toastService: jasmine.SpyObj<IntegrationsToastService>;
let trackingService: jasmine.SpyObj<TrackingService>;
let workspaceService: jasmine.SpyObj<SiWorkspaceService>;
let mappingService: jasmine.SpyObj<SiMappingsService>;


beforeEach(async () => {
const advancedSettingsServiceSpy = jasmine.createSpyObj('SiAdvancedSettingService', ['getAdvancedSettings', 'getExpenseFilter', 'getAdditionalEmails']);
const toastServiceSpy = jasmine.createSpyObj('IntegrationsToastService', ['displayToastMessage']);
const trackingServiceSpy = jasmine.createSpyObj('TrackingService', ['trackTimeSpent', 'integrationsOnboardingCompletion', 'intacctUpdateEvent']);
const workspaceServiceSpy = jasmine.createSpyObj('SiWorkspaceService', ['getIntacctOnboardingState', 'setIntacctOnboardingState']);
const mappingServiceSpy = jasmine.createSpyObj('SiMappingsService', ['getGroupedDestinationAttributes', 'getConfiguration', 'refreshSageIntacctDimensions', 'refreshFyleDimensions']);
await TestBed.configureTestingModule({
declarations: [ IntacctAdvancedSettingsComponent ]
})
.compileComponents();
declarations: [ IntacctAdvancedSettingsComponent, SkipExportComponent ],
imports: [ SharedModule, ReactiveFormsModule ],
providers: [
FormBuilder,
{ provide: SiAdvancedSettingService, useValue: advancedSettingsServiceSpy },
{ provide: IntegrationsToastService, useValue: toastServiceSpy },
{ provide: TrackingService, useValue: trackingServiceSpy },
{ provide: SiWorkspaceService, useValue: workspaceServiceSpy },
{ provide: SiMappingsService, useValue: mappingServiceSpy },
provideRouter([])
]
}).compileComponents();

advancedSettingsService = TestBed.inject(SiAdvancedSettingService) as jasmine.SpyObj<SiAdvancedSettingService>;
toastService = TestBed.inject(IntegrationsToastService) as jasmine.SpyObj<IntegrationsToastService>;
trackingService = TestBed.inject(TrackingService) as jasmine.SpyObj<TrackingService>;
workspaceService = TestBed.inject(SiWorkspaceService) as jasmine.SpyObj<SiWorkspaceService>;
mappingService = TestBed.inject(SiMappingsService) as jasmine.SpyObj<SiMappingsService>;
router = TestBed.inject(Router);

advancedSettingsService.getAdditionalEmails.and.returnValue(of(adminEmails));
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));

fixture = TestBed.createComponent(IntacctAdvancedSettingsComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});

it('should create', () => {
expect(component).toBeTruthy();
});
});

it('should initialize with correct data', fakeAsync(() => {
fixture.detectChanges();
tick();

expect(component.isLoading).toBeFalse();
expect(component.adminEmails).toEqual(adminEmails.concat(advancedSettings.workspace_schedules.additional_email_options));
expect(component.advancedSettings).toEqual(advancedSettings);
expect(component.sageIntacctLocations).toEqual(groupedAttributes.LOCATION);
expect(component.sageIntacctDefaultItem).toEqual(groupedAttributes.ITEM);
expect(component.sageIntacctDepartments).toEqual(groupedAttributes.DEPARTMENT);
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);
}));

it('should initialize forms correctly', () => {
fixture.detectChanges();

expect(component.advancedSettingsForm).toBeDefined();
expect(component.skipExportForm).toBeDefined();

expect(component.advancedSettingsForm.get('exportSchedule')?.value).toBeTrue();
expect(component.advancedSettingsForm.get('exportScheduleFrequency')?.value).toBe(12);
expect(component.advancedSettingsForm.get('setDescriptionField')?.value).toEqual(['employee_email', 'merchant', 'purpose']);
});

it('should handle onboarding state correctly', () => {
spyOnProperty(router, 'url').and.returnValue('/integrations/intacct/onboarding/advanced_settings');
fixture.detectChanges();

expect(component.isOnboarding).toBeTrue();
});

it('should handle non-onboarding state correctly', () => {
spyOnProperty(router, 'url').and.returnValue('/integrations/intacct/advanced_settings');
fixture.detectChanges();

expect(component.isOnboarding).toBeFalse();
});

it('should create memo preview correctly', () => {
fixture.detectChanges();

const expectedPreview = '[email protected] - Pizza Hut - Client Meeting';
expect(component.memoPreviewText).toBe(expectedPreview);
});
});
61 changes: 59 additions & 2 deletions src/app/integrations/intacct/intacct.fixture.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@ import { SkipExportLogResponse } from "src/app/core/models/intacct/db/expense-gr
import { ExpenseField } from 'src/app/core/models/intacct/db/expense-field.model';
import { DependentFieldSetting, ImportSettingGet, MappingSetting } from 'src/app/core/models/intacct/intacct-configuration/import-settings.model';
import { LocationEntityMapping } from 'src/app/core/models/intacct/db/location-entity-mapping.model';
import { GroupedDestinationAttribute } from "src/app/core/models/intacct/db/destination-attribute.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";

export const workspaceResponse: IntacctWorkspace[] = [{
"id": 1,
Expand Down Expand Up @@ -942,4 +944,59 @@ export const blankMapping: MappingSetting = {
export const customFieldFormValue = {
attribute_type: 'TEST',
source_placeholder: 'TEST_PLACEHOLDER'
};
};

export const adminEmails = [
{ name: 'John Doe', email: '[email protected]' },
{ name: 'Jane Smith', email: '[email protected]' }
] as QBDEmailOptions[];

export const advancedSettings = {
workspace_schedules: {
enabled: true,
interval_hours: 12,
emails_selected: ['[email protected]'],
additional_email_options: [
{ name: 'Additional User', email: '[email protected]' }
]
},
configurations: {
sync_fyle_to_sage_intacct_payments: true,
sync_sage_intacct_to_fyle_payments: false,
auto_create_destination_entity: true,
change_accounting_period: true,
memo_structure: ['employee_email', 'merchant', 'purpose'],
auto_create_merchants_as_vendors: false
},
general_mappings: {
default_location: { id: 'LOC1' },
default_department: { id: 'DEP1' },
default_project: { id: 'PRJ1' },
default_class: { id: 'CLS1' },
default_item: { id: 'ITEM1' },
payment_account: { id: 'ACC1' },
use_intacct_employee_locations: true,
use_intacct_employee_departments: true
}
} as unknown as AdvancedSettingsGet;

export const expenseFilter = {
count: 0
};

export const groupedAttributes = {
LOCATION: [{ destination_id: 'LOC1', value: 'Location 1' }] as IntacctDestinationAttribute[],
DEPARTMENT: [{ destination_id: 'DEP1', value: 'Department 1' }] as IntacctDestinationAttribute[],
PROJECT: [{ destination_id: 'PRJ1', value: 'Project 1' }] as IntacctDestinationAttribute[],
CLASS: [{ destination_id: 'CLS1', value: 'Class 1' }] as IntacctDestinationAttribute[],
ITEM: [{ destination_id: 'ITEM1', value: 'Item 1' }] as IntacctDestinationAttribute[],
PAYMENT_ACCOUNT: [{ destination_id: 'ACC1', value: 'Account 1' }] as IntacctDestinationAttribute[]
} as GroupedDestinationAttribute;

export const configurationForAddvancedSettings = {
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;
Loading