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', () => {
19621962 } ) ;
19631963 } ) ;
19641964
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+
19651996 afterAll ( ( ) => {
19661997 cronJob . stop ( ) ;
19671998 clearInterval ( errsolePostgres . flushIntervalId ) ;
You can’t perform that action at this time.
0 commit comments