Skip to content

test(discussion view): add tests for client methods and --replies mode#13299

Merged
babakks merged 8 commits into
cli:feature/discussionfrom
maxbeizer:discussion-view-tests
Apr 29, 2026
Merged

test(discussion view): add tests for client methods and --replies mode#13299
babakks merged 8 commits into
cli:feature/discussionfrom
maxbeizer:discussion-view-tests

Conversation

@maxbeizer
Copy link
Copy Markdown
Contributor

Summary

Adds table-driven tests for the discussion view command, covering both client-level and command-level behavior. This is the follow-up test work discussed after merging #13295.

Client Tests (client_impl_test.go)

  • TestGetByNumber: field mapping, discussions-disabled error
  • TestGetWithComments: field mapping with nested replies, forward/backward pagination, reply reversal in newest mode, cursor/direction tracking, discussions-disabled error
  • TestGetCommentReplies: full field mapping, forward/backward pagination, reply reversal in newest mode, cursor/direction tracking, discussions-disabled error, nil node guard, wrong-node-type guard

Command Tests (view_test.go)

  • TestNewCmdView_repliesFlags (table-driven): mutual exclusivity (--replies with --comments/--web), --order/--limit/--after require --comments or --replies, pagination flags work with --replies
  • TestViewRun_replies (table-driven): TTY rendering, non-TTY raw output, JSON export, pagination hint presence/absence, routing assertion (verifies GetCommentReplies is called and GetByNumber/GetWithComments are not)

All new tests are table-driven per reviewer request.

Test Counts

  • 7 new client test cases (across 3 test functions)
  • 15 new command test cases (across 2 test functions)

cc @babakks

…--replies mode

Add table-driven tests for:

Client (client_impl_test.go):
- TestGetByNumber: field mapping, discussions disabled
- TestGetWithComments: field mapping, forward/backward pagination,
  reply reversal in newest mode, discussions disabled
- TestGetCommentReplies: field mapping, forward/backward pagination,
  reply reversal, discussions disabled, nil node, wrong node type

Command (view_test.go):
- TestNewCmdView_repliesFlags: mutual exclusivity with --comments/--web,
  --order/--limit/--after require --comments or --replies, pagination
  flags work with --replies
- TestViewRun_replies: TTY/non-TTY/JSON output, pagination hints,
  routing assertion (GetCommentReplies called, not GetByNumber or
  GetWithComments)

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@maxbeizer maxbeizer requested a review from a team as a code owner April 27, 2026 20:43
@maxbeizer maxbeizer requested review from williammartin and removed request for a team April 27, 2026 20:43
@github-actions github-actions Bot added external pull request originating outside of the CLI core team needs-triage needs to be reviewed unmet-requirements and removed needs-triage needs to be reviewed labels Apr 27, 2026
@github-actions
Copy link
Copy Markdown

Thanks for your pull request! Unfortunately, it doesn't meet the minimum requirements for review:

  • None of the referenced issues have the help wanted label

Please update your PR to address the above. Requirements:

  1. Include a detailed description of what this PR does
  2. Link to an issue with the help wanted label (use Fixes #123 or Closes #123 if it resolves the issue)

This PR will be automatically closed in 7 days if these requirements are not met.

babakks and others added 7 commits April 28, 2026 10:38
Inline mock JSON responses, use non-default values for all fields to
verify mapping, add repo-not-found test case, and match real API
behaviour for discussions-disabled response (null discussion with
NOT_FOUND error).

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Signed-off-by: Babak K. Shandiz <babakks@github.com>
Inline all JSON response helpers (getWithCommentsResp, wrapCommentsBlock,
commentNode) to avoid cross-test coupling. Add missing test cases for
empty comments, first page newest reversal, multiple replies on a single
comment, and repo not found. Populate the "maps comments with replies"
case with non-zero field values and use a single assert.Equal for the
full Discussion struct. Match real API error responses for discussions
disabled and repo not found cases. Rename wantDisc to assertDisc across
all client test functions and require it for non-error cases.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Inline all JSON response helpers (getCommentRepliesResp, wrapRepliesBlock,
bareCommentNode, replyNode) to avoid cross-test coupling. Fix JSON response
shape to place "node" as sibling of "repository" under "data", matching the
real GraphQL query structure. Populate "maps all fields" with non-zero
values and use a single assert.Equal for the full Discussion struct.

Match real API error responses: discussions disabled returns NOT_FOUND on
discussion, node not found returns NOT_FOUND with null node, wrong-type
node returns empty object. Add missing test cases for repo not found and
first page newest reversal.

Move shared wantComments/wantTotal/wantCursor/wantNext/wantDirection fields
into assertDisc callbacks for both TestGetWithComments and
TestGetCommentReplies, giving each case full ownership of its assertions.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Replace scattered standalone test functions with a single table-driven
TestNewCmdView covering all arg/flag parsing: number, hash, URL, web,
comments, replies, limit, after, order, mutual exclusivity, and invalid
inputs. Uses shlex.Split for arg parsing and asserts opts fields
individually per case.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@babakks babakks requested review from babakks and removed request for williammartin April 29, 2026 12:07
@babakks
Copy link
Copy Markdown
Member

babakks commented Apr 29, 2026

Thanks for the PR, @maxbeizer! 🙏

I went through it and made some changes. I think this is now a good example to be referenced for the upcoming commands.

Have a look and let me know WDYT. If you're okay with it I'll merge it and we're done with list and view commands.

Changes

Details

This branch adds test coverage for discussion view and its underlying client methods, building on the feature/discussion branch.

Client tests (pkg/cmd/discussion/client):

  • Improved coverage for GetByNumber, GetWithComments, and GetCommentReplies
  • Fixed test fixtures to use nil next page cursor to match actual API behaviour
  • General polish and cleanup (removed flower box comments, consistent style)

View command tests (pkg/cmd/discussion/view):

  • Added TestJSONFields to verify the full set of exported JSON fields
  • Consolidated flag parsing tests into a single TestNewCmdView table test (22 cases)
  • Consolidated run tests into a single TestViewRun table test (18 cases) covering:
    • TTY and non-TTY output
    • Web mode
    • Answerable vs unanswerable discussions
    • Comments (with and without pagination)
    • Replies (with and without pagination)
    • JSON output (with and without comments field, with pagination)
  • All clientStub callbacks assert received arguments (repo, number, and method-specific params)
  • Removed all old standalone TestViewRun_* functions

@maxbeizer
Copy link
Copy Markdown
Contributor Author

Changes look good to me — go ahead and merge when ready. The consolidated table-driven tests and helpers will be a great template for Phase 2. 👍

@babakks babakks merged commit a92d0c6 into cli:feature/discussion Apr 29, 2026
7 of 8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

external pull request originating outside of the CLI core team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants