Skip to content

Commit 33d33ed

Browse files
committed
Add tests and format
1 parent d3a0e26 commit 33d33ed

File tree

2 files changed

+37
-4
lines changed

2 files changed

+37
-4
lines changed

src/utils.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,7 @@ export class Utils {
390390
* Returns the custom server ID if provided, otherwise returns the default server ID.
391391
*/
392392
private static getCustomOrDefaultServerId(): string {
393-
const customServerId :string | undefined = this.getInputtedCustomId();
393+
const customServerId: string | undefined = this.getInputtedCustomId();
394394
return customServerId || this.getRunDefaultServerId();
395395
}
396396

@@ -399,7 +399,7 @@ export class Utils {
399399
if (customServerId) {
400400
return customServerId;
401401
}
402-
return undefined
402+
return undefined;
403403
}
404404

405405
/**
@@ -476,7 +476,7 @@ export class Utils {
476476
* If a custom server ID is defined, only remove the custom server ID.
477477
*/
478478
public static async removeJFrogServers() {
479-
const customServerId:string | undefined = this.getInputtedCustomId();
479+
const customServerId: string | undefined = this.getInputtedCustomId();
480480
core.info(`The value of custom is: '${customServerId}'`);
481481

482482
if (customServerId) {

test/main.spec.ts

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import semver = require('semver/preload');
66
jest.mock('os');
77
jest.mock('@actions/core');
88
jest.mock('semver');
9-
109
const DEFAULT_CLI_URL: string = 'https://releases.jfrog.io/artifactory/jfrog-cli/';
1110
const CUSTOM_CLI_URL: string = 'http://127.0.0.1:8081/artifactory/jfrog-cli-remote/';
1211
// Config in JFrog CLI 1.46.3 and below
@@ -425,3 +424,37 @@ describe('isJobSummarySupported', () => {
425424
expect(semver.gte).toHaveBeenCalledWith(version, MIN_CLI_VERSION_JOB_SUMMARY);
426425
});
427426
});
427+
428+
describe('Utils.removeJFrogServers', () => {
429+
beforeEach(() => {
430+
jest.clearAllMocks();
431+
});
432+
433+
it('should remove only the custom server ID if defined', async () => {
434+
const customServerId: string = 'custom-server-id';
435+
jest.spyOn(Utils as any, 'getInputtedCustomId').mockReturnValue(customServerId);
436+
jest.spyOn(Utils as any, 'runCli').mockResolvedValue(undefined);
437+
438+
await Utils.removeJFrogServers();
439+
440+
expect(core.info).toHaveBeenCalledWith(`The value of custom is: '${customServerId}'`);
441+
expect(core.debug).toHaveBeenCalledWith(`Removing custom server ID: '${customServerId}'...`);
442+
expect(Utils.runCli).toHaveBeenCalledWith(['c', 'rm', customServerId, '--quiet']);
443+
});
444+
445+
it('should remove all configured server IDs if no custom server ID is defined', async () => {
446+
jest.spyOn(Utils as any, 'getInputtedCustomId').mockReturnValue(undefined);
447+
const serverIds: string[] = ['server1', 'server2'];
448+
jest.spyOn(Utils as any, 'getConfiguredJFrogServers').mockReturnValue(serverIds);
449+
jest.spyOn(Utils as any, 'runCli').mockResolvedValue(undefined);
450+
451+
await Utils.removeJFrogServers();
452+
453+
expect(core.info).toHaveBeenCalledWith(`The value of custom is: 'undefined'`);
454+
for (const serverId of serverIds) {
455+
expect(core.debug).toHaveBeenCalledWith(`Removing server ID: '${serverId}'...`);
456+
expect(Utils.runCli).toHaveBeenCalledWith(['c', 'rm', serverId, '--quiet']);
457+
}
458+
expect(core.exportVariable).toHaveBeenCalledWith(Utils.JFROG_CLI_SERVER_IDS_ENV_VAR, '');
459+
});
460+
});

0 commit comments

Comments
 (0)