Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(api-client): 20565 Implement robust authentication and error handling, improve test coverage #954

Merged
merged 40 commits into from
Feb 6, 2025

Conversation

vkozio
Copy link
Contributor

@vkozio vkozio commented Jan 8, 2025

https://kontur.fibery.io/Tasks/Task/Improve-coverage-for-auth-and-api-clients-20565

Summary by CodeRabbit

  • New Features
    • Enhanced authentication flows providing finer control over session management and token refresh for improved reliability.
  • Bug Fixes
    • Improved error handling for API and network issues, resulting in more consistent and meaningful responses.
  • Refactor
    • Streamlined API request configurations and retry logic for enhanced stability and performance.
  • Documentation
    • Expanded and reorganized client usage and error reporting guides for greater transparency and clarity.

Copy link
Contributor

coderabbitai bot commented Jan 8, 2025

Note

Reviews paused

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Walkthrough

The pull request introduces widespread refactoring across tests, factories, API clients, and feature modules. Changes include the removal of boolean flags in API calls in favor of structured authentication settings (via an authRequirement property), improved error handling, and dynamic token generation based on current timestamps. Documentation, configuration files, and test suites (including retry and error handling tests) have been updated to reflect these changes. Minor modifications to import statements and file ignore patterns are also included.

Changes

File(s) Change Summary
src/core/api_client/tests/*.ts, src/utils/atoms/createStateMap.test.tsx Restructured test suites: enhanced error handling, reorganized authorization tests, updated timing and state management, and added new mocks (e.g. for wait and URL replacement).
src/core/api_client/tests/factories/auth.factory.ts, token.factory.ts, OidcSimpleClient.test.ts Updated token and authentication factories: introduced TokenConfig interface, new token generation methods, and enhanced OIDC client tests with improved state synchronization and error scenarios.
src/core/api_client/apiClient.ts, errors.ts, types.ts, utils.ts, readme.md Refactored API client internals: replaced boolean auth flags with an authRequirement property; added AUTH_REQUIREMENT property; improved error parsing, messaging, and documentation; updated type definitions.
src/core/api/assets.ts, boundaries.ts, features.ts, insights.ts, layers.ts, mcda.ts, search.ts, subscription.ts, users.ts Updated API endpoint calls: removed extraneous boolean parameters and replaced them with configuration objects explicitly defining auth requirements and signal handling.
src/features/* (e.g., create_layer, advanced_analytics_panel, bivariate_color_manager, event_episodes, events_list, layers_in_area, live_sensor, reports) Modified API calls in feature modules: transitioned from boolean flags to explicit authRequirement settings; adjusted request configurations and maintained existing error handling flows.
src/core/api_client/readme.md, src/core/auth/README.md, src/core/auth/RFC.md, src/core/auth/constants.ts, src/core/config/loaders/appConfigLoader.ts, src/core/metrics/app-metrics.ts, src/core/resources/*, vite.config.ts Expanded and restructured documentation; added new authentication constants and event types; updated configuration and build setups (including Vite plugins and import adjustments).
.cursorignore Revised ignored file patterns: removed fixture/test-related patterns and added directories such as dist/, node_modules/, server/, and others.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant ApiClient
    participant TokenStore
    participant AuthServer

    Client->>ApiClient: API request (with authRequirement)
    ApiClient->>TokenStore: Check token validity
    alt Valid Token
        TokenStore-->>ApiClient: Return token
        ApiClient->>AuthServer: Forward request with token
        AuthServer-->>ApiClient: Return response
    else Missing/Invalid Token (MUST)
        ApiClient-->>Client: Return authentication error
    else Missing Token (OPTIONAL)
        ApiClient->>AuthServer: Forward request without token
        AuthServer-->>ApiClient: Return response (with warning)
    end
    ApiClient-->>Client: Return API response
Loading

Poem

I'm a tiny rabbit with a heart full of cheer,
Hopping through refactors as the changes appear.
Tokens and tests now dance in a neat, structured line,
With errors tamed and mocks in a rhyme.
In this code garden, every branch is set right—
A bunny’s delight in a world coded bright! 🐇✨

Tip

🌐 Web search-backed reviews and chat
  • We have enabled web search-based reviews and chat for all users. This feature allows CodeRabbit to access the latest documentation and information on the web.
  • You can disable this feature by setting web_search: false in the knowledge_base settings.
  • Please share any feedback in the Discord discussion.

📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 2b6b38f and 76035a4.

📒 Files selected for processing (55)
  • .cursorignore (2 hunks)
  • src/core/api/assets.ts (1 hunks)
  • src/core/api/boundaries.ts (1 hunks)
  • src/core/api/features.ts (1 hunks)
  • src/core/api/insights.ts (2 hunks)
  • src/core/api/layers.ts (3 hunks)
  • src/core/api/mcda.ts (1 hunks)
  • src/core/api/search.ts (1 hunks)
  • src/core/api/subscription.ts (2 hunks)
  • src/core/api/users.ts (1 hunks)
  • src/core/api_client/apiClient.ts (7 hunks)
  • src/core/api_client/errors.ts (3 hunks)
  • src/core/api_client/readme.md (1 hunks)
  • src/core/api_client/tests/README.md (1 hunks)
  • src/core/api_client/tests/_clientTestsContext.ts (1 hunks)
  • src/core/api_client/tests/apiClient.test.ts (3 hunks)
  • src/core/api_client/tests/authorization.test.ts (1 hunks)
  • src/core/api_client/tests/errorsHandling.test.ts (11 hunks)
  • src/core/api_client/tests/eventHandling.test.ts (1 hunks)
  • src/core/api_client/tests/factories/auth.factory.ts (3 hunks)
  • src/core/api_client/tests/factories/mock.factory.ts (6 hunks)
  • src/core/api_client/tests/factories/token.factory.ts (1 hunks)
  • src/core/api_client/tests/httpHandling.test.ts (1 hunks)
  • src/core/api_client/tests/mocks/replaceUrlWithProxy.mock.ts (1 hunks)
  • src/core/api_client/tests/mocks/waitMock.ts (1 hunks)
  • src/core/api_client/tests/retryBehavior.test.ts (5 hunks)
  • src/core/api_client/tests/types.ts (1 hunks)
  • src/core/api_client/tests/urlHandling.test.ts (1 hunks)
  • src/core/api_client/types.ts (2 hunks)
  • src/core/api_client/utils.ts (1 hunks)
  • src/core/auth/OidcSimpleClient.test.ts (1 hunks)
  • src/core/auth/OidcSimpleClient.ts (5 hunks)
  • src/core/auth/README.md (1 hunks)
  • src/core/auth/RFC.md (1 hunks)
  • src/core/auth/constants.ts (1 hunks)
  • src/core/config/loaders/appConfigLoader.ts (1 hunks)
  • src/core/metrics/app-metrics.ts (1 hunks)
  • src/core/resources/bivariateStatisticsResource/index.ts (1 hunks)
  • src/core/resources/eventFeedsResource.ts (1 hunks)
  • src/core/shared_state/currentEventResource.ts (0 hunks)
  • src/features/advanced_analytics_panel/atoms/advancedAnalyticsWorldResource.ts (0 hunks)
  • src/features/bivariate_color_manager/atoms/bivariateColorManagerResource.ts (1 hunks)
  • src/features/create_layer/atoms/currentEditedLayerFeatures.ts (1 hunks)
  • src/features/create_layer/atoms/editableLayerController.ts (2 hunks)
  • src/features/create_layer/atoms/editableLayersDetailsResource.ts (1 hunks)
  • src/features/create_layer/atoms/editableLayersListResource.ts (1 hunks)
  • src/features/event_episodes/atoms/episodesResource.ts (1 hunks)
  • src/features/events_list/atoms/eventListResource.ts (2 hunks)
  • src/features/layers_in_area/atoms/areaLayersDetailsResource/areaLayersDetailsResourceAtom.ts (1 hunks)
  • src/features/live_sensor/SensorsSnapshotsSender.ts (1 hunks)
  • src/features/reports/atoms/reportResource.ts (1 hunks)
  • src/features/reports/atoms/reportsAtom.ts (2 hunks)
  • src/utils/atoms/createStateMap.test.tsx (1 hunks)
  • src/utils/axios/replaceUrlWithProxy.ts (1 hunks)
  • vite.config.ts (3 hunks)
✨ Finishing Touches
  • 📝 Generate Docstrings (Beta)

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@vkozio vkozio requested a review from a team January 8, 2025 11:54
@vkozio
Copy link
Contributor Author

vkozio commented Jan 8, 2025

@coderabbitai ignore

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 20

📜 Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 2b6b38f and 11c4677.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (27)
  • .eslintignore (0 hunks)
  • .eslintrc.identical.keys.cjs (0 hunks)
  • .eslintrc.json (0 hunks)
  • .gitignore (1 hunks)
  • eslint.config.mjs (1 hunks)
  • eslintrc.identical.keys.mjs (1 hunks)
  • package.json (5 hunks)
  • src/core/api_client/apiClient.ts (1 hunks)
  • src/core/api_client/apiClientError.ts (1 hunks)
  • src/core/api_client/tests/authorization.test.ts (1 hunks)
  • src/core/api_client/tests/errorHandling.test.ts (1 hunks)
  • src/core/api_client/tests/eventHandling.test.ts (1 hunks)
  • src/core/api_client/tests/factories/auth.factory.ts (3 hunks)
  • src/core/api_client/tests/factories/mock.factory.ts (4 hunks)
  • src/core/api_client/tests/factories/token.factory.ts (1 hunks)
  • src/core/api_client/tests/httpHandling.test.ts (1 hunks)
  • src/core/api_client/tests/mocks/replaceUrlWithProxy.mock.ts (1 hunks)
  • src/core/api_client/tests/urlHandling.test.ts (1 hunks)
  • src/core/api_client/types.ts (0 hunks)
  • src/core/api_client/utils.ts (0 hunks)
  • src/core/auth/OidcSimpleClient.test.ts (1 hunks)
  • src/core/auth/OidcSimpleClient.ts (6 hunks)
  • src/core/metrics/app-metrics.ts (0 hunks)
  • src/utils/atoms/createStateMap.test.tsx (1 hunks)
  • src/utils/axios/replaceUrlWithProxy.ts (1 hunks)
  • src/utils/storage/index.ts (1 hunks)
  • vite.config.ts (1 hunks)
💤 Files with no reviewable changes (6)
  • .eslintrc.identical.keys.cjs
  • src/core/metrics/app-metrics.ts
  • .eslintignore
  • src/core/api_client/types.ts
  • .eslintrc.json
  • src/core/api_client/utils.ts
🧰 Additional context used
🪛 Biome (1.9.4)
src/core/api_client/tests/eventHandling.test.ts

[error] 130-130: Forbidden non-null assertion.

Unsafe fix: Replace with optional chain operator ?. This operator includes runtime checks, so it is safer than the compile-only non-null assertion operator

(lint/style/noNonNullAssertion)

src/utils/atoms/createStateMap.test.tsx

[error] 57-63: Avoid using unnecessary Fragment.

A fragment is redundant if it contains only one child, or if it is the child of a html element, and is not a keyed fragment.
Unsafe fix: Remove the Fragment

(lint/complexity/noUselessFragments)

src/core/api_client/tests/factories/token.factory.ts

[error] 17-17: Forbidden non-null assertion.

(lint/style/noNonNullAssertion)


[error] 18-18: Forbidden non-null assertion.

(lint/style/noNonNullAssertion)


[error] 19-19: Using this in a static context can be confusing.

this refers to the class.
Unsafe fix: Use the class name instead.

(lint/complexity/noThisInStatic)


[error] 24-24: Using this in a static context can be confusing.

this refers to the class.
Unsafe fix: Use the class name instead.

(lint/complexity/noThisInStatic)


[error] 32-32: Using this in a static context can be confusing.

this refers to the class.
Unsafe fix: Use the class name instead.

(lint/complexity/noThisInStatic)

src/core/api_client/tests/factories/mock.factory.ts

[error] 22-22: Using this in a static context can be confusing.

this refers to the class.
Unsafe fix: Use the class name instead.

(lint/complexity/noThisInStatic)


[error] 50-50: Using this in a static context can be confusing.

this refers to the class.
Unsafe fix: Use the class name instead.

(lint/complexity/noThisInStatic)


[error] 246-246: This type annotation is trivially inferred from its initialization.

Safe fix: Remove the type annotation.

(lint/style/noInferrableTypes)


[error] 252-252: This type annotation is trivially inferred from its initialization.

Safe fix: Remove the type annotation.

(lint/style/noInferrableTypes)

src/core/api_client/tests/factories/auth.factory.ts

[error] 53-53: Using this in a static context can be confusing.

this refers to the class.
Unsafe fix: Use the class name instead.

(lint/complexity/noThisInStatic)


[error] 75-75: Using this in a static context can be confusing.

this refers to the class.
Unsafe fix: Use the class name instead.

(lint/complexity/noThisInStatic)

🔇 Additional comments (29)
src/core/api_client/tests/authorization.test.ts (4)

5-6: Import statements are appropriate.

The imported modules fetchMock, ApiClientError, and getApiErrorKind are correctly included for the test setup.


9-10: Factory imports are correctly added.

The MockFactory and AuthFactory are appropriately imported for mocking and authentication purposes in the tests.


22-57: Comprehensive test for password grant authentication.

The test case for handling password grant authentication is well-structured. It correctly resets mocks, sets up successful authentication, and verifies both the user's login status and the stored token. Additionally, it checks the token request format to ensure the correct parameters are sent.


60-117: Effective error handling tests cover multiple scenarios.

The test for handling authentication failures efficiently covers various error cases, including unauthorized access, bad requests, and network errors. By iterating over the errorCases array, it ensures that each scenario is tested, and the expected error kinds are correctly asserted.

src/core/api_client/tests/mocks/replaceUrlWithProxy.mock.ts (1)

1-7: Mock function replaceUrlWithProxyMock is correctly implemented.

The mock effectively replaces the real replaceUrlWithProxy function, ensuring that URL handling can be tested without invoking the actual implementation, which is essential for isolating test cases.

src/core/api_client/apiClientError.ts (2)

16-17: Great improvement in type safety and error checking!

The change from any to unknown and using instanceof for type checking is more type-safe and reliable.


20-21: Consistent error handling improvements across helper functions.

The changes maintain consistency in type safety and error handling patterns across all utility functions.

Also applies to: 24-25

src/core/api_client/tests/factories/token.factory.ts (2)

8-11: Good improvement using dynamic timestamps!

Using current time-based calculations makes the token generation more realistic and maintainable.


23-26: Consistent time-based token generation.

The implementation maintains consistency in how expiration times are calculated across different token types.

Also applies to: 31-35

🧰 Tools
🪛 Biome (1.9.4)

[error] 24-24: Using this in a static context can be confusing.

this refers to the class.
Unsafe fix: Use the class name instead.

(lint/complexity/noThisInStatic)

src/core/api_client/tests/factories/auth.factory.ts (3)

12-17: Well-designed TokenConfig interface.

The interface provides a clean and focused set of properties for token configuration.


45-51: Good token creation implementation.

The createToken method handles defaults well and correctly implements the expired token scenario.


53-58: Comprehensive mock implementations for different scenarios.

The mock methods cover success, error, and logout scenarios, providing good test coverage.

Also applies to: 60-65, 67-72

🧰 Tools
🪛 Biome (1.9.4)

[error] 53-53: Using this in a static context can be confusing.

this refers to the class.
Unsafe fix: Use the class name instead.

(lint/complexity/noThisInStatic)

src/core/api_client/apiClient.ts (1)

154-154: Verify token refresh behavior.

The removal of the token assignment simplifies the code, but we should ensure that:

  1. Token refresh still works correctly
  2. No race conditions occur during concurrent requests
  3. Error handling remains consistent

Run this script to check for potential race conditions in token refresh:

✅ Verification successful

Token refresh implementation verified as safe and correct.

The removed token assignment was redundant as the getAccessToken() call already handles token refresh with proper concurrency protection. The implementation in OidcSimpleClient prevents race conditions during concurrent requests, and error cases are properly handled.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for proper handling of concurrent token refresh
# Look for other token refresh implementations that might need similar updates

# Search for token refresh patterns
ast-grep --pattern 'await $_.getAccessToken()'

# Search for token usage patterns
rg -A 5 'getAccessToken'

Length of output: 4799

src/core/api_client/tests/eventHandling.test.ts (3)

15-74: LGTM! Well-structured event listener tests.

The test suite thoroughly covers error event listener functionality, including registration, triggering, multiple listeners, and unsubscription. The assertions are comprehensive and verify both the error events and the error types.


113-136: LGTM! Comprehensive pool management tests.

The test effectively verifies concurrent request tracking and pool updates. Good use of poolUpdates array to track state changes.

🧰 Tools
🪛 Biome (1.9.4)

[error] 130-130: Forbidden non-null assertion.

Unsafe fix: Replace with optional chain operator ?. This operator includes runtime checks, so it is safer than the compile-only non-null assertion operator

(lint/style/noNonNullAssertion)


158-194: LGTM! Thorough error handling tests.

The tests effectively verify pool cleanup for both regular and network errors. Good use of MockFactory for simulating different error scenarios.

src/core/api_client/tests/factories/mock.factory.ts (2)

21-30: LGTM! Improved token endpoint mocking.

Good improvement using a function for dynamic response generation and tracking call count. This provides more flexibility and better tracking of mock usage.

🧰 Tools
🪛 Biome (1.9.4)

[error] 22-22: Using this in a static context can be confusing.

this refers to the class.
Unsafe fix: Use the class name instead.

(lint/complexity/noThisInStatic)


48-53: LGTM! Consistent pattern for logout endpoint.

The logout endpoint mock follows the same pattern as the token endpoint, maintaining consistency in the codebase.

🧰 Tools
🪛 Biome (1.9.4)

[error] 50-50: Using this in a static context can be confusing.

this refers to the class.
Unsafe fix: Use the class name instead.

(lint/complexity/noThisInStatic)

src/core/auth/OidcSimpleClient.test.ts (3)

27-67: LGTM! Thorough token management tests.

Good coverage of both successful and error scenarios in token management. The tests effectively verify token storage, retrieval, and validation.


70-178: LGTM! Comprehensive token refresh tests.

Excellent coverage of concurrent refresh scenarios and error handling. Good use of mocks to simulate various token states and server responses.


477-662: LGTM! Thorough token refresh flow tests.

Excellent coverage of the token refresh flow, including:

  • Preemptive refresh
  • Network errors
  • Concurrent refresh requests
  • Various token states
eslint.config.mjs (2)

145-145: Ensure the correct path for localesPath in i18n rules

The localesPath specified in the i18n-checker/json-key-exists rule on line 144 may need to point to a specific JSON file rather than a directory.

Please verify that localesPath is correctly configured. If a specific JSON file is required, adjust the path accordingly.


53-54: Verify the usage of fixupPluginRules with eslint-plugin-react-hooks

The use of fixupPluginRules on line 53 may not be necessary for eslint-plugin-react-hooks. This function is typically used to adjust plugin rules for compatibility, but eslint-plugin-react-hooks should work without it.

Please verify if fixupPluginRules is required here. If not, consider simplifying the plugin configuration:

-          'react-hooks': fixupPluginRules(reactHooks),
+          'react-hooks': reactHooks,

Run the following script to check if any errors occur without fixupPluginRules:

eslintrc.identical.keys.mjs (2)

17-17: Ensure filePath in i18n-json/identical-keys rule is correct

The filePath on line 17 points to common.json. Confirm that this is the intended reference file for key validation across all locales.

Please verify that common.json is the correct base file. If a different file should be used, update the filePath accordingly.


9-12: Confirm the processor configuration for .json files

The processor configuration on lines 9-12 spreads the .json processor from eslint-plugin-i18n-json. Ensure that this setup correctly processes JSON files.

Please verify that the processor is correctly applied. If issues arise, consider adjusting the configuration as follows:

-      processor: {
-        meta: { name: '.json' },
-        ...i18nJsonPlugin.processors['.json'],
-      },
+      processor: i18nJsonPlugin.processors['.json'],

Run the following script to verify the ESLint configuration:

✅ Verification successful

The processor configuration is correctly implemented

The current implementation that spreads the .json processor and adds metadata is valid. While no translation files exist yet, the configuration is properly set up for processing JSON files when they are added. The suggested change to use direct assignment offers no advantages over the current implementation.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify ESLint processor configuration for JSON files

# Test ESLint with the current configuration
npx eslint 'src/core/localization/translations/**/*.json' --config eslintrc.identical.keys.mjs

Length of output: 190


Script:

#!/bin/bash
# Check the plugin import and processor configuration
echo "=== Checking plugin import ==="
rg "import.*eslint-plugin-i18n-json" -A 2

echo -e "\n=== Looking for similar processor configurations ==="
rg "processor.*json" -A 3

echo -e "\n=== Finding JSON files in translations directory ==="
fd -e json . src/core/localization/translations

Length of output: 1018


Script:

#!/bin/bash
# Check for localization or translation directories
echo "=== Finding all JSON files in the project ==="
fd -e json

echo -e "\n=== Looking for translation or localization directories ==="
fd -t d "translations\|localization\|locale"

Length of output: 531

.gitignore (1)

21-21: LGTM! More maintainable ignore patterns.

The consolidation of specific patterns into more general ones (.env.*.local, *.log, configs/*.local.*) improves maintainability while maintaining the same functionality.

Also applies to: 30-30, 35-35

package.json (3)

24-24: LGTM! New coverage script for improved reporting.

The new coverage:lcov script with specific coverage reporting options will help with test coverage tracking and reporting.


126-126: Review the impact of dependency updates.

Several dependencies have been updated. Notable changes:

  • ESLint major version update (8.x → 9.x)
  • Testing-related packages updated
  • React ecosystem packages updated

Please ensure:

  1. The major ESLint version upgrade is compatible
  2. All tests pass with the updated dependencies

Also applies to: 128-128, 130-130, 140-140, 153-156, 160-160, 165-166, 172-172, 175-175, 178-178, 180-183, 187-187, 196-196


26-26: Verify the impact of ESLint configuration changes.

The changes to lint scripts and ESLint configuration might affect existing code. Please ensure:

  1. The new configuration doesn't introduce breaking changes
  2. The team is aware of any new linting rules

Also applies to: 28-28

✅ Verification successful

ESLint configuration changes are safe and well-structured

The changes to the lint scripts and ESLint configuration are using standard patterns and up-to-date dependencies. The setup includes proper TypeScript support, React-specific rules, and i18n validation. No breaking changes detected.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for potential linting issues with the new configuration

# Test: Run ESLint with the new configuration and check for errors
eslint --quiet src/**/*.{ts,tsx} > lint_results.txt || true
echo "Number of files with potential issues:"
wc -l lint_results.txt

Length of output: 462


Script:

#!/bin/bash
# Find ESLint config files
echo "=== ESLint Config Files ==="
fd -e json -e js -e yaml -e yml . -E node_modules | grep -i eslint

# Show content of ESLint configs if found
echo -e "\n=== ESLint Config Contents ==="
fd -e json -e js -e yaml -e yml . -E node_modules -x cat {} \; | grep -i eslint -A 10 -B 10

# Check package.json for ESLint-related entries
echo -e "\n=== Package.json ESLint Dependencies ==="
cat package.json | grep -i eslint -A 2 -B 2

Length of output: 29521

src/core/auth/OidcSimpleClient.ts Outdated Show resolved Hide resolved
src/core/auth/OidcSimpleClient.ts Outdated Show resolved Hide resolved
src/core/auth/OidcSimpleClient.ts Outdated Show resolved Hide resolved
src/utils/axios/replaceUrlWithProxy.ts Outdated Show resolved Hide resolved
eslint.config.mjs Outdated Show resolved Hide resolved
src/utils/atoms/createStateMap.test.tsx Show resolved Hide resolved
src/utils/atoms/createStateMap.test.tsx Show resolved Hide resolved
vite.config.ts Outdated Show resolved Hide resolved
src/utils/storage/index.ts Outdated Show resolved Hide resolved
Copy link
Contributor

coderabbitai bot commented Jan 8, 2025

✅ Actions performed

Reviews paused.

Copy link

github-actions bot commented Jan 8, 2025

Language To Recheck Fuzzy Untranslated Total
ar 3 24 101 128
de 2 24 101 127
es 3 24 101 128
id 2 24 101 127
ko 3 24 101 128
uk 0 7 8 15

@vkozio
Copy link
Contributor Author

vkozio commented Jan 8, 2025

@coderabbitai resolve

Copy link

github-actions bot commented Jan 8, 2025

Bundle size diff

Old size New size Diff
5.17 MB 5.17 MB 2.53 KB (0.05%)

Copy link
Contributor

coderabbitai bot commented Jan 8, 2025

✅ Actions performed

Comments resolved.

Copy link

codecov bot commented Jan 8, 2025

Codecov Report

Attention: Patch coverage is 67.37089% with 139 lines in your changes missing coverage. Please review.

Project coverage is 10.69%. Comparing base (2b6b38f) to head (76035a4).
Report is 14 commits behind head on main.

Files with missing lines Patch % Lines
src/core/auth/OidcSimpleClient.ts 81.67% 48 Missing ⚠️
src/utils/axios/replaceUrlWithProxy.ts 16.66% 15 Missing ⚠️
src/core/api/layers.ts 0.00% 9 Missing ⚠️
...ures/create_layer/atoms/editableLayerController.ts 0.00% 9 Missing ⚠️
src/core/api/insights.ts 0.00% 8 Missing ⚠️
src/core/api_client/apiClient.ts 86.95% 6 Missing ⚠️
src/core/api/features.ts 0.00% 4 Missing ⚠️
src/core/api/users.ts 0.00% 4 Missing ⚠️
src/core/config/loaders/appConfigLoader.ts 0.00% 4 Missing ⚠️
...s/create_layer/atoms/editableLayersListResource.ts 0.00% 4 Missing ⚠️
... and 16 more

❌ Your patch status has failed because the patch coverage (16.66%) is below the target coverage (30.00%). You can increase the patch coverage or adjust the target coverage.
❌ Your project status has failed because the head coverage (1.13%) is below the target coverage (15.00%). You can increase the head coverage or adjust the target coverage.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #954      +/-   ##
==========================================
+ Coverage   10.04%   10.69%   +0.65%     
==========================================
  Files         669      670       +1     
  Lines       29420    29610     +190     
  Branches     1236     1317      +81     
==========================================
+ Hits         2954     3168     +214     
+ Misses      25936    25911      -25     
- Partials      530      531       +1     
Components Coverage Δ
UI Components 0.26% <ø> (-0.01%) ⬇️
Core Logic 19.96% <74.93%> (+2.15%) ⬆️
Features 1.13% <0.00%> (-0.01%) ⬇️
Utilities 45.37% <16.66%> (-0.40%) ⬇️

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link

github-actions bot commented Jan 8, 2025

Preview environments for this PR:

These previews are automatically updated with each commit.

Note: After a new deployment, it may take a few minutes for the changes to propagate and for caches to update. During this time, you might experience temporary loading issues or see an older version of the app. If the app fails to load, please wait a few minutes and try again.

Copy link

codecov bot commented Jan 8, 2025

Bundle Report

Changes will increase total bundle size by 7.51kB (0.14%) ⬆️. This is within the configured threshold ✅

Detailed changes
Bundle name Size Change
konturio/disaster-ninja-fe-esm 5.42MB 7.51kB (0.14%) ⬆️

Affected Assets, Files, and Routes:

view changes for bundle: konturio/disaster-ninja-fe-esm

Assets Changed:

Asset Name Size Change Total Size Change (%)
assets/index-*.js -5 bytes 9.84kB -0.05%
assets/index-*.js 48 bytes 18.57kB 0.26%
assets/index-*.js 47 bytes 2.88kB 1.66%
assets/index-*.js -1 bytes 2.62kB -0.04%
assets/index-*.js 45 bytes 5.14kB 0.88%
assets/index-*.js 48 bytes 1.98kB 2.48%
assets/index-*.js 40 bytes 35.83kB 0.11%
assets/index-*.js 2.31kB 182.5kB 1.28%
assets/index-*.js 48 bytes 2.16kB 2.28%
assets/index-*.js 48 bytes 1.78kB 2.77%
assets/index-*.js 161 bytes 3.21kB 5.28% ⚠️
assets/index-*.js 85 bytes 8.33kB 1.03%
assets/index-*.js 50 bytes 37.36kB 0.13%
assets/index-*.js 48 bytes 10.3kB 0.47%
assets/index-*.js 48 bytes 1.52kB 3.26%
assets/index-*.js 103 bytes 138.28kB 0.07%
assets/index-*.js 483 bytes 5.05kB 10.57% ⚠️
assets/index-*.js -5 bytes 4.08kB -0.12%
assets/index-*.js 45 bytes 17.25kB 0.26%
assets/index-*.js 48 bytes 13.21kB 0.36%
assets/index-*.js 48 bytes 1.32kB 3.77%
assets/index-*.js 91 bytes 6.87kB 1.34%
assets/index-*.js 48 bytes 6.02kB 0.8%
assets/index-*.js 3 bytes 18.64kB 0.02%
assets/index-*.js -99 bytes 3.25kB -2.96%
assets/ToolbarIcon-*.js -790 bytes 176.57kB -0.45%
assets/Map-*.js -1.24kB 125.48kB -0.98%
assets/EditFeaturesOrLayerPanel-*.js 256 bytes 62.06kB 0.41%
assets/axisDTOtoAxis-*.js -1.87kB 42.69kB -4.19%
assets/App-*.js -3 bytes 27.59kB -0.01%
assets/Report-*.js 39 bytes 27.58kB 0.14%
assets/BivariateManager-*.js 44 bytes 20.31kB 0.22%
assets/index-*.css 103 bytes 2.59kB 4.15%
assets/index-*.css 487 bytes 2.48kB 24.39% ⚠️
assets/index-*.css 371 bytes 2.0kB 22.82% ⚠️
assets/Pricing-*.js 78 bytes 18.79kB 0.42%
assets/Map-*.css -288 bytes 16.21kB -1.75%
assets/Profile-*.js 280 bytes 14.87kB 1.92%
assets/PanelContent-*.js -3 bytes 6.33kB -0.05%
assets/PanelContent-*.js 48 bytes 1.73kB 2.85%
assets/PanelContent-*.js 53 bytes 2.94kB 1.84%
assets/BreadcrumbsPanel-*.js -32 bytes 4.55kB -0.7%
assets/ReferenceAreaInfo-*.js 1.64kB 3.15kB 108.33% ⚠️
assets/UserGeometryRenderer-*.js 5 bytes 2.88kB 0.17%
assets/PopupTooltipWrapper-*.js (New) 2.82kB 2.82kB 100.0% 🚀
assets/BivariateLegend-*.js 41 bytes 2.6kB 1.6%
assets/ConnectedMap-*.js 16 bytes 1.99kB 0.81%
assets/PopupTooltipTrigger-*.js (New) 1.87kB 1.87kB 100.0% 🚀
assets/eventFeeds-*.js -3 bytes 1.01kB -0.3%
assets/ReportsList.module-*.js 40 bytes 920 bytes 4.55%
assets/ReferenceAreaInfo-*.css 497 bytes 900 bytes 123.33% ⚠️
assets/createBivariateGraphQLQuery-*.js 42 bytes 828 bytes 5.34% ⚠️
assets/currentEventResource-*.js -3 bytes 704 bytes -0.42%
assets/insights-*.js -9 bytes 559 bytes -1.58%
assets/boundaries-*.js -146 bytes 530 bytes -21.6%
assets/boundaries-*.js (New) 239 bytes 239 bytes 100.0% 🚀
assets/PopupTooltipTrigger-*.css (New) 127 bytes 127 bytes 100.0% 🚀
assets/referenceArea-*.js (Deleted) -984 bytes 0 bytes -100.0% 🗑️

Files in assets/index-*.js:

  • ./src/core/api/layers.ts → Total Size: 1.41kB

  • ./src/core/api_client/errors.ts → Total Size: 2.78kB

  • ./src/core/api_client/types.ts → Total Size: 108 bytes

  • ./src/core/api_client/apiClient.ts → Total Size: 6.0kB

  • ./src/core/api_client/utils.ts → Total Size: 344 bytes

Files in assets/index-*.js:

  • ./src/core/api/assets.ts → Total Size: 257 bytes

Files in assets/Map-*.js:

  • ./src/core/api/mcda.ts → Total Size: 417 bytes

  • ./src/core/api/search.ts → Total Size: 668 bytes

Files in assets/Pricing-*.js:

  • ./src/core/api/subscription.ts → Total Size: 538 bytes

Files in assets/Profile-*.js:

  • ./src/core/api/users.ts → Total Size: 294 bytes

Files in assets/PopupTooltipWrapper-*.js:

  • ./src/core/api/features.ts → Total Size: 621 bytes

Files in assets/insights-*.js:

  • ./src/core/api/insights.ts → Total Size: 876 bytes

Files in assets/boundaries-*.js:

  • ./src/core/api/boundaries.ts → Total Size: 206 bytes

@vkozio
Copy link
Contributor Author

vkozio commented Jan 8, 2025

@coderabbitai summary

Copy link
Contributor

coderabbitai bot commented Jan 8, 2025

✅ Actions performed

Summary regeneration triggered.

Copy link
Contributor

@albaranau albaranau left a comment

Choose a reason for hiding this comment

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

It would be best to double check all the introduced api call changes.

src/core/resources/eventFeedsResource.ts Outdated Show resolved Hide resolved
src/core/auth/constants.ts Show resolved Hide resolved
src/core/auth/constants.ts Outdated Show resolved Hide resolved
src/core/api/insights.ts Outdated Show resolved Hide resolved
vkozio added 11 commits January 16, 2025 22:54
…ogic and improve consistency across API calls and tests
…uction; remove unused authentication response types
…ensure proper typing and chaining for wretch requests
…error handling scenarios in authorization tests
…cessary checks for AUTH_REQUIREMENT.NEVER; update tests to reflect new behavior for optional and mandatory authentication scenarios
…licit error messages; update MockApiErrorResponse type to make message optional and enhance mock factory for conditional message inclusion
…t.AUTH_REQUIREMENT in API calls for consistency and maintainability
Copy link
Contributor

@albaranau albaranau left a comment

Choose a reason for hiding this comment

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

Please create a task that reflects the changes in how ApiClient works and rename the PR according to that task.

Left couple comments too

src/core/api/insights.ts Outdated Show resolved Hide resolved
src/core/auth/README.md Outdated Show resolved Hide resolved
src/core/auth/README.md Outdated Show resolved Hide resolved
src/core/api_client/tests/apiClient.test.ts Show resolved Hide resolved
src/core/auth/README.md Outdated Show resolved Hide resolved
src/core/auth/README.md Outdated Show resolved Hide resolved
@vkozio vkozio changed the title fix(tests): 20565 improve coverage for auth and api clients feat(api-client): 20565 Implement robust authentication and error handling, improve test coverage Feb 5, 2025
@vkozio
Copy link
Contributor Author

vkozio commented Feb 5, 2025

@coderabbitai summary

Copy link
Contributor

coderabbitai bot commented Feb 5, 2025

✅ Actions performed

Summary regeneration triggered.

@vkozio vkozio requested a review from albaranau February 5, 2025 23:21
Copy link
Contributor

@albaranau albaranau left a comment

Choose a reason for hiding this comment

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

🙏

@vkozio vkozio merged commit a1d855c into main Feb 6, 2025
16 of 22 checks passed
@vkozio vkozio deleted the 20565-improve-coverage-for-auth-and-api-clients branch February 6, 2025 15:17
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.

2 participants