@@ -1955,30 +1955,34 @@ describe('QueryOrchestrator', () => {
1955
1955
] ) ;
1956
1956
} ) ;
1957
1957
1958
- test ( 'should use cache on second call' , async ( ) => {
1959
- // First call
1960
- await metadataOrchestrator . queryDataSourceSchemas ( ) ;
1961
- // Second call should use cache
1962
- const result = await metadataOrchestrator . queryDataSourceSchemas ( ) ;
1958
+ test ( 'should use cache when syncJobId is provided' , async ( ) => {
1959
+ // First call with syncJobId
1960
+ await metadataOrchestrator . queryDataSourceSchemas ( 'default' , { syncJobId : 'job-123' } ) ;
1961
+
1962
+ // Clear the mock calls
1963
+ metadataMockDriver . getSchemas . mockClear ( ) ;
1964
+
1965
+ // Second call with same syncJobId should use cache
1966
+ const result = await metadataOrchestrator . queryDataSourceSchemas ( 'default' , { syncJobId : 'job-123' } ) ;
1963
1967
1964
1968
expect ( result ) . toEqual ( [
1965
1969
{ schema_name : 'public' } ,
1966
1970
{ schema_name : 'analytics' } ,
1967
1971
{ schema_name : 'staging' }
1968
1972
] ) ;
1973
+
1974
+ // Verify driver wasn't called again
1975
+ expect ( metadataMockDriver . getSchemas ) . not . toHaveBeenCalled ( ) ;
1969
1976
} ) ;
1970
1977
1971
- test ( 'should force refresh when requested ' , async ( ) => {
1978
+ test ( 'should refresh when syncJobId is not provided ' , async ( ) => {
1972
1979
// First call
1973
1980
await metadataOrchestrator . queryDataSourceSchemas ( ) ;
1974
- // Second call with forceRefresh
1975
- const result = await metadataOrchestrator . queryDataSourceSchemas ( 'default' , { forceRefresh : true } ) ;
1981
+ // Second call without syncJobId should refresh
1982
+ await metadataOrchestrator . queryDataSourceSchemas ( ) ;
1976
1983
1977
- expect ( result ) . toEqual ( [
1978
- { schema_name : 'public' } ,
1979
- { schema_name : 'analytics' } ,
1980
- { schema_name : 'staging' }
1981
- ] ) ;
1984
+ // Driver should be called twice
1985
+ expect ( metadataMockDriver . getSchemas ) . toHaveBeenCalledTimes ( 2 ) ;
1982
1986
} ) ;
1983
1987
1984
1988
test ( 'should pass requestId option' , async ( ) => {
@@ -2008,11 +2012,11 @@ describe('QueryOrchestrator', () => {
2008
2012
expect ( metadataMockDriver . getTablesForSpecificSchemas ) . toHaveBeenCalledWith ( schemas ) ;
2009
2013
} ) ;
2010
2014
2011
- test ( 'should cache results based on schema list ' , async ( ) => {
2015
+ test ( 'should use cache when syncJobId is provided ' , async ( ) => {
2012
2016
const schemas = [ { schema_name : 'public' } ] ;
2013
2017
2014
- // First call - will execute and store in cache
2015
- await metadataOrchestrator . queryTablesForSchemas ( schemas ) ;
2018
+ // First call with syncJobId - will execute and store in cache
2019
+ await metadataOrchestrator . queryTablesForSchemas ( schemas , 'default' , { syncJobId : 'job-123' } ) ;
2016
2020
2017
2021
// Add a delay to ensure the first query has completed and cached its result
2018
2022
await new Promise ( resolve => setTimeout ( resolve , 100 ) ) ;
@@ -2024,8 +2028,8 @@ describe('QueryOrchestrator', () => {
2024
2028
// Our hash function should handle this correctly
2025
2029
const schemas2 = [ { schema_name : 'public' } ] ;
2026
2030
2027
- // Second call should use cache
2028
- const result = await metadataOrchestrator . queryTablesForSchemas ( schemas2 ) ;
2031
+ // Second call with same syncJobId should use cache
2032
+ const result = await metadataOrchestrator . queryTablesForSchemas ( schemas2 , 'default' , { syncJobId : 'job-123' } ) ;
2029
2033
2030
2034
expect ( result ) . toEqual ( [
2031
2035
{ schema_name : 'public' , table_name : 'users' } ,
@@ -2044,11 +2048,11 @@ describe('QueryOrchestrator', () => {
2044
2048
expect ( metadataMockDriver . getTablesForSpecificSchemas ) . toHaveBeenCalledWith ( [ ] ) ;
2045
2049
} ) ;
2046
2050
2047
- test ( 'should force refresh when requested ' , async ( ) => {
2051
+ test ( 'should refresh when syncJobId is not provided ' , async ( ) => {
2048
2052
const schemas = [ { schema_name : 'public' } ] ;
2049
2053
2050
2054
await metadataOrchestrator . queryTablesForSchemas ( schemas ) ;
2051
- await metadataOrchestrator . queryTablesForSchemas ( schemas , 'default' , { forceRefresh : true } ) ;
2055
+ await metadataOrchestrator . queryTablesForSchemas ( schemas ) ;
2052
2056
2053
2057
expect ( metadataMockDriver . getTablesForSpecificSchemas ) . toHaveBeenCalledTimes ( 2 ) ;
2054
2058
} ) ;
@@ -2111,11 +2115,11 @@ describe('QueryOrchestrator', () => {
2111
2115
expect ( metadataMockDriver . getColumnsForSpecificTables ) . toHaveBeenCalledWith ( tables ) ;
2112
2116
} ) ;
2113
2117
2114
- test ( 'should cache results based on table list ' , async ( ) => {
2118
+ test ( 'should use cache when syncJobId is provided ' , async ( ) => {
2115
2119
const tables = [ { schema_name : 'public' , table_name : 'users' } ] ;
2116
2120
2117
- // First call - will execute and store in cache
2118
- await metadataOrchestrator . queryColumnsForTables ( tables ) ;
2121
+ // First call with syncJobId - will execute and store in cache
2122
+ await metadataOrchestrator . queryColumnsForTables ( tables , 'default' , { syncJobId : 'job-123' } ) ;
2119
2123
2120
2124
// Add a delay to ensure the first query has completed and cached its result
2121
2125
await new Promise ( resolve => setTimeout ( resolve , 100 ) ) ;
@@ -2127,8 +2131,8 @@ describe('QueryOrchestrator', () => {
2127
2131
// Our hash function should handle this correctly
2128
2132
const tables2 = [ { schema_name : 'public' , table_name : 'users' } ] ;
2129
2133
2130
- // Second call should use cache
2131
- const result = await metadataOrchestrator . queryColumnsForTables ( tables2 ) ;
2134
+ // Second call with same syncJobId should use cache
2135
+ const result = await metadataOrchestrator . queryColumnsForTables ( tables2 , 'default' , { syncJobId : 'job-123' } ) ;
2132
2136
2133
2137
expect ( result ) . toEqual ( [
2134
2138
{
@@ -2165,11 +2169,11 @@ describe('QueryOrchestrator', () => {
2165
2169
expect ( metadataMockDriver . getColumnsForSpecificTables ) . toHaveBeenCalledWith ( [ ] ) ;
2166
2170
} ) ;
2167
2171
2168
- test ( 'should force refresh when requested ' , async ( ) => {
2172
+ test ( 'should refresh when syncJobId is not provided ' , async ( ) => {
2169
2173
const tables = [ { schema_name : 'public' , table_name : 'users' } ] ;
2170
2174
2171
2175
await metadataOrchestrator . queryColumnsForTables ( tables ) ;
2172
- await metadataOrchestrator . queryColumnsForTables ( tables , 'default' , { forceRefresh : true } ) ;
2176
+ await metadataOrchestrator . queryColumnsForTables ( tables ) ;
2173
2177
2174
2178
expect ( metadataMockDriver . getColumnsForSpecificTables ) . toHaveBeenCalledTimes ( 2 ) ;
2175
2179
} ) ;
@@ -2217,11 +2221,11 @@ describe('QueryOrchestrator', () => {
2217
2221
// Mock driver error
2218
2222
metadataMockDriver . getSchemas . mockRejectedValueOnce ( new Error ( 'Database connection failed' ) ) ;
2219
2223
2220
- await expect ( metadataOrchestrator . queryDataSourceSchemas ( 'default' , { forceRefresh : true } ) ) . rejects . toThrow ( 'Database connection failed' ) ;
2224
+ await expect ( metadataOrchestrator . queryDataSourceSchemas ( ) ) . rejects . toThrow ( 'Database connection failed' ) ;
2221
2225
2222
2226
// Should retry on next call
2223
2227
metadataMockDriver . getSchemas . mockResolvedValueOnce ( [ { schema_name : 'recovered' } ] ) ;
2224
- const result = await metadataOrchestrator . queryDataSourceSchemas ( 'default' , { forceRefresh : true } ) ;
2228
+ const result = await metadataOrchestrator . queryDataSourceSchemas ( ) ;
2225
2229
expect ( result ) . toEqual ( [ { schema_name : 'recovered' } ] ) ;
2226
2230
} ) ;
2227
2231
} ) ;
0 commit comments