(t *testing.T)
| 87 | } |
| 88 | |
| 89 | func TestCmdScaffold(t *testing.T) { |
| 90 | const repoName = `query RepoName { repository(owner: "o", name: "r") { name } }` |
| 91 | const exampleIssue = `{"id":1,"number":1347,"title":"Found a bug","body":"I'm having a problem with this.","state":"open",` + |
| 92 | `"user":{"login":"octocat","id":1},"labels":[{"name":"bug","color":"f29513"}],"created_at":"2011-04-22T13:33:48Z"}` |
| 93 | |
| 94 | tests := []struct { |
| 95 | name string |
| 96 | noSchemas bool |
| 97 | responses string |
| 98 | logged []loggedRequest |
| 99 | runs []runRecord |
| 100 | args []string |
| 101 | wantStdout string |
| 102 | wantErr string |
| 103 | want string |
| 104 | }{ |
| 105 | { |
| 106 | name: "cyclic fragments stop before scaffolding", |
| 107 | logged: []loggedRequest{gqlEntry("r1", "Loop", `query Loop { viewer { ...Fields } } fragment Fields on User { login ...Fields }`, "")}, |
| 108 | args: []string{"graphql Loop"}, |
| 109 | wantErr: "gh's query couldn't be read; ghmock log --full shows it", |
| 110 | want: `{}`, |
| 111 | }, |
| 112 | { |
| 113 | name: "scaffolding uses the selected second operation", |
| 114 | logged: []loggedRequest{gqlEntry("r1", "Second", |
| 115 | `query First { viewer { login } } query Second { viewer { name } }`, "")}, |
| 116 | args: []string{"graphql Second"}, |
| 117 | wantStdout: "graphql Second: added response 1 of 1 with placeholder values\n", |
| 118 | want: `{"graphql Second":[{"body":{"data":{"viewer":{"name":"name"}}}}]}`, |
| 119 | }, |
| 120 | { |
| 121 | name: "candidate validation retains explicit overrides of variable defaults", |
| 122 | logged: []loggedRequest{gqlEntry("r1", "Default", |
| 123 | `query Default($show:Boolean = true) { viewer { login name @include(if:$show) } }`, `{"show":false}`)}, |
| 124 | args: []string{"graphql Default"}, |
| 125 | wantStdout: "graphql Default: added response 1 of 1 with placeholder values\n", |
| 126 | want: `{"graphql Default":[{"body":{"data":{"viewer":{"login":"login"}}}}]}`, |
| 127 | }, |
| 128 | { |
| 129 | name: "an existing typename alias chooses the object to repair", |
| 130 | responses: `{"graphql Kind":[{"body":{"data":{"repository":{"issueOrPullRequest":{"kind":"Issue"}}}}}]}`, |
| 131 | logged: []loggedRequest{gqlEntry("r1", "Kind", |
| 132 | `query Kind { repository(owner:"o",name:"r") { issueOrPullRequest(number:1) { kind:__typename ...on PullRequest { number } ...on Issue { title } } } }`, "")}, |
| 133 | args: []string{"graphql Kind"}, |
| 134 | wantStdout: "graphql Kind: response 1 of 1: added data.repository.issueOrPullRequest.title\n", |
| 135 | want: `{"graphql Kind":[{"body":{"data":{"repository":{"issueOrPullRequest":{"kind":"Issue","title":"title"}}}}}]}`, |
| 136 | }, |
| 137 | { |
| 138 | name: "--missing uses the completed run rather than a later incomplete query", |
| 139 | logged: []loggedRequest{ |
| 140 | gqlEntry("r1", "Same", `query Same { viewer { login } }`, ""), |
| 141 | gqlEntry("r2", "Same", `query Same { viewer { name } }`, ""), |
| 142 | }, |
| 143 | runs: []runRecord{{ID: "r1"}}, |
| 144 | args: []string{"--missing"}, |
| 145 | wantStdout: "graphql Same: added response 1 of 1 with placeholder values\n", |
| 146 | want: `{"graphql Same":[{"body":{"data":{"viewer":{"login":"login"}}}}]}`, |
nothing calls this directly
no test coverage detected