1
1
const { run } = require ( '../src/index' ) ;
2
2
const core = require ( '@actions/core' ) ;
3
3
const DeployManager = require ( '../src/deploy-manager' ) ;
4
- const fs = require ( 'fs' ) ;
5
4
6
5
jest . mock ( '@actions/core' ) ;
7
6
jest . mock ( '../src/deploy-manager' ) ;
8
7
9
-
10
8
describe ( 'Invalid Inputs' , ( ) => {
11
9
beforeEach ( ( ) => {
12
- // Reset the mock implementation for core.getInput and DeployManager.getServerState before each test
10
+ // Reset mocks
13
11
core . getInput . mockReset ( ) ;
12
+ core . setFailed . mockReset ( ) ;
13
+ core . error . mockReset ( ) ;
14
+ // Stub core.summary to avoid undefined errors
15
+ core . summary = {
16
+ addHeading : jest . fn ( ) . mockReturnThis ( ) ,
17
+ addSeparator : jest . fn ( ) . mockReturnThis ( ) ,
18
+ addCodeBlock : jest . fn ( ) . mockReturnThis ( ) ,
19
+ write : jest . fn ( ) . mockResolvedValue ( ) ,
20
+ } ;
14
21
DeployManager . getServerState . mockReset ( ) ;
15
22
} ) ;
16
23
17
24
test ( 'Missing serverUrl, username, and password' , async ( ) => {
18
- // Mocking inputs
25
+ // Mocking inputs: only action provided
19
26
core . getInput . mockImplementation ( ( name ) => {
20
- switch ( name ) {
21
- case 'action' :
22
- return 'create_publish_deploy' ;
23
- // Missing serverUrl, username, and password
24
- default :
25
- return '' ;
26
- }
27
+ if ( name === 'action' ) return 'create_publish_deploy' ;
28
+ return '' ;
27
29
} ) ;
28
30
29
31
await run ( ) ;
30
32
31
- expect ( core . setFailed ) . toHaveBeenCalledWith ( 'serverUrl, username, and password are required.' ) ;
33
+ expect ( core . setFailed ) . toHaveBeenCalledWith (
34
+ 'serverUrl, username, and password are required for all actions.'
35
+ ) ;
32
36
} ) ;
33
37
34
38
test ( 'Missing manifestPath, darPackagePath, and environmentId' , async ( ) => {
35
- // Mocking inputs
39
+ // Mocking inputs: server connection inputs provided, rest missing
36
40
core . getInput . mockImplementation ( ( name ) => {
37
41
switch ( name ) {
38
42
case 'action' :
@@ -43,7 +47,6 @@ describe('Invalid Inputs', () => {
43
47
return 'testuser' ;
44
48
case 'password' :
45
49
return 'testpassword' ;
46
- // Other necessary inputs
47
50
default :
48
51
return '' ;
49
52
}
@@ -53,7 +56,8 @@ describe('Invalid Inputs', () => {
53
56
54
57
await run ( ) ;
55
58
56
- expect ( core . setFailed ) . toHaveBeenCalledWith ( "manifestPath is required for action 'create_publish_deploy'." ) ;
59
+ expect ( core . setFailed ) . toHaveBeenCalledWith (
60
+ "Input 'manifestPath' is required for action 'create_publish_deploy'."
61
+ ) ;
57
62
} ) ;
58
-
59
- } ) ;
63
+ } ) ;
0 commit comments