@@ -28,28 +28,30 @@ jest.unstable_mockModule('@azure-rest/ai-inference', () => ({
28
28
isUnexpected : jest . fn ( ( ) => false )
29
29
} ) )
30
30
31
+ const mockExistsSync = jest . fn ( ) . mockReturnValue ( true )
32
+ const mockReadFileSync = jest . fn ( ) . mockReturnValue ( 'Hello, AI!' )
33
+
34
+ jest . unstable_mockModule ( 'fs' , ( ) => ( {
35
+ existsSync : mockExistsSync ,
36
+ readFileSync : mockReadFileSync
37
+ } ) )
38
+
31
39
jest . unstable_mockModule ( '@actions/core' , ( ) => core )
32
40
33
41
// The module being tested should be imported dynamically. This ensures that the
34
42
// mocks are used in place of any actual dependencies.
35
43
const { run } = await import ( '../src/main.js' )
36
44
37
45
describe ( 'main.ts' , ( ) => {
38
- beforeEach ( ( ) => {
46
+ it ( 'Sets the response output' , async ( ) => {
39
47
// Set the action's inputs as return values from core.getInput().
40
48
core . getInput . mockImplementation ( ( name ) => {
41
49
if ( name === 'prompt' ) return 'Hello, AI!'
42
50
if ( name === 'system_prompt' ) return 'You are a test assistant.'
43
51
if ( name === 'model_name' ) return 'gpt-4o'
44
52
return ''
45
53
} )
46
- } )
47
-
48
- afterEach ( ( ) => {
49
- jest . resetAllMocks ( )
50
- } )
51
54
52
- it ( 'Sets the response output' , async ( ) => {
53
55
await run ( )
54
56
55
57
expect ( core . setOutput ) . toHaveBeenNthCalledWith (
@@ -78,4 +80,29 @@ describe('main.ts', () => {
78
80
// Verify that the action was marked as failed.
79
81
expect ( core . setFailed ) . toHaveBeenNthCalledWith ( 1 , 'prompt is not set' )
80
82
} )
83
+
84
+ it ( 'uses prompt-file' , async ( ) => {
85
+ const promptFile = 'prompt.txt'
86
+ core . getInput . mockImplementation ( ( name ) => {
87
+ if ( name === 'prompt-file' ) return promptFile
88
+ if ( name === 'system-prompt' ) return 'You are a test assistant.'
89
+ if ( name === 'model-name' ) return 'gpt-4o'
90
+ return ''
91
+ } )
92
+
93
+ await run ( )
94
+
95
+ expect ( mockExistsSync ) . toHaveBeenCalledWith ( promptFile )
96
+ expect ( mockReadFileSync ) . toHaveBeenCalledWith ( promptFile , 'utf-8' )
97
+ expect ( core . setOutput ) . toHaveBeenNthCalledWith (
98
+ 1 ,
99
+ 'response' ,
100
+ 'Hello, user!'
101
+ )
102
+ expect ( core . setOutput ) . toHaveBeenNthCalledWith (
103
+ 2 ,
104
+ 'response-path' ,
105
+ expect . stringContaining ( 'modelResponse.txt' )
106
+ )
107
+ } )
81
108
} )
0 commit comments