Skip to content

Commit ef5d54d

Browse files
Test case updated
1 parent 1daa06d commit ef5d54d

File tree

1 file changed

+21
-17
lines changed

1 file changed

+21
-17
lines changed

__tests__/index.test.js

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,42 @@
11
const { run } = require('../src/index');
22
const core = require('@actions/core');
33
const DeployManager = require('../src/deploy-manager');
4-
const fs = require('fs');
54

65
jest.mock('@actions/core');
76
jest.mock('../src/deploy-manager');
87

9-
108
describe('Invalid Inputs', () => {
119
beforeEach(() => {
12-
// Reset the mock implementation for core.getInput and DeployManager.getServerState before each test
10+
// Reset mocks
1311
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+
};
1421
DeployManager.getServerState.mockReset();
1522
});
1623

1724
test('Missing serverUrl, username, and password', async () => {
18-
// Mocking inputs
25+
// Mocking inputs: only action provided
1926
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 '';
2729
});
2830

2931
await run();
3032

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+
);
3236
});
3337

3438
test('Missing manifestPath, darPackagePath, and environmentId', async () => {
35-
// Mocking inputs
39+
// Mocking inputs: server connection inputs provided, rest missing
3640
core.getInput.mockImplementation((name) => {
3741
switch (name) {
3842
case 'action':
@@ -43,7 +47,6 @@ describe('Invalid Inputs', () => {
4347
return 'testuser';
4448
case 'password':
4549
return 'testpassword';
46-
// Other necessary inputs
4750
default:
4851
return '';
4952
}
@@ -53,7 +56,8 @@ describe('Invalid Inputs', () => {
5356

5457
await run();
5558

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+
);
5762
});
58-
59-
});
63+
});

0 commit comments

Comments
 (0)