11import { ComponentFixture , TestBed } from '@angular/core/testing' ;
22import { FormArray , FormBuilder , ReactiveFormsModule } from '@angular/forms' ;
33import { provideRouter , Router , RouterModule } from '@angular/router' ;
4- import { of } from 'rxjs' ;
4+ import { of , throwError } from 'rxjs' ;
55import { IntacctC1ImportSettingsComponent } from './intacct-c1-import-settings.component' ;
66import { SiImportSettingService } from 'src/app/core/services/si/si-configuration/si-import-setting.service' ;
77import { SiMappingsService } from 'src/app/core/services/si/si-core/si-mappings.service' ;
@@ -20,12 +20,15 @@ import {
2020 settingsWithDependentFields ,
2121 sageIntacctFieldsSortedByPriorityForC1 ,
2222 importSettingsWithProjectMapping ,
23- expenseFieldsExpectedForC1
23+ expenseFieldsExpectedForC1 ,
24+ costCodeFieldValue ,
25+ costTypeFieldValue
2426} from '../../intacct.fixture' ;
2527import { IntacctConfiguration } from 'src/app/core/models/db/configuration.model' ;
26- import { ImportSettingGet } from 'src/app/core/models/intacct/intacct-configuration/import-settings.model' ;
28+ import { ImportSettingGet , ImportSettingPost , ImportSettings } from 'src/app/core/models/intacct/intacct-configuration/import-settings.model' ;
2729import { SharedModule } from 'src/app/shared/shared.module' ;
2830import { HttpClientTestingModule } from '@angular/common/http/testing' ;
31+ import { IntacctOnboardingState , IntacctUpdateEvent , Page , ProgressPhase , ToastSeverity , TrackingApp } from 'src/app/core/models/enum/enum.model' ;
2932
3033describe ( 'IntacctC1ImportSettingsComponent' , ( ) => {
3134 let component : IntacctC1ImportSettingsComponent ;
@@ -48,12 +51,12 @@ describe('IntacctC1ImportSettingsComponent', () => {
4851 'refreshSageIntacctDimensions' ,
4952 'refreshFyleDimensions'
5053 ] ) ;
51- const importSettingServiceSpy = jasmine . createSpyObj ( 'SiImportSettingService' , [ 'getImportSettings' ] ) ;
54+ const importSettingServiceSpy = jasmine . createSpyObj ( 'SiImportSettingService' , [ 'getImportSettings' , 'postImportSettings' ] ) ;
5255 const connectorServiceSpy = jasmine . createSpyObj ( 'IntacctConnectorService' , [ 'getLocationEntityMapping' ] ) ;
5356 const storageServiceSpy = jasmine . createSpyObj ( 'StorageService' , [ 'get' ] ) ;
5457 const toastServiceSpy = jasmine . createSpyObj ( 'IntegrationsToastService' , [ 'displayToastMessage' ] ) ;
55- const trackingServiceSpy = jasmine . createSpyObj ( 'TrackingService' , [ 'trackTimeSpent' ] ) ;
56- const workspaceServiceSpy = jasmine . createSpyObj ( 'SiWorkspaceService' , [ 'getIntacctOnboardingState' ] ) ;
58+ const trackingServiceSpy = jasmine . createSpyObj ( 'TrackingService' , [ 'trackTimeSpent' , 'intacctUpdateEvent' , 'integrationsOnboardingCompletion' ] ) ;
59+ const workspaceServiceSpy = jasmine . createSpyObj ( 'SiWorkspaceService' , [ 'getIntacctOnboardingState' , 'setIntacctOnboardingState' ] ) ;
5760 const helperServiceSpy = jasmine . createSpyObj ( 'HelperService' , [
5861 'disableFormField' ,
5962 'enableFormField' ,
@@ -166,4 +169,59 @@ describe('IntacctC1ImportSettingsComponent', () => {
166169 expect ( component . importSettingsForm . get ( 'costTypes' ) ) . toBeDefined ( ) ;
167170 } ) ;
168171 } ) ;
172+
173+ describe ( 'Save' , ( ) => {
174+ beforeEach ( ( ) => {
175+ importSettingService . postImportSettings . and . returnValue ( of ( importSettings ) ) ;
176+ } ) ;
177+
178+ it ( 'should handle post onboarding state' , ( ) => {
179+ component . ngOnInit ( ) ;
180+
181+ workspaceService . getIntacctOnboardingState . and . returnValue ( IntacctOnboardingState . COMPLETE ) ;
182+ component . isOnboarding = false ;
183+
184+ component . save ( ) ;
185+
186+ expect ( importSettingService . postImportSettings ) . toHaveBeenCalled ( ) ;
187+ expect ( toastService . displayToastMessage ) . toHaveBeenCalledWith ( ToastSeverity . SUCCESS , 'Import settings saved successfully' ) ;
188+ expect ( trackingService . trackTimeSpent ) . toHaveBeenCalledWith ( TrackingApp . INTACCT , Page . IMPORT_SETTINGS_INTACCT , jasmine . any ( Date ) ) ;
189+ expect ( trackingService . intacctUpdateEvent ) . toHaveBeenCalledWith (
190+ IntacctUpdateEvent . ADVANCED_SETTINGS_INTACCT ,
191+ {
192+ phase : ProgressPhase . POST_ONBOARDING ,
193+ oldState : importSettings ,
194+ newState : importSettings
195+ }
196+ ) ;
197+ expect ( component . saveInProgress ) . toBeFalse ( ) ;
198+ expect ( router . navigate ) . not . toHaveBeenCalled ( ) ;
199+ } ) ;
200+
201+ it ( 'should handle onboarding state' , ( ) => {
202+ component . ngOnInit ( ) ;
203+
204+ workspaceService . getIntacctOnboardingState . and . returnValue ( IntacctOnboardingState . IMPORT_SETTINGS ) ;
205+ component . isOnboarding = true ;
206+
207+ component . save ( ) ;
208+
209+ expect ( importSettingService . postImportSettings ) . toHaveBeenCalled ( ) ;
210+ expect ( trackingService . integrationsOnboardingCompletion ) . toHaveBeenCalledWith ( TrackingApp . INTACCT , IntacctOnboardingState . IMPORT_SETTINGS , 3 , jasmine . any ( Object ) ) ;
211+ expect ( workspaceService . setIntacctOnboardingState ) . toHaveBeenCalledWith ( IntacctOnboardingState . ADVANCED_CONFIGURATION ) ;
212+ expect ( router . navigate ) . toHaveBeenCalledWith ( [ '/integrations/intacct/onboarding/advanced_settings' ] ) ;
213+ } ) ;
214+
215+ it ( 'should handle save error' , ( ) => {
216+ component . ngOnInit ( ) ;
217+
218+ importSettingService . postImportSettings . and . returnValue ( throwError ( ( ) => new Error ( 'Error' ) ) ) ;
219+
220+ component . save ( ) ;
221+
222+ expect ( importSettingService . postImportSettings ) . toHaveBeenCalled ( ) ;
223+ expect ( toastService . displayToastMessage ) . toHaveBeenCalledWith ( ToastSeverity . ERROR , 'Error saving import settings, please try again later' ) ;
224+ expect ( component . saveInProgress ) . toBeFalse ( ) ;
225+ } ) ;
226+ } ) ;
169227} ) ;
0 commit comments