@@ -4,33 +4,49 @@ import { TokenService } from './token.service';
44import { StorageService } from './storage.service' ;
55import { SecureStorageService } from './secure-storage.service' ;
66import { RouterAuthService } from './router-auth.service' ;
7+ import { PlatformOrgSettingsService } from './platform/v1/spender/org-settings.service' ;
8+ import { of } from 'rxjs' ;
9+ import { getFormatPreferenceProviders } from '../testing/format-preference-providers.utils' ;
10+ import { FORMAT_PREFERENCES } from 'src/app/constants' ;
11+ import { FormatPreferences } from 'src/app/core/models/format-preferences.model' ;
12+ import { DATE_PIPE_DEFAULT_OPTIONS } from '@angular/common' ;
13+ import { orgSettingsRes } from '../mock-data/org-settings.data' ;
714
815describe ( 'ConfigService' , ( ) => {
916 let configService : ConfigService ;
1017 let tokenService : jasmine . SpyObj < TokenService > ;
1118 let storageService : jasmine . SpyObj < StorageService > ;
1219 let secureStorageService : jasmine . SpyObj < SecureStorageService > ;
1320 let routerAuthService : jasmine . SpyObj < RouterAuthService > ;
21+ let orgSettingsService : jasmine . SpyObj < PlatformOrgSettingsService > ;
22+ let formatPreferences : FormatPreferences ;
23+ let datePipeOptions : { dateFormat : string } ;
1424
1525 beforeEach ( ( ) => {
1626 const tokenServiceSpy = jasmine . createSpyObj ( 'TokenService' , [ 'getClusterDomain' ] ) ;
1727 const storageServiceSpy = jasmine . createSpyObj ( 'StorageService' , [ 'clearAll' ] ) ;
1828 const secureStorageServiceSpy = jasmine . createSpyObj ( 'SecureStorageService' , [ 'clearAll' ] ) ;
1929 const routerAuthServiceSpy = jasmine . createSpyObj ( 'RouterAuthService' , [ 'setClusterDomain' ] ) ;
30+ const orgSettingsServiceSpy = jasmine . createSpyObj ( 'PlatformOrgSettingsService' , [ 'get' ] ) ;
2031 TestBed . configureTestingModule ( {
2132 providers : [
2233 ConfigService ,
2334 { provide : TokenService , useValue : tokenServiceSpy } ,
2435 { provide : StorageService , useValue : storageServiceSpy } ,
2536 { provide : SecureStorageService , useValue : secureStorageServiceSpy } ,
2637 { provide : RouterAuthService , useValue : routerAuthServiceSpy } ,
38+ { provide : PlatformOrgSettingsService , useValue : orgSettingsServiceSpy } ,
39+ ...getFormatPreferenceProviders ( ) ,
2740 ] ,
2841 } ) ;
2942 configService = TestBed . inject ( ConfigService ) ;
3043 tokenService = TestBed . inject ( TokenService ) as jasmine . SpyObj < TokenService > ;
3144 storageService = TestBed . inject ( StorageService ) as jasmine . SpyObj < StorageService > ;
3245 secureStorageService = TestBed . inject ( SecureStorageService ) as jasmine . SpyObj < SecureStorageService > ;
3346 routerAuthService = TestBed . inject ( RouterAuthService ) as jasmine . SpyObj < RouterAuthService > ;
47+ orgSettingsService = TestBed . inject ( PlatformOrgSettingsService ) as jasmine . SpyObj < PlatformOrgSettingsService > ;
48+ formatPreferences = TestBed . inject ( FORMAT_PREFERENCES ) as FormatPreferences ;
49+ datePipeOptions = TestBed . inject ( DATE_PIPE_DEFAULT_OPTIONS ) as { dateFormat : string } ;
3450 } ) ;
3551
3652 it ( 'should be created' , ( ) => {
@@ -41,16 +57,48 @@ describe('ConfigService', () => {
4157 it ( 'should call setClusterDomain if clusterDomain is present' , async ( ) => {
4258 const clusterDomain = 'https://staging.fyle.tech' ;
4359 tokenService . getClusterDomain . and . resolveTo ( clusterDomain ) ;
60+
61+ orgSettingsService . get . and . returnValue ( of ( orgSettingsRes ) ) ;
4462 await configService . loadConfigurationData ( ) ;
4563 expect ( routerAuthService . setClusterDomain ) . toHaveBeenCalledOnceWith ( clusterDomain ) ;
4664 expect ( tokenService . getClusterDomain ) . toHaveBeenCalledTimes ( 1 ) ;
4765 } ) ;
4866
4967 it ( 'should clear all stored data if clusterDomain is not present' , async ( ) => {
5068 tokenService . getClusterDomain . and . resolveTo ( null ) ;
69+ orgSettingsService . get . and . returnValue ( of ( orgSettingsRes ) ) ;
70+
5171 await configService . loadConfigurationData ( ) ;
5272 expect ( storageService . clearAll ) . toHaveBeenCalledTimes ( 1 ) ;
5373 expect ( secureStorageService . clearAll ) . toHaveBeenCalledTimes ( 1 ) ;
5474 } ) ;
75+
76+ it ( 'should update format preferences and date options from regional settings' , async ( ) => {
77+ const clusterDomain = 'https://staging.fyle.tech' ;
78+ tokenService . getClusterDomain . and . resolveTo ( clusterDomain ) ;
79+ const orgSettings = {
80+ ...orgSettingsRes ,
81+ regional_settings : {
82+ allowed : true ,
83+ enabled : true ,
84+ time_format : 'H:mm' ,
85+ date_format : 'dd/MM/yyyy' ,
86+ currency_format : {
87+ decimal_separator : ',' ,
88+ thousand_separator : '.' ,
89+ symbol_position : 'after' ,
90+ } ,
91+ } ,
92+ } ;
93+ orgSettingsService . get . and . returnValue ( of ( orgSettings ) ) ;
94+
95+ await configService . loadConfigurationData ( ) ;
96+
97+ expect ( formatPreferences . timeFormat ) . toBe ( 'H:mm' ) ;
98+ expect ( formatPreferences . currencyFormat . placement ) . toBe ( 'after' ) ;
99+ expect ( formatPreferences . currencyFormat . decimalSeparator ) . toBe ( ',' ) ;
100+ expect ( formatPreferences . currencyFormat . thousandSeparator ) . toBe ( '.' ) ;
101+ expect ( datePipeOptions . dateFormat ) . toBe ( 'dd/MM/yyyy' ) ;
102+ } ) ;
55103 } ) ;
56104} ) ;
0 commit comments