Skip to content

Commit

Permalink
BC-6453 - rename functions
Browse files Browse the repository at this point in the history
- `checkPermissionByReferences` to `checkPermissionsByReference`
- `hasPermissionByReferences` to `hasPermissionsByReference`
  • Loading branch information
bergatco committed Jun 12, 2024
1 parent 2a95f62 commit eacdd8b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ describe(AuthorizationClientAdapter.name, () => {
expect(service).toBeDefined();
});

describe('checkPermissionByReferences', () => {
describe('checkPermissionsByReference', () => {
describe('when authorizationReferenceControllerAuthorizeByReference resolves successful', () => {
const setup = (props: { isAuthorized: boolean }) => {
const params = {
Expand Down Expand Up @@ -84,7 +84,7 @@ describe(AuthorizationClientAdapter.name, () => {

const expectedOptions = { headers: { authorization: `Bearer ${jwtToken}` } };

await service.checkPermissionByReferences(params);
await service.checkPermissionsByReference(params);

expect(authorizationApi.authorizationReferenceControllerAuthorizeByReference).toHaveBeenCalledWith(
params,
Expand All @@ -96,7 +96,7 @@ describe(AuthorizationClientAdapter.name, () => {
it('should resolve', async () => {
const { params } = setup({ isAuthorized: true });

await expect(service.checkPermissionByReferences(params)).resolves.toBeUndefined();
await expect(service.checkPermissionsByReference(params)).resolves.toBeUndefined();
});
});

Expand All @@ -106,7 +106,7 @@ describe(AuthorizationClientAdapter.name, () => {

const expectedError = new AuthorizationForbiddenLoggableException(params);

await expect(service.checkPermissionByReferences(params)).rejects.toThrowError(expectedError);
await expect(service.checkPermissionsByReference(params)).rejects.toThrowError(expectedError);
});
});
});
Expand All @@ -133,12 +133,12 @@ describe(AuthorizationClientAdapter.name, () => {

const expectedError = new AuthorizationErrorLoggableException(error, params);

await expect(service.checkPermissionByReferences(params)).rejects.toThrowError(expectedError);
await expect(service.checkPermissionsByReference(params)).rejects.toThrowError(expectedError);
});
});
});

describe('hasPermissionByReferences', () => {
describe('hasPermissionsByReference', () => {
describe('when authorizationReferenceControllerAuthorizeByReference resolves successful', () => {
const setup = () => {
const params = {
Expand Down Expand Up @@ -166,7 +166,7 @@ describe(AuthorizationClientAdapter.name, () => {

const expectedOptions = { headers: { authorization: `Bearer ${jwtToken}` } };

await service.hasPermissionByReferences(params);
await service.hasPermissionsByReference(params);

expect(authorizationApi.authorizationReferenceControllerAuthorizeByReference).toHaveBeenCalledWith(
params,
Expand All @@ -177,7 +177,7 @@ describe(AuthorizationClientAdapter.name, () => {
it('should return isAuthorized', async () => {
const { params, response } = setup();

const result = await service.hasPermissionByReferences(params);
const result = await service.hasPermissionsByReference(params);

expect(result).toEqual(response.data.isAuthorized);
});
Expand Down Expand Up @@ -217,7 +217,7 @@ describe(AuthorizationClientAdapter.name, () => {

const expectedOptions = { headers: { authorization: `Bearer ${jwtToken}` } };

await adapter.hasPermissionByReferences(params);
await adapter.hasPermissionsByReference(params);

expect(authorizationApi.authorizationReferenceControllerAuthorizeByReference).toHaveBeenCalledWith(
params,
Expand Down Expand Up @@ -260,7 +260,7 @@ describe(AuthorizationClientAdapter.name, () => {

const expectedOptions = { headers: { authorization: `Bearer ${jwtToken}` } };

await adapter.hasPermissionByReferences(params);
await adapter.hasPermissionsByReference(params);

expect(authorizationApi.authorizationReferenceControllerAuthorizeByReference).toHaveBeenCalledWith(
params,
Expand Down Expand Up @@ -291,7 +291,7 @@ describe(AuthorizationClientAdapter.name, () => {
it('should throw an UnauthorizedException', async () => {
const { params, adapter } = setup();

await expect(adapter.hasPermissionByReferences(params)).rejects.toThrowError(UnauthorizedException);
await expect(adapter.hasPermissionsByReference(params)).rejects.toThrowError(UnauthorizedException);
});
});

Expand All @@ -317,7 +317,7 @@ describe(AuthorizationClientAdapter.name, () => {

const expectedError = new AuthorizationErrorLoggableException(error, params);

await expect(service.hasPermissionByReferences(params)).rejects.toThrowError(expectedError);
await expect(service.hasPermissionsByReference(params)).rejects.toThrowError(expectedError);
});
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ import { AuthorizationErrorLoggableException, AuthorizationForbiddenLoggableExce
export class AuthorizationClientAdapter {
constructor(private readonly authorizationApi: AuthorizationApi, @Inject(REQUEST) private request: Request) {}

public async checkPermissionByReferences(params: AuthorizationBodyParams): Promise<void> {
const hasPermission = await this.hasPermissionByReferences(params);
public async checkPermissionsByReference(params: AuthorizationBodyParams): Promise<void> {
const hasPermission = await this.hasPermissionsByReference(params);
if (!hasPermission) {
throw new AuthorizationForbiddenLoggableException(params);
}
}

public async hasPermissionByReferences(params: AuthorizationBodyParams): Promise<boolean> {
public async hasPermissionsByReference(params: AuthorizationBodyParams): Promise<boolean> {
const jwt = this.getJWT();

try {
Expand Down

0 comments on commit eacdd8b

Please sign in to comment.