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

NOTICKET: correctly ensure entityCount is number #607

Merged
merged 2 commits into from
Nov 6, 2024

Conversation

rosado
Copy link
Collaborator

@rosado rosado commented Oct 31, 2024

What type of PR is this? (check all applicable)

  • Bug Fix

Description

A condition would always fail for entityCount = 0.

The clauses inserted into the query were used with an outer join, so this bug did not narrow down the result set. In fact the results would still contain the correct value of zero in the entity_count column.

Related Tickets & Documents

No ticket.

Added/updated tests?

We encourage you to keep the code coverage percentage at 80% and above.

  • Yes

Summary by CodeRabbit

  • Bug Fixes

    • Improved validation for entityCount in queries to ensure only integer values are accepted.
  • Tests

    • Expanded test coverage for the lpaOverviewQuery function to include additional datasets and validate outputs.

@rosado rosado added the bug Something isn't working label Oct 31, 2024
Copy link
Contributor

coderabbitai bot commented Oct 31, 2024

Walkthrough

The changes in this pull request focus on the lpaOverviewQuery function within the src/services/performanceDbApi.js file. The condition for validating entityCount has been updated to ensure only integer values are accepted. Additionally, the test suite for this function has been enhanced to include a new test case that verifies the function's handling of multiple datasets, including one with an entity count of zero. A note has been added indicating that the LpaOverview typedef needs updating.

Changes

File Change Summary
src/services/performanceDbApi.js Modified lpaOverviewQuery to validate entityCount as an integer. Noted need for LpaOverview typedef update.
test/unit/performanceDbApi.test.js Updated tests for lpaOverviewQuery to include a new dataset with entityCount: 0 and added assertions for output verification.

Possibly related PRs

  • fix: don't filter out issues with 'info' severity #590: The changes in this PR also modify the lpaOverviewQuery function in src/services/performanceDbApi.js, enhancing its logic for filtering issues based on severity, which is closely related to the changes made in the main PR regarding the validation of entityCount.

Suggested reviewers

  • GeorgeGoodall-GovUk

🐰 In the meadow, where bunnies play,
A change was made, hip-hip-hooray!
Now integers count, no more to stray,
With tests that cover, come what may.
Hops of joy for each new day! 🌼


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 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.

Copy link

github-actions bot commented Oct 31, 2024

Coverage Report

Status Category Percentage Covered / Total
🔵 Lines 62.81% 3705 / 5898
🔵 Statements 62.81% 3705 / 5898
🔵 Functions 64.65% 161 / 249
🔵 Branches 80.95% 442 / 546
File Coverage
File Stmts Branches Functions Lines Uncovered Lines
Changed Files
src/services/performanceDbApi.js 65.61% 92.59% 29.41% 65.61% 49-77, 114-116, 177-181, 202-204, 253-259, 270-273, 284-297, 306-322, 336-350, 364-381, 392-419, 423-427, 438-441
Generated in workflow #183 for commit 1acc733 by the Vitest Coverage Report Action

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: 0

🧹 Outside diff range and nitpick comments (2)
src/services/performanceDbApi.js (2)

109-109: Good fix for the entityCount validation!

The change from entityCount && entityCount >= 0 to Number.isInteger(entityCount) && entityCount >= 0 correctly fixes the issue where an entityCount of 0 would fail the condition. The use of Number.isInteger() also adds proper type validation.

For additional type safety, consider adding JSDoc type annotations for the entityCount parameter in the function signature.

Add this type annotation to the entityCounts array in the params object:

/**
 * @param {Object} params
 * @param {string[]} params.datasetsFilter
 * @param {Array<{dataset: string, resource: string, entityCount?: number}>} params.entityCounts
 */

Line range hint 41-44: Update the LpaOverview typedef as indicated

The comment indicates that the typedef needs updating. Consider adding entityCount-related properties to properly reflect the data structure.

Update the typedef to include:

/**
 * @typedef {object} Dataset
 * @property {'Not submitted' | 'Error' | 'Needs fixing' | 'Warning' | 'Live' } status
 * @property {string} endpoint
 * @property {number} issue_count
 * @property {number} entity_count
 * @property {?string} error
 */
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between fb34a92 and ab09244.

📒 Files selected for processing (2)
  • src/services/performanceDbApi.js (1 hunks)
  • test/unit/performanceDbApi.test.js (1 hunks)
🔇 Additional comments (3)
test/unit/performanceDbApi.test.js (2)

51-53: Test data properly validates zero entity count case

The addition of a test case with entityCount: 0 effectively validates the bug fix mentioned in the PR objectives, ensuring the query handles zero counts correctly.


58-59: Comprehensive test coverage with appropriate assertions

The additional assertions properly verify that both datasets are included in the query output, regardless of their entity count values.

Let's verify the test coverage for the related implementation:

✅ Verification successful

Test coverage is appropriate and correctly verifies dataset inclusion

The test correctly verifies that both datasets are included in the query output, regardless of their entity count values. Looking at the implementation in performanceDbApi.js, we can confirm:

  1. The lpaOverviewQuery function properly handles both datasets with zero and non-zero entity counts
  2. The test case covers both scenarios by using entityCount: 10 for dataset-three and entityCount: 0 for dataset-four
  3. The implementation ensures that datasets are included in the query via the entityCountsSelects array, which is correctly populated regardless of the entity count value
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify test coverage for entityCount handling
# Expected: Find the implementation of lpaOverviewQuery and its entityCount validation

# Search for the implementation
ast-grep --pattern 'export function lpaOverviewQuery($_) {
  $$$
}'

# Look for related tests
rg -l "entityCount.*[=><].*0" "test/"

Length of output: 107


Script:

#!/bin/bash
# Let's try a broader search to find the implementation and test files

# Search for files containing 'dataset-three' or 'dataset-four'
rg -l "dataset-(three|four)" .

# Search for performance-related query implementations
rg -l "lpaOverviewQuery|performanceDb" .

# Look for the test file content
cat test/unit/performanceDbApi.test.js

Length of output: 4593


Script:

#!/bin/bash
# Let's examine the implementation to verify the entityCount handling
cat src/services/performanceDbApi.js

Length of output: 14206

src/services/performanceDbApi.js (1)

Line range hint 111-116: Verify the SQL query construction with entityCount handling

The SQL query construction looks robust:

  • Uses LEFT OUTER JOIN to include rows without matching entity_counts
  • Handles missing values with COALESCE(ec.entity_count, 0)
  • Includes a fallback for empty entityCountsSelects

Let's verify the query construction and execution:

@eveleighoj eveleighoj temporarily deployed to submit-pr-607 November 6, 2024 09:57 Inactive
Copy link
Contributor

@GeorgeGoodall GeorgeGoodall left a comment

Choose a reason for hiding this comment

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

lgtm

@rosado rosado merged commit 0c028f3 into main Nov 6, 2024
5 checks passed
@rosado rosado deleted the rosado/NOTICKET-query-fix branch November 6, 2024 12:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants