Skip to content

Commit 1c6bae9

Browse files
committed
fix: improves user creation test suite
Refactors user creation tests to enhance reliability by cleaning up database entries after each test run. This ensures consistent test execution and prevents potential conflicts due to leftover data.
1 parent 109143d commit 1c6bae9

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -486,6 +486,10 @@ describe('test git-proxy-cli', function () {
486486
// *** create user ***
487487

488488
describe('test git-proxy-cli :: create-user', function () {
489+
const testUser = 'testuser';
490+
const testPassword = 'testpassword';
491+
const testEmail = '[email protected]';
492+
489493
it('attempt to create user should fail when server is down', async function () {
490494
try {
491495
// start server -> login -> stop server
@@ -514,9 +518,10 @@ describe('test git-proxy-cli', function () {
514518

515519
it('attempt to create user should fail when not admin', async function () {
516520
try {
521+
await helper.addUserToDb(testUser, testPassword, testEmail, 'testGitAccount');
517522
await helper.startServer(service);
518523
await helper.runCli(
519-
`npx -- @finos/git-proxy-cli login --username testuser --password testpassword`,
524+
`npx -- @finos/git-proxy-cli login --username ${testUser} --password ${testPassword}`,
520525
);
521526

522527
const cli = `npx -- @finos/git-proxy-cli create-user --username newuser --password newpass --email [email protected] --gitAccount newgit`;
@@ -525,6 +530,7 @@ describe('test git-proxy-cli', function () {
525530
const expectedErrorMessages = ['Error: Create User: Authentication required'];
526531
await helper.runCli(cli, expectedExitCode, expectedMessages, expectedErrorMessages);
527532
} finally {
533+
await helper.removeUserFromDb(testUser);
528534
await helper.closeServer(service.httpServer);
529535
}
530536
});
@@ -563,6 +569,7 @@ describe('test git-proxy-cli', function () {
563569
null,
564570
);
565571
} finally {
572+
await helper.removeUserFromDb('newuser');
566573
await helper.closeServer(service.httpServer);
567574
}
568575
});
@@ -586,6 +593,7 @@ describe('test git-proxy-cli', function () {
586593
null,
587594
);
588595
} finally {
596+
await helper.removeUserFromDb('newadmin');
589597
await helper.closeServer(service.httpServer);
590598
}
591599
});

0 commit comments

Comments
 (0)