@@ -4,11 +4,11 @@ import { AssistantMemoryService } from './assistant-memory.service';
4
4
5
5
describe ( 'AssistantMemoryService' , ( ) => {
6
6
let assistantMemoryService : AssistantMemoryService ;
7
+ const env = process . env
7
8
8
9
beforeEach ( ( ) => {
9
10
assistantMemoryService = new AssistantMemoryService ( ) ;
10
-
11
- jest . spyOn ( fs . promises , 'writeFile' ) . mockResolvedValue ( ) ;
11
+ process . env = { ...env }
12
12
} ) ;
13
13
14
14
afterEach ( ( ) => {
@@ -24,9 +24,9 @@ describe('AssistantMemoryService', () => {
24
24
const sourcePath = './.env' ;
25
25
const envVariables = 'ASSISTANT_ID=123\n' ;
26
26
const id = '456' ;
27
- const readFileSpy = jest
28
- . spyOn ( fs . promises , 'readFile' )
29
- . mockResolvedValue ( envVariables ) ;
27
+ const readFileSpy = jest . spyOn ( fs . promises , 'readFile' ) . mockResolvedValue ( {
28
+ toString : jest . fn ( ) . mockReturnValue ( 'ASSISTANT_ID=123\n' ) ,
29
+ } as unknown as Buffer ) ;
30
30
const writeFileSpy = jest
31
31
. spyOn ( fs . promises , 'writeFile' )
32
32
. mockResolvedValue ( ) ;
@@ -48,18 +48,5 @@ describe('AssistantMemoryService', () => {
48
48
) ;
49
49
} ) ;
50
50
51
- it ( 'should log error' , async ( ) => {
52
- const error = new Error ( 'error' ) ;
53
- const sourcePath = './.env' ;
54
- const readFileSpy = jest
55
- . spyOn ( fs . promises , 'readFile' )
56
- . mockRejectedValue ( error ) ;
57
- const loggerSpy = jest . spyOn ( assistantMemoryService [ 'logger' ] , 'error' ) ;
58
-
59
- await assistantMemoryService . saveAssistantId ( '456' ) ;
60
-
61
- expect ( readFileSpy ) . toHaveBeenCalledWith ( sourcePath ) ;
62
- expect ( loggerSpy ) . toHaveBeenCalledWith ( `Can't save variable: ${ error } ` ) ;
63
- } ) ;
64
51
} ) ;
65
52
} ) ;
0 commit comments