Fix credit note single response parsing - extract credit_note instead of credit_notes#1291
Open
mcse3010 wants to merge 1 commit into
Open
Conversation
The transformCreditNoteResponse function was extracting 'credit_notes' (plural) from the API response, but the FreshBooks API returns 'credit_note' (singular) for single credit note operations (GET, POST, PUT). This caused a TypeError when accessing properties on undefined. Changes: - Fix CreditNote.ts to extract 'credit_note' instead of 'credit_notes' - Update test mocks to match actual API response format
There was a problem hiding this comment.
Pull request overview
This PR fixes a critical bug in the credit notes single-entity operations (single(), create(), update(), delete()) that were failing with TypeError: Cannot read properties of undefined (reading 'id'). The root cause was that transformCreditNoteResponse was incorrectly extracting credit_notes (plural) from API responses, when the FreshBooks API actually returns credit_note (singular) for single credit note operations.
Key Changes:
- Fixed response parsing to use
credit_noteinstead ofcredit_notesintransformCreditNoteResponse - Updated test mocks to match actual API response format for single credit note operations
- Corrected typo in test description
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| packages/api/src/models/CreditNote.ts | Fixed transformCreditNoteResponse to extract credit_note (singular) instead of credit_notes (plural) from API responses, aligning with how other entities (Invoice, Client) handle single-entity responses |
| packages/api/tests/CreditNote.test.ts | Updated mock responses for single(), create(), update(), and delete() tests to use credit_note instead of credit_notes, and fixed typo in test description |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Purpose
Fix creditNotes.single(), create(), update(), and delete() methods which were failing with TypeError: Cannot read properties of undefined (reading 'id').
The transformCreditNoteResponse function was extracting credit_notes (plural) from the API response, but the FreshBooks API returns credit_note (singular) for single credit note operations. This is consistent with how other entities work (e.g., invoice not invoices in transformInvoiceResponse).
Before: Methods fail because credit_notes is undefined in the response
After: Methods correctly extract credit_note from the response
Changes
Related Material
See Issue #1290
Don't know if you work on the API docs as well, but -- also interesting to note, the API documentation is wrong and doesn't match what the API returns