Skip to content

Commit af46924

Browse files
committed
refactor: checkUserPushPermission.ts logs refactored and test changed accordingly
1 parent 6ef713e commit af46924

2 files changed

Lines changed: 7 additions & 11 deletions

File tree

src/proxy/processors/push-action/checkUserPushPermission.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ const validateUser = async (userEmail: string, action: Action, step: Step): Prom
3131
const list = await getUsers({ email: userEmail });
3232

3333
if (list.length > 1) {
34-
console.error(`Multiple users found with email address ${userEmail}, ending`);
3534
step.error = true;
35+
step.log(`Multiple users found with email address ${userEmail}, ending`);
3636
step.log(
3737
`Multiple Users have email <${userEmail}> so we cannot uniquely identify the user, ending`,
3838
);
@@ -43,15 +43,15 @@ const validateUser = async (userEmail: string, action: Action, step: Step): Prom
4343
action.addStep(step);
4444
return action;
4545
} else if (list.length == 0) {
46-
console.error(`No user with email address ${userEmail} found`);
46+
step.log(`No user with email address ${userEmail} found`);
4747
} else {
4848
isUserAllowed = await isUserPushAllowed(action.url, list[0].username);
4949
}
5050

51-
console.log(`User ${userEmail} permission on Repo ${action.url} : ${isUserAllowed}`);
51+
step.log(`User ${userEmail} permission on Repo ${action.url} : ${isUserAllowed}`);
5252

5353
if (!isUserAllowed) {
54-
console.log('User not allowed to Push');
54+
step.log('User not allowed to Push');
5555
step.error = true;
5656
step.log(`User ${userEmail} is not allowed to push on repo ${action.url}, ending`);
5757
step.setError(

test/processors/checkUserPushPermission.test.ts

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,10 @@ import { exec } from '../../src/proxy/processors/push-action/checkUserPushPermis
1515
describe('checkUserPushPermission', () => {
1616
let getUsersMock: Mock;
1717
let isUserPushAllowedMock: Mock;
18-
let consoleLogSpy: ReturnType<typeof vi.spyOn>;
19-
let consoleErrorSpy: ReturnType<typeof vi.spyOn>;
2018

2119
beforeEach(() => {
2220
getUsersMock = vi.mocked(getUsers);
2321
isUserPushAllowedMock = vi.mocked(isUserPushAllowed);
24-
consoleLogSpy = vi.spyOn(console, 'log').mockImplementation(() => {});
25-
consoleErrorSpy = vi.spyOn(console, 'error').mockImplementation(() => {});
2622
});
2723

2824
afterEach(() => {
@@ -62,7 +58,7 @@ describe('checkUserPushPermission', () => {
6258
expect(stepLogSpy).toHaveBeenLastCalledWith(
6359
'User db-user@test.com is allowed to push on repo https://github.com/finos/git-proxy.git',
6460
);
65-
expect(consoleLogSpy).toHaveBeenLastCalledWith(
61+
expect(stepLogSpy).toHaveBeenCalledWith(
6662
'User db-user@test.com permission on Repo https://github.com/finos/git-proxy.git : true',
6763
);
6864
});
@@ -81,7 +77,7 @@ describe('checkUserPushPermission', () => {
8177
`Your push has been blocked (db-user@test.com is not allowed to push on repo https://github.com/finos/git-proxy.git)`,
8278
);
8379
expect(result.steps[0].errorMessage).toContain('Your push has been blocked');
84-
expect(consoleLogSpy).toHaveBeenLastCalledWith('User not allowed to Push');
80+
expect(stepLogSpy).toHaveBeenCalledWith('User not allowed to Push');
8581
});
8682

8783
it('should reject push when no user found for git account', async () => {
@@ -110,7 +106,7 @@ describe('checkUserPushPermission', () => {
110106
expect(stepLogSpy).toHaveBeenLastCalledWith(
111107
'Your push has been blocked (there are multiple users with email db-user@test.com)',
112108
);
113-
expect(consoleErrorSpy).toHaveBeenLastCalledWith(
109+
expect(stepLogSpy).toHaveBeenCalledWith(
114110
'Multiple users found with email address db-user@test.com, ending',
115111
);
116112
});

0 commit comments

Comments
 (0)