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

fix(#285): false-positives for unknowns #534

Merged
merged 1 commit into from
Oct 5, 2024

Conversation

philipbrembeck
Copy link
Contributor

@philipbrembeck philipbrembeck commented Oct 5, 2024

Ref: #285

Summary by Sourcery

Fix false-positive results for unknown ingredients by categorizing them correctly. Refactor the ingredients parsing logic and improve the response structure. Update tests by removing and skipping certain cases. Update the OpenAPI specification by removing the 'translate' query parameter.

Bug Fixes:

  • Fix false-positive results for unknown ingredients by correctly categorizing them as 'maybe_vegan'.

Enhancements:

  • Refactor the ingredients parsing logic into a separate method for better code organization and readability.
  • Improve the response structure by categorizing ingredients into 'surely_vegan', 'not_vegan', and 'maybe_vegan'.

Documentation:

  • Remove the 'translate' query parameter from the OpenAPI specification in 'OpenAPI.yaml'.

Tests:

  • Remove a test case in 'product.service.spec.ts' that checks for a NotFoundException when a product is not found.
  • Skip certain test cases in 'errors.controller.spec.ts' related to OpenAPI specification and security.txt file.

Copy link

stackblitz bot commented Oct 5, 2024

Review PR in StackBlitz Codeflow Run & review this pull request in StackBlitz Codeflow.

Copy link

sourcery-ai bot commented Oct 5, 2024

Reviewer's Guide by Sourcery

This pull request addresses false-positive issues for unknown ingredients and improves the overall functionality of the ingredients controller. The changes include refactoring the ingredient parsing logic, updating the response structure, and modifying test cases.

Updated class diagram for IngredientsController

classDiagram
    class IngredientsController {
        +getIngredients(ingredientsParam: string, res: Response, translateFlag: boolean)
        +parseIngredients(ingredientsString: string) : string[]
        +sendResponse(res: Response, notVeganItems: string[], veganItems: string[], unknownItems: string[])
    }
    class TranslationService {
        +translateText(text: string, targetLang: string, timeout: number)
    }
    class ResponseData {
        +boolean vegan
        +string[] surely_vegan
        +string[] not_vegan
        +string[] maybe_vegan
    }
    IngredientsController --> TranslationService
    IngredientsController --> ResponseData
Loading

File-Level Changes

Change Details Files
Refactored ingredient parsing and classification logic
  • Introduced a new parseIngredients method to handle ingredient string parsing
  • Updated the logic to classify ingredients as vegan, not vegan, or unknown
  • Modified the response structure to include surely_vegan, not_vegan, and maybe_vegan categories
  • Removed lodash dependency and implemented custom filtering logic
src/ingredients/ingredients.controller.ts
Updated API response structure
  • Modified the ResponseData interface to include surely_vegan, not_vegan, and maybe_vegan properties
  • Updated the sendResponse method to use the new response structure
src/ingredients/ingredients.controller.ts
Improved error handling and type safety
  • Added type assertion for isNotVegan and isVegan arrays
  • Improved error handling for translation service
  • Added DeeplLanguages type import and usage
src/ingredients/ingredients.controller.ts
Modified test cases
  • Updated product service test to use a valid barcode and increased timeout
  • Skipped some test cases in errors.controller.spec.ts
src/product/product.service.spec.ts
src/errors.controller.spec.ts
Updated OpenAPI specification
  • Removed the 'translate' query parameter from the OpenAPI specification
OpenAPI.yaml

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time. You can also use
    this command to specify where the summary should be inserted.

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey @philipbrembeck - I've reviewed your changes - here's some feedback:

Overall Comments:

  • The changes look good overall, but please revisit the skipped tests in errors.controller.spec.ts to ensure adequate test coverage is maintained.
Here's what I looked at during the review
  • 🟡 General issues: 1 issue found
  • 🟢 Security: all looks good
  • 🟢 Testing: all looks good
  • 🟢 Complexity: all looks good
  • 🟢 Documentation: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

src/ingredients/ingredients.controller.ts Show resolved Hide resolved
@philipbrembeck philipbrembeck merged commit e7c5942 into staging Oct 5, 2024
5 checks passed
@philipbrembeck philipbrembeck deleted the fix/alse-positives-for-unknowns branch October 7, 2024 17:57
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