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: unit tests for migration of /v2/corporate_card_transactions #3510

Merged
merged 3 commits into from
Feb 17, 2025

Conversation

Z3RO-O
Copy link
Contributor

@Z3RO-O Z3RO-O commented Feb 16, 2025

Clickup

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

Code Coverage

Unit Test Coverage % values
Statements 96.03% ( 19750 / 20566 )
Branches 91.17% ( 10836 / 11885 )
Functions 94.34% ( 5872 / 6224 )
Lines 96.08% ( 18868 / 19637 )

UI Preview

Please add screenshots for UI changes

Summary by CodeRabbit

  • Chores

    • Removed legacy mock data for corporate card expense transactions.
  • Refactor

    • Improved naming and data handling for corporate card transaction processing.
  • Tests

    • Updated test cases to ensure accurate behavior in expense merging and corporate card transaction retrieval, including adjustments to expected data structures and parameters.

Copy link

gitstream-cm bot commented Feb 16, 2025

🚨 gitStream Monthly Automation Limit Reached 🚨

Your organization has exceeded the number of pull requests allowed for automation with gitStream.
Monthly PRs automated: 315/250

To continue automating your PR workflows and unlock additional features, please contact LinearB.

Copy link

coderabbitai bot commented Feb 16, 2025

Walkthrough

This pull request removes an outdated mock data file and updates several test suites to reflect a new naming convention and data structure for corporate card transactions. The deleted file contained immutable mock data, now replaced in tests by the new constant ccTransactionResponseData. Additionally, test methods have been renamed—from getv2CardTransactions() to getCorporateCardTransactions()—with API calls updated from apiV2Service.get to spenderPlatformV1ApiService.get and parameters adjusted.

Changes

File(s) Change Summary
src/app/core/mock-data/corporate-card-expense.data.ts Removed the file; deleted the exported corporateCardExpenseData constant used for simulating API responses.
src/app/core/services/corporate-credit-card-expense.service.spec.ts Renamed test method from getv2CardTransactions() to getCorporateCardTransactions(); updated API call from apiV2Service.get to spenderPlatformV1ApiService.get; adjusted parameters (e.g., limit from 2 to 1) and expected response.
src/app/core/services/merge-expenses.service.spec.ts
src/app/fyle/merge-expense/merge-expense-3.page.spec.ts
Updated mock data imports by replacing corporateCardExpenseData/apiCardV2Transactions with ccTransactionResponseData; aligned test expectations and method names to use getCorporateCardTransactions.
src/app/fyle/merge-expense/card-transaction-preview/card-transaction-preview.component.spec.ts Updated mock transaction details to reflect new data structure; changed property names from vendor to merchant and txn_dt to spent_at.

Sequence Diagram(s)

sequenceDiagram
    participant Component
    participant CorporateCreditCardExpenseService
    participant SpenderPlatformV1ApiService
    Component->>+CorporateCreditCardExpenseService: getCorporateCardTransactions(params)
    CorporateCreditCardExpenseService->>+SpenderPlatformV1ApiService: get(updatedParams)
    SpenderPlatformV1ApiService-->>-CorporateCreditCardExpenseService: ccTransactionResponseData
    CorporateCreditCardExpenseService-->>-Component: ccTransactionResponseData
Loading

Suggested reviewers

  • arjunaj5
  • Chethan-Fyle
  • Dimple16

Poem

Like a supercharged Rajinikanth move, the old mocks disappear in style,
Our code now shines bright—pure power, no denial.
Methods reborn with a name that roars, a true superstar’s decree,
Tests aligned and flowing smooth, as unstoppable as can be.
In every line, the spirit of a boss echoes loud and clear—
Code that wins like Rajinikanth, with fame and fearless cheer!


📜 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 4cd7b98 and 2dc3856.

📒 Files selected for processing (2)
  • src/app/core/services/merge-expenses.service.spec.ts (3 hunks)
  • src/app/fyle/merge-expense/card-transaction-preview/card-transaction-preview.component.spec.ts (3 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: build (12.x)
🔇 Additional comments (6)
src/app/core/services/merge-expenses.service.spec.ts (3)

93-93: Yo, this import change is spot on, machan!

The import statement correctly reflects the migration from corporateCardExpenseData to ccTransactionResponseData.


126-126: Mind it! The spy method name change is perfect, thalaiva!

The spy method name has been correctly updated to match the new service method name.


490-542: Style ah test cases update panirukinga! (You've stylishly updated the test cases!)

The test cases have been comprehensively updated with:

  • Proper test coverage for the new method name and data structure
  • Edge case handling for null ids and empty arrays
  • Clear and accurate assertions
src/app/fyle/merge-expense/card-transaction-preview/card-transaction-preview.component.spec.ts (3)

7-7: Mind it! The import change looks perfect, machan!

The migration from MatchedCCCTransaction to corporateCardTransaction shows the style of a true professional. This is how we roll in platform v1!


32-38: Kabali da! These test changes are hitting the bullseye!

The mock data structure transformation is as smooth as my style! The type update to Partial<corporateCardTransaction> is exactly what the doctor ordered.


33-35:

❓ Verification inconclusive

Thalaiva says: Let's verify this epic transformation!

The property name changes from vendor to merchant and txn_dt to spent_at are looking sharp! But in my style, we should verify this is consistent across the entire codebase.

Also applies to: 45-46


🏁 Script executed:

#!/bin/bash
# Description: Check for any remaining old property names in test files

echo "Checking for old property names in test files..."
rg -l "vendor|txn_dt" "src/**/*.spec.ts"

echo "Verifying new property names are used consistently..."
rg -l "merchant|spent_at" "src/**/*.spec.ts"

Length of output: 427


Rajinikanth's Transformation Verification Alert!

The updates from vendor to merchant and txn_dt to spent_at match the epic transformation we’re aiming for. However, our automated check couldn’t pinpoint the file due to path resolution issues. I recommend a manual verification in the specific file:

  • File: src/app/fyle/merge-expense/card-transaction-preview/card-transaction-preview.component.spec.ts
    • Check Lines: 33-35 for property replacements (ensure it's now using merchant and spent_at).
    • Also Verify: Lines 45-46 for updated selectors and test assertions.

Once confirmed that no remnants of the old properties (vendor and txn_dt) remain, we can celebrate this transformation like a true legend!

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

@github-actions github-actions bot added the size/M Medium PR label Feb 16, 2025
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 (2)
src/app/core/services/corporate-credit-card-expense.service.spec.ts (1)

159-178: 🧹 Nitpick (assertive)

Mind it! Add more test cases for error scenarios, macha!

The test suite for getCorporateCardTransactions needs additional test cases to handle:

  • API error responses
  • Network failures
  • Invalid parameters

Add these test cases to make the test suite more robust:

it('should handle API errors in getCorporateCardTransactions', (done) => {
  const error = new Error('API Error');
  spenderPlatformV1ApiService.get.and.returnValue(throwError(() => error));

  const param = {
    offset: 0,
    queryParams: {},
    limit: 1,
  };

  cccExpenseService.getCorporateCardTransactions(param).subscribe({
    error: (err) => {
      expect(err).toBe(error);
      done();
    }
  });
});

it('should handle invalid parameters in getCorporateCardTransactions', (done) => {
  const param = {
    offset: -1, // Invalid offset
    queryParams: {},
    limit: 0,  // Invalid limit
  };

  cccExpenseService.getCorporateCardTransactions(param).subscribe({
    error: (err) => {
      expect(err instanceof Error).toBe(true);
      expect(err.message).toContain('Invalid parameters');
      done();
    }
  });
});
src/app/core/services/merge-expenses.service.spec.ts (1)

488-533: 🧹 Nitpick (assertive)

Style ah? Let's make it more stylish with comprehensive test coverage!

The test suite for getCorporateCardTransactions is good but needs more test cases for edge scenarios.

Add these test cases to make it more powerful:

it('should handle invalid group_id in corporate card transactions', (done) => {
  const params = {
    queryParams: {
      group_id: null
    },
    offset: 0,
    limit: 1
  };

  customInputsService.getAll.withArgs(true).and.returnValue(of(customInputData));
  corporateCreditCardExpenseService.getCorporateCardTransactions
    .withArgs(params)
    .and.returnValue(throwError(() => new Error('Invalid group_id')));

  mergeExpensesService.getCorporateCardTransactions([undefined]).subscribe({
    error: (err) => {
      expect(err.message).toEqual('Invalid group_id');
      done();
    }
  });
});

it('should handle pagination in corporate card transactions', (done) => {
  const params = {
    queryParams: {
      group_id: ['in.(,)']
    },
    offset: 10,
    limit: 5
  };

  customInputsService.getAll.withArgs(true).and.returnValue(of(customInputData));
  corporateCreditCardExpenseService.getCorporateCardTransactions
    .withArgs(params)
    .and.returnValue(of(ccTransactionResponseData));

  mergeExpensesService.getCorporateCardTransactions(expensesDataWithCC, 10, 5).subscribe((res) => {
    expect(res).toEqual(ccTransactionResponseData.data);
    done();
  });
});
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between d38bbc5 and 4cd7b98.

📒 Files selected for processing (4)
  • src/app/core/mock-data/corporate-card-expense.data.ts (0 hunks)
  • src/app/core/services/corporate-credit-card-expense.service.spec.ts (1 hunks)
  • src/app/core/services/merge-expenses.service.spec.ts (4 hunks)
  • src/app/fyle/merge-expense/merge-expense-3.page.spec.ts (2 hunks)
💤 Files with no reviewable changes (1)
  • src/app/core/mock-data/corporate-card-expense.data.ts
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: build (12.x)

Comment on lines 256 to 262
it('onPaymentModeChanged(): should call mergeExpensesService.getCorporateCardTransactions() once and assign CCCTxns correctly', () => {
component.expenses = expenseList2;
mergeExpensesService.getCorporateCardTransactions.and.returnValue(of(apiCardV2Transactions.data));
mergeExpensesService.getCorporateCardTransactions.and.returnValue(of(ccTransactionResponseData.data));
component.onPaymentModeChanged();
expect(mergeExpensesService.getCorporateCardTransactions).toHaveBeenCalledOnceWith(expenseList2);
expect(component.CCCTxns).toEqual(apiCardV2Transactions.data);
expect(component.CCCTxns).toEqual(ccTransactionResponseData.data);
});
Copy link

Choose a reason for hiding this comment

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

🧹 Nitpick (assertive)

Thalaiva says: Add more test cases for payment mode changes!

The test for onPaymentModeChanged only covers the happy path. We need to test different payment modes and error scenarios.

Add these test cases to make it more robust:

it('should handle empty expense list in onPaymentModeChanged', () => {
  component.expenses = [];
  component.onPaymentModeChanged();
  expect(mergeExpensesService.getCorporateCardTransactions).not.toHaveBeenCalled();
  expect(component.CCCTxns).toEqual([]);
});

it('should handle errors in onPaymentModeChanged', () => {
  component.expenses = expenseList2;
  mergeExpensesService.getCorporateCardTransactions.and.returnValue(throwError(() => new Error('API Error')));
  
  component.onPaymentModeChanged();
  expect(mergeExpensesService.getCorporateCardTransactions).toHaveBeenCalledWith(expenseList2);
  expect(component.CCCTxns).toBeUndefined();
});

Copy link

Unit Test Coverage % values
Statements 96.03% ( 19750 / 20566 )
Branches 91.17% ( 10836 / 11885 )
Functions 94.34% ( 5872 / 6224 )
Lines 96.08% ( 18868 / 19637 )

@Z3RO-O Z3RO-O requested a review from Dimple16 February 16, 2025 13:19
@Z3RO-O Z3RO-O merged commit 4901ea9 into Fyle-86cxz8ph9 Feb 17, 2025
7 checks passed
Z3RO-O added a commit that referenced this pull request Feb 18, 2025
* feat: Migrate /v2/corporate_card_transactions to platform

* fix: unit tests for migration of /v2/corporate_card_transactions (#3510)
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