Skip to content

Fix for wallet-admin switch for admin vs. engagement approver#149

Merged
jmgasper merged 1 commit into
masterfrom
dev
Mar 26, 2026
Merged

Fix for wallet-admin switch for admin vs. engagement approver#149
jmgasper merged 1 commit into
masterfrom
dev

Conversation

@jmgasper

Copy link
Copy Markdown
Collaborator

No description provided.

const paymentAdminVerifyAccess = jest.fn().mockResolvedValue(undefined);
const engagementApproverVerifyAccess = jest
.fn()
.mockRejectedValue(new Error('should not be called'));

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[💡 readability]
Using mockRejectedValue with an error message like 'should not be called' is a bit misleading. Consider using a more descriptive message or a different approach to ensure clarity in test failures.


private normalizeRoles(roles: string[] = []): Set<string> {
return new Set(
(roles || []).map((role) => role?.trim().toLowerCase()).filter(Boolean),

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[⚠️ maintainability]
The use of role?.trim().toLowerCase() is repeated in multiple places. Consider extracting this logic into a helper function to improve maintainability and reduce duplication.

normalizedRoles: Set<string>,
): boolean {
return (
providerRole === Role.EngagementPaymentApprover.trim().toLowerCase() &&

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[❗❗ correctness]
Ensure that Role.EngagementPaymentApprover and Role.PaymentAdmin are always defined and not null or undefined to avoid potential runtime errors.

}

async verifyAccess(resourceId: string, userId: string, roles: string[] = []) {
const normalizedRoles = this.normalizeRoles(roles);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[⚠️ correctness]
The normalizeRoles function is called but its implementation is not shown in the diff. Ensure that it correctly normalizes roles to prevent potential mismatches or errors in access verification.

const normalizedRole = r?.trim().toLowerCase();
if (
!normalizedRole ||
this.shouldSkipProvider(normalizedRole, normalizedRoles)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[❗❗ correctness]
The shouldSkipProvider function is used to determine if a provider should be skipped. Ensure that this function is well-tested to avoid inadvertently skipping necessary providers, which could lead to incorrect access control.

@jmgasper
jmgasper merged commit edc65e4 into master Mar 26, 2026
5 of 7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant