MCPcopy
hub / github.com/cli/cli / TestGetByNumber

Function TestGetByNumber

pkg/cmd/discussion/client/client_test.go:1012–1150  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

1010}
1011
1012func TestGetByNumber(t *testing.T) {
1013 repo := ghrepo.New("OWNER", "REPO")
1014
1015 tests := []struct {
1016 name string
1017 httpStubs func(*testing.T, *httpmock.Registry)
1018 wantErr string
1019 assertDisc *Discussion
1020 }{
1021 {
1022 name: "maps all fields",
1023 httpStubs: func(t *testing.T, reg *httpmock.Registry) {
1024 reg.Register(
1025 httpmock.GraphQL(`query RepositoryMetaForDiscussions\b`),
1026 httpmock.StringResponse(repoMetaResp("R_1", true)),
1027 )
1028 reg.Register(
1029 httpmock.GraphQL(`query DiscussionMinimal\b`),
1030 httpmock.StringResponse(heredoc.Doc(`
1031 {
1032 "data": {
1033 "repository": {
1034 "discussion": {
1035 "id": "D_1",
1036 "number": 42,
1037 "title": "Test Discussion",
1038 "body": "This is a test",
1039 "url": "https://github.com/OWNER/REPO/discussions/42",
1040 "closed": true,
1041 "stateReason": "RESOLVED",
1042 "isAnswered": true,
1043 "answerChosenAt": "2025-06-01T12:00:00Z",
1044 "author": {"__typename": "User", "login": "alice", "id": "U1", "name": "Alice"},
1045 "category": {"id": "C1", "name": "Q&A", "slug": "q-a", "emoji": ":question:", "isAnswerable": true},
1046 "answerChosenBy": {"__typename": "User", "login": "bob", "id": "U2", "name": "Bob"},
1047 "labels": {"nodes": [{"id": "L1", "name": "bug", "color": "d73a4a"}]},
1048 "reactionGroups": [{"content": "THUMBS_UP", "users": {"totalCount": 3}}],
1049 "createdAt": "2025-01-01T00:00:00Z",
1050 "updatedAt": "2025-01-02T00:00:00Z",
1051 "closedAt": "2025-06-01T00:00:00Z",
1052 "locked": true,
1053 "comments": {"totalCount": 5}
1054 }
1055 }
1056 }
1057 }
1058 `)),
1059 )
1060 },
1061 assertDisc: &Discussion{
1062 ID: "D_1",
1063 Number: 42,
1064 Title: "Test Discussion",
1065 Body: "This is a test",
1066 URL: "https://github.com/OWNER/REPO/discussions/42",
1067 Closed: true,
1068 StateReason: "RESOLVED",
1069 Author: DiscussionActor{ID: "U1", Login: "alice", Name: "Alice"},

Callers

nothing calls this directly

Calls 12

RegisterMethod · 0.95
VerifyMethod · 0.95
NewFunction · 0.92
GraphQLFunction · 0.92
StringResponseFunction · 0.92
repoMetaRespFunction · 0.85
newTestDiscussionClientFunction · 0.85
ContainsMethod · 0.80
EqualMethod · 0.80
RunMethod · 0.65
GetByNumberMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected