|
98 | 98 | end |
99 | 99 | end |
100 | 100 |
|
| 101 | + describe 'Crowdin Client graphql' do |
| 102 | + let(:graphql_request) do |
| 103 | + { |
| 104 | + query: 'query Viewer { viewer { id } }', |
| 105 | + operationName: 'Viewer', |
| 106 | + variables: { projectId: 1, emptyValue: nil } |
| 107 | + } |
| 108 | + end |
| 109 | + let(:graphql_response) { { 'data' => { 'viewer' => { 'id' => 1 } } } } |
| 110 | + |
| 111 | + it 'posts to the default GraphQL endpoint', :default do |
| 112 | + stub_request(:post, 'https://api.crowdin.com/api/graphql') |
| 113 | + .with(body: graphql_request.to_json) |
| 114 | + .to_return(body: graphql_response.to_json) |
| 115 | + |
| 116 | + expect(@crowdin.graphql(graphql_request)).to eq(graphql_response) |
| 117 | + end |
| 118 | + |
| 119 | + it 'posts to the Enterprise GraphQL endpoint', :enterprise do |
| 120 | + stub_request(:post, 'https://domain.api.crowdin.com/api/graphql') |
| 121 | + .with(body: graphql_request.to_json) |
| 122 | + .to_return(body: graphql_response.to_json) |
| 123 | + |
| 124 | + expect(@crowdin.graphql(graphql_request)).to eq(graphql_response) |
| 125 | + end |
| 126 | + |
| 127 | + it 'supports a custom GraphQL endpoint URL', :default do |
| 128 | + custom_url = 'http://localhost:3000/api/graphql' |
| 129 | + |
| 130 | + stub_request(:post, custom_url) |
| 131 | + .with(body: graphql_request.to_json) |
| 132 | + .to_return(body: graphql_response.to_json) |
| 133 | + |
| 134 | + expect(@crowdin.graphql(graphql_request, url: custom_url)).to eq(graphql_response) |
| 135 | + end |
| 136 | + |
| 137 | + it 'returns parsed GraphQL error responses', :default do |
| 138 | + graphql_error_response = { 'errors' => [{ 'message' => 'Invalid query' }] } |
| 139 | + |
| 140 | + stub_request(:post, 'https://api.crowdin.com/api/graphql') |
| 141 | + .with(body: graphql_request.to_json) |
| 142 | + .to_return(status: 400, body: graphql_error_response.to_json) |
| 143 | + |
| 144 | + expect(@crowdin.graphql(graphql_request)).to eq(graphql_error_response) |
| 145 | + end |
| 146 | + end |
| 147 | + |
101 | 148 | describe 'connection' do |
102 | 149 | subject(:connection) { crowdin_client.connection } |
103 | 150 |
|
|
0 commit comments