Skip to content

Commit fa4c28f

Browse files
committed
fix: resolve CLI test failures in GitHub Actions
- Add proper test setup/teardown for create-user tests - Fix missing required fields test to use empty password instead of omitting it - Use unique usernames with timestamps to prevent conflicts between test runs - Add proper cleanup for created users in finally blocks - Ensure all 42 CLI tests now pass consistently
1 parent cf17024 commit fa4c28f

File tree

1 file changed

+31
-9
lines changed

1 file changed

+31
-9
lines changed

packages/git-proxy-cli/test/testCli.test.js

Lines changed: 31 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -493,6 +493,14 @@ describe('test git-proxy-cli', function () {
493493
// *** create user ***
494494

495495
describe('test git-proxy-cli :: create-user', function () {
496+
before(async function () {
497+
await helper.addUserToDb(TEST_USER, TEST_PASSWORD, TEST_EMAIL, TEST_GIT_ACCOUNT);
498+
});
499+
500+
after(async function () {
501+
await helper.removeUserFromDb(TEST_USER);
502+
});
503+
496504
it('attempt to create user should fail when server is down', async function () {
497505
try {
498506
// start server -> login -> stop server
@@ -541,7 +549,7 @@ describe('test git-proxy-cli', function () {
541549
await helper.startServer(service);
542550
await helper.runCli(`npx -- @finos/git-proxy-cli login --username admin --password admin`);
543551

544-
const cli = `npx -- @finos/git-proxy-cli create-user --username newuser --email new@email.com --gitAccount newgit`;
552+
const cli = `npx -- @finos/git-proxy-cli create-user --username newuser --password "" --email new@email.com --gitAccount newgit`;
545553
const expectedExitCode = 4;
546554
const expectedMessages = null;
547555
const expectedErrorMessages = ['Error: Create User: Missing required fields'];
@@ -552,48 +560,62 @@ describe('test git-proxy-cli', function () {
552560
});
553561

554562
it('should successfully create a new user', async function () {
563+
const uniqueUsername = `newuser_${Date.now()}`;
555564
try {
556565
await helper.startServer(service);
557566
await helper.runCli(`npx -- @finos/git-proxy-cli login --username admin --password admin`);
558567

559-
const cli = `npx -- @finos/git-proxy-cli create-user --username newuser --password newpass --email new@email.com --gitAccount newgit`;
568+
const cli = `npx -- @finos/git-proxy-cli create-user --username ${uniqueUsername} --password newpass --email new@email.com --gitAccount newgit`;
560569
const expectedExitCode = 0;
561-
const expectedMessages = ["User 'newuser' created successfully"];
570+
const expectedMessages = [`User '${uniqueUsername}' created successfully`];
562571
const expectedErrorMessages = null;
563572
await helper.runCli(cli, expectedExitCode, expectedMessages, expectedErrorMessages);
564573

565574
// Verify we can login with the new user
566575
await helper.runCli(
567-
`npx -- @finos/git-proxy-cli login --username newuser --password newpass`,
576+
`npx -- @finos/git-proxy-cli login --username ${uniqueUsername} --password newpass`,
568577
0,
569-
[`Login "newuser" <new@email.com>: OK`],
578+
[`Login "${uniqueUsername}" <new@email.com>: OK`],
570579
null,
571580
);
572581
} finally {
573582
await helper.closeServer(service.httpServer);
583+
// Clean up the created user
584+
try {
585+
await helper.removeUserFromDb(uniqueUsername);
586+
} catch (error) {
587+
// Ignore cleanup errors
588+
}
574589
}
575590
});
576591

577592
it('should successfully create a new admin user', async function () {
593+
const uniqueUsername = `newadmin_${Date.now()}`;
578594
try {
579595
await helper.startServer(service);
580596
await helper.runCli(`npx -- @finos/git-proxy-cli login --username admin --password admin`);
581597

582-
const cli = `npx -- @finos/git-proxy-cli create-user --username newadmin --password newpass --email newadmin@email.com --gitAccount newgit --admin`;
598+
const cli = `npx -- @finos/git-proxy-cli create-user --username ${uniqueUsername} --password newpass --email newadmin@email.com --gitAccount newgit --admin`;
583599
const expectedExitCode = 0;
584-
const expectedMessages = ["User 'newadmin' created successfully"];
600+
const expectedMessages = [`User '${uniqueUsername}' created successfully`];
585601
const expectedErrorMessages = null;
586602
await helper.runCli(cli, expectedExitCode, expectedMessages, expectedErrorMessages);
587603

588604
// Verify we can login with the new admin user
589605
await helper.runCli(
590-
`npx -- @finos/git-proxy-cli login --username newadmin --password newpass`,
606+
`npx -- @finos/git-proxy-cli login --username ${uniqueUsername} --password newpass`,
591607
0,
592-
[`Login "newadmin" <newadmin@email.com> (admin): OK`],
608+
[`Login "${uniqueUsername}" <newadmin@email.com> (admin): OK`],
593609
null,
594610
);
595611
} finally {
596612
await helper.closeServer(service.httpServer);
613+
// Clean up the created user
614+
try {
615+
await helper.removeUserFromDb(uniqueUsername);
616+
} catch (error) {
617+
// Ignore cleanup errors
618+
}
597619
}
598620
});
599621
});

0 commit comments

Comments
 (0)