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

test: Add tests for Connnect Card - 1 #3410

Open
wants to merge 1 commit into
base: FYLE-86cx2t82k-tests-for-connect-card
Choose a base branch
from

Conversation

bistaastha
Copy link
Contributor

@bistaastha bistaastha commented Jan 7, 2025

workerB
Coverage - remaining coverage to be added in follow up:
Screenshot 2025-01-07 at 11 58 34 PM

Summary by CodeRabbit

  • Bug Fixes

    • Enhanced error handling for card enrollment process
    • Improved masking of card numbers in error messages for privacy
  • Tests

    • Added comprehensive unit tests for the Spender Onboarding Connect Card Step component
    • Verified component initialization, lifecycle methods, and error handling scenarios

Copy link

coderabbitai bot commented Jan 7, 2025

Walkthrough

Superstar style, I'll break it down! 🌟 This pull request is all about supercharging the SpenderOnboardingConnectCardStepComponent with rock-solid unit tests and refined error handling. We've added comprehensive test coverage that checks every move of the component, ensuring it handles card enrollments and error scenarios with the precision of a mass hero's punch! The changes focus on masking card numbers in error messages and tightening up form validation methods.

Changes

File Change Summary
src/app/fyle/.../spender-onboarding-connect-card-step.component.spec.ts Added comprehensive unit tests covering component initialization, service interactions, error handling, and card enrollment scenarios
src/app/fyle/.../spender-onboarding-connect-card-step.component.ts Refined error message handling to use only last 4 digits of card numbers, updated validator bindings

Possibly related PRs

Suggested labels

size/M

Suggested reviewers

  • arjunaj5
  • Chethan-Fyle

Poem

🃏 Cards connect, tests ignite
Digits masked, errors take flight
Validators dance with might
In code's spectacular light
Rajini's style, pure delight! 💥

Sequence Diagram

sequenceDiagram
    participant Component as SpenderOnboardingConnectCardStep
    participant Service as CorporateCreditCardExpenseService
    participant Form as FormGroup

    Component->>Form: Initialize Form
    Component->>Service: Attempt Card Enrollment
    alt Enrollment Successful
        Service-->>Component: Success Response
    else Enrollment Failed
        Service-->>Component: Error Response
        Component->>Component: Setup Error Messages
        Component->>Form: Update Form State
    end
Loading

Thalaiva's coding style: Precise, powerful, and always leaving a stylish mark! 😎🚀


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

@github-actions github-actions bot added the size/M Medium PR label Jan 7, 2025
Copy link

github-actions bot commented Jan 7, 2025

PR description must contain a link to a ClickUp (case-insensitive)

1 similar comment
Copy link

github-actions bot commented Jan 7, 2025

PR description must contain a link to a ClickUp (case-insensitive)

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

🔭 Outside diff range comments (1)
src/app/fyle/spender-onboarding/spender-onboarding-connect-card-step/spender-onboarding-connect-card-step.component.ts (1)

Line range hint 3-3: Mind it! Remove the unused import, partner!

The ChangeDetectorRef is imported but never used in the code. Let's keep our imports clean and tidy!

-import { ChangeDetectorRef, Component, EventEmitter, Input, OnChanges, OnInit, Output, SimpleChanges } from '@angular/core';
+import { Component, EventEmitter, Input, OnChanges, OnInit, Output, SimpleChanges } from '@angular/core';
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between b2af4d7 and e2d3cd5.

📒 Files selected for processing (2)
  • src/app/fyle/spender-onboarding/spender-onboarding-connect-card-step/spender-onboarding-connect-card-step.component.spec.ts (1 hunks)
  • src/app/fyle/spender-onboarding/spender-onboarding-connect-card-step/spender-onboarding-connect-card-step.component.ts (3 hunks)
🧰 Additional context used
🪛 GitHub Actions: Lint
src/app/fyle/spender-onboarding/spender-onboarding-connect-card-step/spender-onboarding-connect-card-step.component.ts

[error] 3-3: 'ChangeDetectorRef' is defined but never used

⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: build (12.x)
🔇 Additional comments (5)
src/app/fyle/spender-onboarding/spender-onboarding-connect-card-step/spender-onboarding-connect-card-step.component.ts (3)

91-91: Superstar style security handling, macha!

Excellent work on masking the card numbers by only using the last 4 digits in error messages. This is a top-notch security practice that protects sensitive card information!


214-215: Mind-blowing fix for the validator binding!

The .bind(this) ensures our validators maintain the correct context. Without this, the validators could lose their 'this' context and crash like a villain's lair!


115-115: Style-ah implemented security, thalaiva!

The same card number masking is consistently applied here too. This kind of consistency in security practices is what separates heroes from zeros!

src/app/fyle/spender-onboarding/spender-onboarding-connect-card-step/spender-onboarding-connect-card-step.component.spec.ts (2)

24-59: What a grand entrance for our test setup, machan!

The test setup is as perfectly orchestrated as a mass hero entry scene! Excellent job with:

  • Proper spy creation for all services
  • Complete module configuration
  • Default mock responses

83-124: These test cases are punching like my signature moves!

Superb coverage of error scenarios with special focus on card number masking. The test cases verify that sensitive data is always protected, just like how I protect the innocent in my movies!

Comment on lines +155 to +232
describe('enrollMultipleCards(): ', () => {
it('should handle successful card enrollment', fakeAsync(() => {
corporateCreditCardExpenseService.getCorporateCards.and.returnValue(
of([statementUploadedCard, { ...statementUploadedCard, id: 'bacc15bbrRGWzg' }])
);
component.ngOnInit();

const stepCompleteSpy = spyOn(component.isStepComplete, 'emit');
const showErrorPopoverSpy = spyOn(component, 'showErrorPopover');
const setupErrorMessagesSpy = spyOn(component, 'setupErrorMessages');
realTimeFeedService.enroll.and.returnValues(of(statementUploadedCard), of(statementUploadedCard));
component.enrollMultipleCards(component.enrollableCards);
tick();
expect(component.cardsList.successfulCards).toEqual(['**** 5555', '**** 5555']);
expect(component.cardsEnrolling).toBeFalse();
expect(stepCompleteSpy).toHaveBeenCalledWith(true);
expect(showErrorPopoverSpy).not.toHaveBeenCalled();
expect(setupErrorMessagesSpy).not.toHaveBeenCalled();
}));

it('should handle unsuccessful card enrollment', fakeAsync(() => {
corporateCreditCardExpenseService.getCorporateCards.and.returnValue(
of([statementUploadedCard, { ...statementUploadedCard, id: 'bacc15bbrRGWzg' }])
);
component.ngOnInit();

const stepCompleteSpy = spyOn(component.isStepComplete, 'emit');
const showErrorPopoverSpy = spyOn(component, 'showErrorPopover');
realTimeFeedService.enroll.and.returnValues(
of(statementUploadedCard),
throwError(() => new Error('This card already exists in the system'))
);
component.enrollMultipleCards(component.enrollableCards);
tick();
expect(component.cardsList.successfulCards).toEqual(['**** 5555']);
expect(component.cardsList.failedCards).toEqual(['**** 5555']);
expect(component.cardsEnrolling).toBeFalse();
expect(stepCompleteSpy).toHaveBeenCalledWith(true);
expect(showErrorPopoverSpy).toHaveBeenCalledTimes(1);
}));
});

describe('enrollSingularCard(): ', () => {
it('should handle successful card enrollment', fakeAsync(() => {
corporateCreditCardExpenseService.getCorporateCards.and.returnValue(of([]));
component.ngOnInit();

component.fg.controls.card_number.setValue('41111111111111111');
const stepCompleteSpy = spyOn(component.isStepComplete, 'emit');
const showErrorPopoverSpy = spyOn(component, 'showErrorPopover');
const setupErrorMessagesSpy = spyOn(component, 'setupErrorMessages');
realTimeFeedService.enroll.and.returnValues(of(statementUploadedCard));
component.enrollSingularCard();
tick();
expect(component.cardsList.successfulCards).toEqual(['**** 1111']);
expect(component.cardsEnrolling).toBeFalse();
expect(stepCompleteSpy).toHaveBeenCalledWith(true);
expect(showErrorPopoverSpy).not.toHaveBeenCalled();
expect(setupErrorMessagesSpy).not.toHaveBeenCalled();
}));

it('should handle unsuccessful card enrollment', fakeAsync(() => {
corporateCreditCardExpenseService.getCorporateCards.and.returnValue(of([]));
component.ngOnInit();

component.fg.controls.card_number.setValue('41111111111111111');
const stepCompleteSpy = spyOn(component.isStepComplete, 'emit');
const showErrorPopoverSpy = spyOn(component, 'showErrorPopover');
realTimeFeedService.enroll.and.returnValues(
throwError(() => new Error('This card already exists in the system'))
);
component.enrollSingularCard();
tick();
expect(component.cardsList.failedCards).toEqual(['**** 1111']);
expect(component.cardsEnrolling).toBeFalse();
expect(showErrorPopoverSpy).toHaveBeenCalledTimes(1);
}));
});
Copy link

Choose a reason for hiding this comment

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

🧹 Nitpick (assertive)

The test coverage is powerful, but let's make it legendary!

The enrollment tests are solid like a punch sequence, but we could add more power with these additional test cases:

  • Network timeout scenarios
  • Multiple consecutive failures
  • Rate limiting responses

Would you like me to help craft these additional test cases?

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