File tree Expand file tree Collapse file tree 1 file changed +31
-0
lines changed Expand file tree Collapse file tree 1 file changed +31
-0
lines changed Original file line number Diff line number Diff line change @@ -1962,6 +1962,37 @@ describe('ErrsolePostgres', () => {
1962
1962
} ) ;
1963
1963
} ) ;
1964
1964
1965
+ describe ( '#deleteAllLogs' , ( ) => {
1966
+ let poolQuerySpy ;
1967
+
1968
+ beforeEach ( ( ) => {
1969
+ poolQuerySpy = jest . spyOn ( poolMock , 'query' ) ;
1970
+ poolMock . query . mockClear ( ) ; // Clear any previous calls
1971
+ } ) ;
1972
+
1973
+ afterEach ( ( ) => {
1974
+ jest . clearAllMocks ( ) ;
1975
+ } ) ;
1976
+
1977
+ it ( 'should delete all logs and reset the table identity' , async ( ) => {
1978
+ poolMock . query . mockResolvedValueOnce ( { } ) ;
1979
+
1980
+ const result = await errsolePostgres . deleteAllLogs ( ) ;
1981
+
1982
+ expect ( poolQuerySpy ) . toHaveBeenCalledWith ( 'TRUNCATE TABLE errsole_logs_v2 RESTART IDENTITY CASCADE' ) ;
1983
+ expect ( result ) . toEqual ( { } ) ;
1984
+ } ) ;
1985
+
1986
+ it ( 'should throw an error if the query fails' , async ( ) => {
1987
+ const error = new Error ( 'Query error' ) ;
1988
+ poolMock . query . mockRejectedValueOnce ( error ) ;
1989
+
1990
+ await expect ( errsolePostgres . deleteAllLogs ( ) ) . rejects . toThrow ( 'Query error' ) ;
1991
+
1992
+ expect ( poolQuerySpy ) . toHaveBeenCalledWith ( 'TRUNCATE TABLE errsole_logs_v2 RESTART IDENTITY CASCADE' ) ;
1993
+ } ) ;
1994
+ } ) ;
1995
+
1965
1996
afterAll ( ( ) => {
1966
1997
cronJob . stop ( ) ;
1967
1998
clearInterval ( errsolePostgres . flushIntervalId ) ;
You can’t perform that action at this time.
0 commit comments