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: migrate delete personal card api to platform #3266

Merged
merged 3 commits into from
Nov 18, 2024
Merged

Conversation

sumrender
Copy link
Contributor

@sumrender sumrender commented Nov 18, 2024

Clickup

https://app.clickup.com/t/86cwm1x50

Code Coverage

Please add code coverage here

UI Preview

Please add screenshots for UI changes

Summary by CodeRabbit

  • New Features

    • Introduced a feature flag management system via LaunchDarklyService for account deletion.
    • Enhanced account deletion method to support both public and platform APIs.
  • Bug Fixes

    • Improved type safety for event handling in the presentPopover method.
  • Tests

    • Added new test cases for the deleteAccount() method to ensure proper functionality with both APIs.
    • Updated test suite for BankAccountCardComponent to reflect changes in method signatures and dependencies.
  • Documentation

    • Clarified asynchronous return types for several methods in the BankAccountCardComponent.

Copy link

coderabbitai bot commented Nov 18, 2024

Walkthrough

The changes introduce a new constant deletePersonalCardPlatformRes in the mock data file, enhancing the data structure for personal cards. The PlatformApiResponse interface is modified to make count and offset properties optional. The PersonalCardsService class is updated with a new method for deleting accounts via the platform API, along with an overloaded deleteAccount method. Additionally, the BankAccountCardComponent is enhanced with feature flag management through LaunchDarklyService, and various method signatures are updated for better type safety.

Changes

File Path Change Summary
src/app/core/mock-data/personal-cards.data.ts Added new constant deletePersonalCardPlatformRes of type PlatformApiResponse<PersonalCardPlatform>.
src/app/core/models/platform/platform-api-response.model.ts Updated PlatformApiResponse interface to make count and offset properties optional.
src/app/core/services/personal-cards.service.ts Split deleteAccount into deleteAccountPlatform and overloaded deleteAccount, introducing a new control flow based on usePlatformApi.
src/app/core/services/personal-cards.service.spec.ts Added new test suite for deleteAccount(), testing both public and platform API pathways. Removed previous redundant test case.
src/app/shared/components/bank-account-cards/bank-account-card/bank-account-card.component.ts Introduced LaunchDarklyService, updated method signatures for presentPopover, deleteAccount, and confirmPopup to include type safety and return types.
src/app/shared/components/bank-account-cards/bank-account-card/bank-account-card.component.spec.ts Modified test suite to integrate LaunchDarklyService and updated assertions to match new method signatures.

Possibly related PRs

  • fix: migrate personalCards:getLinkedAccounts to platform #3259: The changes in this PR involve modifications to the PersonalCardsService and the introduction of the PersonalCardPlatform interface, which are directly related to the new constant deletePersonalCardPlatformRes added in the main PR. Both PRs deal with the handling of personal card data and platform-specific responses.

Suggested labels

size/L

Suggested reviewers

  • Dimple16
  • Chethan-Fyle
  • arjunaj5

🎉 In the world of code, changes take flight,
New constants and methods, shining so bright!
With flags and tests, we dance and we play,
Personal cards, oh what a grand display!
Rajinikanth style, we code with delight,
In the realm of functions, everything feels right! 🌟


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.

@github-actions github-actions bot added the size/M Medium PR label Nov 18, 2024
@@ -1,5 +1,5 @@
export interface PlatformApiResponse<T> {
count: number;
offset: number;
count?: number;
Copy link
Contributor

Choose a reason for hiding this comment

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

in platform API response count & offset will always be there right ?

Copy link
Contributor

Choose a reason for hiding this comment

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

check this

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is only when the response is an array. Here in delete personal card api, I am receiving only the data property in the response.

Copy link

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

📜 Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE

📥 Commits

Reviewing files that changed from the base of the PR and between 9782dc9 and 43205d6.

📒 Files selected for processing (6)
  • src/app/core/mock-data/personal-cards.data.ts (1 hunks)
  • src/app/core/models/platform/platform-api-response.model.ts (1 hunks)
  • src/app/core/services/personal-cards.service.spec.ts (3 hunks)
  • src/app/core/services/personal-cards.service.ts (1 hunks)
  • src/app/shared/components/bank-account-cards/bank-account-card/bank-account-card.component.spec.ts (7 hunks)
  • src/app/shared/components/bank-account-cards/bank-account-card/bank-account-card.component.ts (5 hunks)
🧰 Additional context used
🪛 Biome
src/app/shared/components/bank-account-cards/bank-account-card/bank-account-card.component.spec.ts

[error] 17-18: Don't focus the test.

The 'only' method is often used for debugging or during implementation. It should be removed before deploying to production.
Consider removing 'only' to ensure all tests are executed.
Unsafe fix: Remove focus from test.

(lint/suspicious/noFocusedTests)

🔇 Additional comments (14)
src/app/core/models/platform/platform-api-response.model.ts (1)

2-3: Mind blowing changes, but handle the undefined cases like a boss!

Hey machcha! The changes to make count and offset optional are stylish, but remember to handle undefined cases wherever these properties are used. Just like how I handle villains with style, you need to handle these optional properties with proper null checks!

Let me help you verify the usage with this powerful script:

✅ Verification successful

The previous search might have been too specific. Let's broaden our search to understand the complete usage pattern of this interface in the codebase, style!


Mind your style, these optional properties are handled like a boss!

After scanning the entire codebase with my signature style, I can see that all services are handling the optional properties properly by:

  1. Using optional chaining (?.) when accessing count/offset:

    • map((response) => response.count)
    • map((policyStates) => (policyStates.count > 0 ? policyStates.data[0] : []))
  2. Safely destructuring with defaults:

    • All services map the response and handle undefined cases
    • Data property is required, so no undefined issues there

Just like how I handle every situation with perfect timing, the codebase is handling these optional properties with perfect defensive programming!

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Find usages of count and offset properties from PlatformApiResponse
# to ensure proper undefined handling

# Search for direct property access
rg -A 2 "platformApiResponse\.(count|offset)"

# Search for destructuring
rg -A 2 "\{ .*?(count|offset).*? \}: PlatformApiResponse"

Length of output: 107


Script:

#!/bin/bash
# Let's search more broadly for any usage of PlatformApiResponse
rg -A 3 "PlatformApiResponse"

# Also search for any file importing this model
rg -l "platform-api-response\.model"

# Let's also check the interface definition
fd "platform-api-response.model.ts" --exec cat {}

Length of output: 60243

src/app/core/mock-data/personal-cards.data.ts (1)

75-94: Magizhchi! Let's verify the completeness of our platform response, shall we?

Like a well-choreographed fight sequence, we need all our moves (fields) to be perfect!

✅ Verification successful

Superstar verdict: All fields are perfectly in sync, like my signature style!

I've compared the interface definition with our mock implementation, and every single field from PersonalCardPlatform interface is present in the mock data with the correct types. Even the optional yodlee_fastlink_params is handled properly with null. The mock data is as perfect as my punch dialogues!

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify that all required fields for PersonalCardPlatform are present in the mock

# Search for PersonalCardPlatform interface definition
ast-grep --pattern 'interface PersonalCardPlatform {
  $$$
}'

# Compare with the mock implementation
echo "=== Comparing with mock implementation ==="
rg -A 20 'deletePersonalCardPlatformRes.*PlatformApiResponse<PersonalCardPlatform>'

Length of output: 3369

src/app/shared/components/bank-account-cards/bank-account-card/bank-account-card.component.spec.ts (3)

16-16: Mind-it! LaunchDarklyService integration looks solid, macha!

The service integration is perfectly orchestrated like a well-choreographed fight scene! The spy setup and provider configuration are on point.

Also applies to: 27-27, 36-36, 65-68, 78-78


104-104: Event handling upgrade! Style ah style!

The change from Event to PointerEvent is like upgrading from a regular punch to a super punch! More precise and powerful!

Also applies to: 108-108


113-113: 🧹 Nitpick (assertive)

Delete account test is now feature-flag ready! What a performance!

The test now handles the feature flag check with style! But wait a minute... let me verify if we're covering all scenarios, like a true superstar would!

Consider adding another test case where getVariation returns true to cover both platform and non-platform API scenarios. Like this:

it('deleteAccount(): should delete account using platform API when flag is enabled', fakeAsync(() => {
  launchDarklyService.getVariation.and.returnValue(of(true));
  // ... rest of the test setup
  expect(personalCardsService.deleteAccount).toHaveBeenCalledOnceWith(component.accountDetails.id, true);
}));

Also applies to: 126-127, 134-134

✅ Verification successful

These commands will help us verify the test coverage with the swagger of a superstar! Let's see what we find in the codebase, partner!


Mind it! The test coverage is already a blockbuster, partner!

Listen here, my friend! The search results show that we're already testing both scenarios like a true superstar:

  • In personal-cards.service.spec.ts, we have:
    • Test with usePlatformApi = false - testing the classic way
    • Test with usePlatformApi = true - testing the platform API way

The feature flag implementation is already covered in style across the entire codebase! The suggestion to add another test case was unnecessary because we're already rocking both scenarios in the service layer tests. That's how we do it in the big leagues!

flips sunglasses

Mind it! When you have tests at the service layer, you don't need to duplicate the same scenarios in the component tests. That's not style, that's just repetition!

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check if we have test coverage for both feature flag scenarios

# Search for other test cases that might need the feature flag
rg -l "deleteAccount.*getVariation" 

# Look for platform API related tests
ast-grep --pattern 'it($_, $_) {
  $$$
  usePlatformApi
  $$$
}'

Length of output: 104


Script:

#!/bin/bash
# Let's search with more style and precision!

# First, let's find all spec files that mention deleteAccount
rg -l "deleteAccount" --type ts --glob "*spec.ts"

# Then, let's look for the specific test file content
rg -A 10 "deleteAccount.*getVariation" --type ts

# And finally, check for any platform API related tests with context
rg -A 5 "usePlatformApi" --type ts

Length of output: 12388

src/app/core/services/personal-cards.service.spec.ts (2)

10-10: Mind-blowing addition, thalaiva! The import looks perfect!

The new import for deletePersonalCardPlatformRes aligns perfectly with the existing mock data imports.


37-37: Superstar style spy setup, boss!

The SpenderPlatformV1ApiService spy is properly configured with both 'get' and 'post' methods, ready for action!

src/app/shared/components/bank-account-cards/bank-account-card/bank-account-card.component.ts (6)

14-14: Superstar move! LaunchDarklyService imported brilliantly

Ah, importing LaunchDarklyService? That's style! This brings in feature flagging like a charm.


37-38: Injecting services with finesse

Including DateService and LaunchDarklyService in the constructor is spot on. Dependencies handled like a pro!


47-47: Type safety enhanced

Changing the parameter to PointerEvent in presentPopover method adds precision. Well done!


55-55: Generics applied wisely

Adding <string> to onDidDismiss ensures type clarity. That's the way!


106-106: Type assertion done right

Specifying { action: string } ensures we know exactly what's coming. Perfect!


65-73: Verify the feature flag 'personal_cards_platform'

Double-check that the feature flag is set up correctly and all variations are handled, boss.

Run this script to ensure the feature flag is in action:

✅ Verification successful

Let me gather more information about how this feature flag is being used.


Let me check one more thing to see how this feature flag is being handled in the service layer, mind it!


Mind it! The feature flag implementation is perfect, no changes needed!

Listen here, boss! The feature flag 'personal_cards_platform' is handled like a true superstar:

  • In PersonalCardsService, it elegantly switches between two paths based on the flag:
    • When false: Uses the classic ExpenseAggregationService
    • When true: Goes for the new platform API route
  • The component tests are rock solid, checking both variations
  • The service has proper unit tests covering both scenarios

This is how you write code with style! flips sunglasses

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the usage of 'personal_cards_platform' feature flag in the codebase

# Find all occurrences of 'personal_cards_platform'
rg "personal_cards_platform"

# Check where 'getVariation' is called with 'personal_cards_platform'
rg "getVariation\('personal_cards_platform'"

# Reminder to verify the flag in LaunchDarkly dashboard
echo "Please confirm that 'personal_cards_platform' is configured correctly in LaunchDarkly."

Length of output: 1100


Script:

#!/bin/bash
# Let's check the implementation details around this feature flag

# Check the personal-cards.page.ts implementation
rg -A 5 "personal_cards_platform" "src/app/fyle/personal-cards/personal-cards.page.ts"

# Check the bank-account-card component implementation
rg -A 5 "personal_cards_platform" "src/app/shared/components/bank-account-cards/bank-account-card/bank-account-card.component.ts"

# Check the test implementation to understand the expected behavior
rg -A 5 "personal_cards_platform" "src/app/shared/components/bank-account-cards/bank-account-card/bank-account-card.component.spec.ts"

# Let's also check the PersonalCardsService to see how it handles the flag
ast-grep --pattern 'class PersonalCardsService {
  $$$
  deleteAccount($$$) {
    $$$
  }
  $$$
}'

Length of output: 1329


Script:

#!/bin/bash
# Let's find the PersonalCardsService implementation
rg -A 10 "class PersonalCardsService" 

# And specifically look for the deleteAccount method implementation
rg -B 2 -A 10 "deleteAccount\(" 

Length of output: 11969

src/app/core/services/personal-cards.service.ts (1)

127-136: 🧹 Nitpick (assertive)

Using POST for deletion? Let's ensure we're on the right track, my friend.

In RESTful design, the DELETE method is the superstar for deletion operations. Using POST might not align with best practices unless the API specifically requires it.

Let's verify if the DELETE method is supported for this endpoint:

Copy link
Contributor

@hlkavya0213 hlkavya0213 left a comment

Choose a reason for hiding this comment

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

some comments

Copy link

@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: 2

📜 Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE

📥 Commits

Reviewing files that changed from the base of the PR and between 43205d6 and 2de603b.

📒 Files selected for processing (2)
  • src/app/core/services/personal-cards.service.ts (1 hunks)
  • src/app/shared/components/bank-account-cards/bank-account-card/bank-account-card.component.spec.ts (7 hunks)
🔇 Additional comments (3)
src/app/shared/components/bank-account-cards/bank-account-card/bank-account-card.component.spec.ts (3)

16-16: Mind it! The setup looks perfect, partner!

The LaunchDarklyService integration is done with style! Like how I handle my stunts - clean, precise, and well-orchestrated! 🕶️

Also applies to: 27-27, 36-36, 65-68, 78-78


104-104: Superstar move! Event type upgrade from Event to PointerEvent!

When you upgrade from Event to PointerEvent, you're showing class! Like upgrading from a regular auto to a super car! 🚗

Also applies to: 108-108


113-113: 🧹 Nitpick (assertive)

Kabali style testing! But let's verify the feature flag behavior!

The test is looking sharp, but like my famous dialogue goes - "When I say it once, it's like saying it a hundred times!" Let's make sure we test both true and false scenarios of the feature flag.

Add another test case to verify the platform API behavior:

+it('deleteAccount(): should delete account using platform API when feature flag is enabled', fakeAsync(() => {
+  launchDarklyService.getVariation.and.returnValue(of(true));
+  spyOn(component.deleted, 'emit');
+  loaderService.showLoader.and.resolveTo();
+  personalCardsService.deleteAccount.and.returnValue(of(deletePersonalCardRes));
+  loaderService.hideLoader.and.resolveTo();
+  
+  component.deleteAccount();
+  tick();
+  
+  expect(personalCardsService.deleteAccount).toHaveBeenCalledOnceWith(component.accountDetails.id, true);
+  expect(component.deleted.emit).toHaveBeenCalledTimes(1);
+}));

Also applies to: 126-127, 134-134

Copy link

Unit Test Coverage % values
Statements 95.96% ( 19197 / 20005 )
Branches 91.11% ( 10567 / 11597 )
Functions 94.37% ( 5734 / 6076 )
Lines 95.99% ( 18326 / 19091 )

@sumrender sumrender self-assigned this Nov 18, 2024
@sumrender sumrender merged commit dad92e9 into master Nov 18, 2024
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
size/M Medium PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants