From f4767e62f69741fa1d754fb590ee14ec75334682 Mon Sep 17 00:00:00 2001 From: Viswas Haridas <37623357+JustARatherRidiculouslyLongUsername@users.noreply.github.com> Date: Fri, 18 Oct 2024 14:42:28 +0530 Subject: [PATCH] test: intacct advanced settings initialization (#1024) --- ...ntacct-advanced-settings.component.spec.ts | 112 ++++++++++++++++-- .../integrations/intacct/intacct.fixture.ts | 61 +++++++++- 2 files changed, 163 insertions(+), 10 deletions(-) diff --git a/src/app/integrations/intacct/intacct-shared/intacct-advanced-settings/intacct-advanced-settings.component.spec.ts b/src/app/integrations/intacct/intacct-shared/intacct-advanced-settings/intacct-advanced-settings.component.spec.ts index 0496d7077..d875f56f3 100644 --- a/src/app/integrations/intacct/intacct-shared/intacct-advanced-settings/intacct-advanced-settings.component.spec.ts +++ b/src/app/integrations/intacct/intacct-shared/intacct-advanced-settings/intacct-advanced-settings.component.spec.ts @@ -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; + let advancedSettingsService: jasmine.SpyObj; + let router: Router; + let toastService: jasmine.SpyObj; + let trackingService: jasmine.SpyObj; + let workspaceService: jasmine.SpyObj; + let mappingService: jasmine.SpyObj; + 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; + toastService = TestBed.inject(IntegrationsToastService) as jasmine.SpyObj; + trackingService = TestBed.inject(TrackingService) as jasmine.SpyObj; + workspaceService = TestBed.inject(SiWorkspaceService) as jasmine.SpyObj; + mappingService = TestBed.inject(SiMappingsService) as jasmine.SpyObj; + 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 = 'john.doe@acme.com - Pizza Hut - Client Meeting'; + expect(component.memoPreviewText).toBe(expectedPreview); + }); +}); \ No newline at end of file diff --git a/src/app/integrations/intacct/intacct.fixture.ts b/src/app/integrations/intacct/intacct.fixture.ts index 67350bffc..4890f2b00 100644 --- a/src/app/integrations/intacct/intacct.fixture.ts +++ b/src/app/integrations/intacct/intacct.fixture.ts @@ -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, @@ -942,4 +944,59 @@ export const blankMapping: MappingSetting = { export const customFieldFormValue = { attribute_type: 'TEST', source_placeholder: 'TEST_PLACEHOLDER' -}; \ No newline at end of file +}; + +export const adminEmails = [ + { name: 'John Doe', email: 'john.doe@example.com' }, + { name: 'Jane Smith', email: 'jane.smith@example.com' } +] as QBDEmailOptions[]; + +export const advancedSettings = { + workspace_schedules: { + enabled: true, + interval_hours: 12, + emails_selected: ['john.doe@example.com'], + additional_email_options: [ + { name: 'Additional User', email: 'additional.user@example.com' } + ] + }, + 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;