Skip to content

Fix dead-code OR expression in permission-denied assertion#443

Open
swseverance wants to merge 1 commit into
firebase:masterfrom
swseverance:fix/test-utils
Open

Fix dead-code OR expression in permission-denied assertion#443
swseverance wants to merge 1 commit into
firebase:masterfrom
swseverance:fix/test-utils

Conversation

@swseverance
Copy link
Copy Markdown

'permission-denied' || 'PERMISSION_DENIED' always evaluates to the first string due to JS short-circuit; drop the unreachable alternative so the assertion matches only the actual error code.

`'permission-denied' || 'PERMISSION_DENIED'` always evaluates to
the first string due to JS short-circuit; drop the unreachable
alternative so the assertion matches only the actual error code.
Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request simplifies the permission-denied error code checks in test utility files by removing a logical OR operation that was previously ineffective. The reviewer suggests that if the original intent was to support multiple error code formats across different environments, an array-based check using toContain should be implemented instead of a single string comparison.

export async function expectFirestorePermissionDenied(promise: Promise<any>) {
const errorResult = await assertFails(promise);
expect(errorResult.code).toBe('permission-denied' || 'PERMISSION_DENIED');
expect(errorResult.code).toBe('permission-denied');
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

The original code 'permission-denied' || 'PERMISSION_DENIED' was a logical error in JavaScript/TypeScript that always evaluated to the first string. While removing the dead code is an improvement, if the intention was to support both possible error codes (e.g., to handle variations across different SDK versions or environments), you should use an array check with toContain instead of a single string comparison.

Suggested change
expect(errorResult.code).toBe('permission-denied');
expect(['permission-denied', 'PERMISSION_DENIED']).toContain(errorResult.code);

export async function expectFirestorePermissionDenied(promise: Promise<any>) {
const errorResult = await assertFails(promise);
expect(errorResult.code).toBe('permission-denied' || 'PERMISSION_DENIED');
expect(errorResult.code).toBe('permission-denied');
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

The original code 'permission-denied' || 'PERMISSION_DENIED' was a logical error in JavaScript/TypeScript that always evaluated to the first string. While removing the dead code is an improvement, if the intention was to support both possible error codes (e.g., to handle variations across different SDK versions or environments), you should use an array check with toContain instead of a single string comparison.

Suggested change
expect(errorResult.code).toBe('permission-denied');
expect(['permission-denied', 'PERMISSION_DENIED']).toContain(errorResult.code);

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