@@ -24,6 +24,8 @@ import {
2424 updateAllowUsageTracking ,
2525 updateDefaultCmsPublishMode ,
2626 isConfigFlagEnabled ,
27+ getGlobalConfigFilePath ,
28+ getLocalConfigFilePathIfExists ,
2729} from '../index' ;
2830import { HubSpotConfigAccount } from '../../types/Accounts' ;
2931import { HubSpotConfig } from '../../types/Config' ;
@@ -37,13 +39,13 @@ import {
3739 OAUTH_AUTH_METHOD ,
3840 API_KEY_AUTH_METHOD ,
3941} from '../../constants/auth' ;
40- import {
41- getGlobalConfigFilePath ,
42- getLocalConfigDefaultFilePath ,
43- formatConfigForWrite ,
44- } from '../utils' ;
42+ import { getLocalConfigDefaultFilePath , formatConfigForWrite } from '../utils' ;
4543import { getDefaultAccountOverrideAccountId } from '../defaultAccountOverride' ;
46- import { CONFIG_FLAGS , ENVIRONMENT_VARIABLES } from '../../constants/config' ;
44+ import {
45+ CONFIG_FLAGS ,
46+ ENVIRONMENT_VARIABLES ,
47+ HUBSPOT_CONFIGURATION_FOLDER ,
48+ } from '../../constants/config' ;
4749import * as utils from '../utils' ;
4850import { CmsPublishMode } from '../../types/Files' ;
4951
@@ -128,6 +130,32 @@ describe('config/index', () => {
128130 cleanup ( ) ;
129131 } ) ;
130132
133+ describe ( 'getGlobalConfigFilePath()' , ( ) => {
134+ it ( 'returns the global config file path' , ( ) => {
135+ const globalConfigFilePath = getGlobalConfigFilePath ( ) ;
136+ expect ( globalConfigFilePath ) . toBeDefined ( ) ;
137+ expect ( globalConfigFilePath ) . toContain (
138+ `${ HUBSPOT_CONFIGURATION_FOLDER } /config.yml`
139+ ) ;
140+ } ) ;
141+ } ) ;
142+
143+ describe ( 'getLocalConfigFilePathIfExists()' , ( ) => {
144+ it ( 'returns the nearest config file path' , ( ) => {
145+ const mockConfigPath = '/mock/path/hubspot.config.yml' ;
146+ mockFindup . mockReturnValue ( mockConfigPath ) ;
147+
148+ const localConfigPath = getLocalConfigFilePathIfExists ( ) ;
149+ expect ( localConfigPath ) . toBe ( mockConfigPath ) ;
150+ } ) ;
151+
152+ it ( 'returns null if no config file found' , ( ) => {
153+ mockFindup . mockReturnValue ( null ) ;
154+ const localConfigPath = getLocalConfigFilePathIfExists ( ) ;
155+ expect ( localConfigPath ) . toBeNull ( ) ;
156+ } ) ;
157+ } ) ;
158+
131159 describe ( 'localConfigFileExists()' , ( ) => {
132160 it ( 'returns true when local config exists' , ( ) => {
133161 mockFindup . mockReturnValueOnce ( getLocalConfigDefaultFilePath ( ) ) ;
@@ -243,15 +271,21 @@ describe('config/index', () => {
243271 describe ( 'deleteConfigFileIfEmpty()' , ( ) => {
244272 it ( 'deletes the config file if it is empty' , ( ) => {
245273 mockFs . existsSync . mockReturnValue ( true ) ;
246- mockFs . readFileSync . mockReturnValueOnce ( '' ) ;
274+ mockFs . readFileSync . mockReturnValueOnce ( yaml . dump ( { accounts : [ ] } ) ) ;
275+ jest
276+ . spyOn ( utils , 'parseConfig' )
277+ . mockReturnValueOnce ( { accounts : [ ] } as HubSpotConfig ) ;
247278 deleteConfigFileIfEmpty ( ) ;
248279
249280 expect ( mockFs . unlinkSync ) . toHaveBeenCalledWith ( getConfigFilePath ( ) ) ;
250281 } ) ;
251282
252283 it ( 'does not delete the config file if it is not empty' , ( ) => {
253284 mockFs . existsSync . mockReturnValue ( true ) ;
254- mockFs . readFileSync . mockReturnValueOnce ( 'test-config-content' ) ;
285+ mockFs . readFileSync . mockReturnValueOnce ( yaml . dump ( CONFIG ) ) ;
286+ jest
287+ . spyOn ( utils , 'parseConfig' )
288+ . mockReturnValueOnce ( structuredClone ( CONFIG ) ) ;
255289 deleteConfigFileIfEmpty ( ) ;
256290
257291 expect ( mockFs . unlinkSync ) . not . toHaveBeenCalled ( ) ;
0 commit comments