Skip to content

Conversation

@Kyleasmth
Copy link
Collaborator

Screenshot 2026-02-03 at 12 52 44 PM Screenshot 2026-02-03 at 12 52 54 PM Screenshot 2026-02-03 at 12 53 19 PM Screenshot 2026-02-03 at 12 53 35 PM

@changeset-bot
Copy link

changeset-bot bot commented Feb 3, 2026

⚠️ No Changeset found

Latest commit: 262e0e0

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@Kyleasmth Kyleasmth requested a review from bmanquen February 3, 2026 22:54
@Kyleasmth Kyleasmth marked this pull request as ready for review February 4, 2026 00:50
@chatgpt-codex-connector
Copy link

Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits.
Credits must be used to enable repository wide code reviews.

@greptile-apps
Copy link
Contributor

greptile-apps bot commented Feb 4, 2026

Greptile Overview

Greptile Summary

Added comprehensive test suites for useChapter and useChapters hooks, following established testing patterns from useVersion and useVersions.

Key changes:

  • New test file useChapter.test.tsx with 7 test cases covering fetching, parameter changes (versionId, book, chapter), enabled option, error handling, and manual refetch
  • New test file useChapters.test.tsx with 10 test cases including standard tests plus book validation for invalid strings ("undefined", "null", empty string)
  • Fixed timing issue in useVersion.test.tsx and useVersions.test.tsx by checking loading state before error state in error recovery tests
  • Tests properly mock useBibleClient and validate the hook's interaction with useApiData
  • Book validation tests align with existing useChapters.ts:20 implementation that filters invalid book values

Minor gaps:

  • Both new test files are missing "should clear error on successful refetch" tests that verify error state is cleared after a successful retry (pattern exists in useVersion and useVersions tests)

Confidence Score: 4/5

  • Safe to merge with minor test coverage gaps
  • Well-structured tests following established patterns, but missing error recovery tests present in similar test files. Tests validate all major functionality including parameter changes, error handling, and refetch operations. The timing fixes in existing tests improve reliability.
  • No files require special attention - only minor test coverage improvements suggested

Important Files Changed

Filename Overview
packages/hooks/src/useChapter.test.tsx New comprehensive test suite for useChapter hook covering fetching, parameter changes, error handling, and refetch functionality
packages/hooks/src/useChapters.test.tsx New test suite for useChapters hook with standard tests plus book validation logic for invalid string values

Sequence Diagram

sequenceDiagram
    participant Test as Test Suite
    participant Hook as useChapter/useChapters
    participant Client as BibleClient (mocked)
    participant API as useApiData

    Test->>Hook: renderHook(versionId, book, chapter?)
    Hook->>Client: useBibleClient()
    Client-->>Hook: mockClient
    Hook->>API: useApiData(fetchFn, deps, options)
    API-->>Hook: {data, loading: true, error, refetch}
    Hook-->>Test: {chapter/chapters: null, loading: true}
    
    Note over API: useEffect triggered
    API->>Client: getChapter(versionId, book, chapter)
    Client-->>API: Promise<BibleChapter>
    API-->>Hook: {data: chapter, loading: false}
    Hook-->>Test: {chapter: mockChapter, loading: false}
    
    Test->>Hook: rerender with new params
    Note over API: Dependencies changed
    API->>Client: getChapter(newVersionId, book, chapter)
    Client-->>API: Promise<BibleChapter>
    Hook-->>Test: Updated chapter data
    
    Test->>Hook: result.current.refetch()
    Hook->>API: refetch()
    API->>Client: getChapter(versionId, book, chapter)
    Client-->>API: Promise<BibleChapter>
    Hook-->>Test: Refetched chapter data
Loading

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

2 files reviewed, 2 comments

Edit Code Review Agent Settings | Greptile

Comment on lines +159 to +175
it('should handle fetch errors', async () => {
const error = new Error('Failed to fetch chapter');
mockGetChapter.mockRejectedValueOnce(error);

const wrapper = createWrapper({
appKey: mockAppKey,
});

const { result } = renderHook(() => useChapter(1, 'MAT', 1), { wrapper });

await waitFor(() => {
expect(result.current.loading).toBe(false);
});

expect(result.current.error).toEqual(error);
expect(result.current.chapter).toBe(null);
});
Copy link
Contributor

Choose a reason for hiding this comment

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

Missing test for error recovery. useVersion.test.tsx:188 and useVersions.test.tsx:587 include tests verifying that errors are cleared after a successful refetch using mockRejectedValueOnce(error).mockResolvedValueOnce(data) pattern

Prompt To Fix With AI
This is a comment left during a code review.
Path: packages/hooks/src/useChapter.test.tsx
Line: 159:175

Comment:
Missing test for error recovery. `useVersion.test.tsx:188` and `useVersions.test.tsx:587` include tests verifying that errors are cleared after a successful refetch using `mockRejectedValueOnce(error).mockResolvedValueOnce(data)` pattern

How can I resolve this? If you propose a fix, please make it concise.

Comment on lines +133 to +149
it('should handle fetch errors', async () => {
const error = new Error('Failed to fetch chapters');
mockGetChapters.mockRejectedValueOnce(error);

const wrapper = createWrapper({
appKey: mockAppKey,
});

const { result } = renderHook(() => useChapters(1, 'MAT'), { wrapper });

await waitFor(() => {
expect(result.current.loading).toBe(false);
});

expect(result.current.error).toEqual(error);
expect(result.current.chapters).toBe(null);
});
Copy link
Contributor

Choose a reason for hiding this comment

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

Missing test for error recovery. useVersion.test.tsx:188 and useVersions.test.tsx:587 include tests verifying that errors are cleared after a successful refetch using mockRejectedValueOnce(error).mockResolvedValueOnce(data) pattern

Prompt To Fix With AI
This is a comment left during a code review.
Path: packages/hooks/src/useChapters.test.tsx
Line: 133:149

Comment:
Missing test for error recovery. `useVersion.test.tsx:188` and `useVersions.test.tsx:587` include tests verifying that errors are cleared after a successful refetch using `mockRejectedValueOnce(error).mockResolvedValueOnce(data)` pattern

How can I resolve this? If you propose a fix, please make it concise.

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.

2 participants