Skip to content

Commit

Permalink
add unit test for fetchOverriddenUserWithPerms
Browse files Browse the repository at this point in the history
  • Loading branch information
aidynoJ committed Feb 20, 2025
1 parent b9f2b23 commit b5a3f82
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/loginServices.js
Original file line number Diff line number Diff line change
Expand Up @@ -922,7 +922,7 @@ function fetchUserWithPerms(okapiUrl, tenant, token, rtrIgnore = false) {
* @returns {Promise} Promise resolving to the response-body (JSON) of the request
*/

function fetchOverriddenUserWithPerms(okapiUrl, tenant, token, rtrIgnore = false) {
export function fetchOverriddenUserWithPerms(okapiUrl, tenant, token, rtrIgnore = false) {
const usersPath = okapi.authnUrl ? 'users-keycloak' : 'bl-users';
return fetch(
`${okapiUrl}/${usersPath}/_self?expandPermissions=true&fullPermissions=true&overrideUser=true`,
Expand Down
25 changes: 24 additions & 1 deletion src/loginServices.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ import {
validateUser,
IS_LOGGING_OUT,
SESSION_NAME, getStoredTenant,
requestLogin, requestUserWithPerms,
requestLogin,
requestUserWithPerms,
fetchOverriddenUserWithPerms,
} from './loginServices';

import {
Expand Down Expand Up @@ -800,4 +802,25 @@ describe('unauthorizedPath functions', () => {
});
});
});

describe('fetchOverriddenUserWithPerms', () => {
afterEach(() => {
mockFetchCleanUp();
});
it('should call the self endpoint with override query string parameter', async () => {
mockFetchSuccess({});

await fetchOverriddenUserWithPerms('http://okapi-url', 'test-tenant', 'token');

expect(global.fetch).toHaveBeenCalledWith('http://okapi-url/users-keycloak/_self?expandPermissions=true&fullPermissions=true&overrideUser=true',
{
headers: expect.objectContaining({
'X-Okapi-Tenant': 'test-tenant',
'X-Okapi-Token': 'token',
'Content-Type': 'application/json',
}),
'rtrIgnore': false
});
});
});
});

0 comments on commit b5a3f82

Please sign in to comment.