|
3 | 3 | require 'rails_helper'
|
4 | 4 |
|
5 | 5 | RSpec.describe UploadJob do
|
| 6 | + include ActiveJob::TestHelper |
| 7 | + |
6 | 8 | around do |example|
|
7 | 9 | ClimateControl.modify GITHUB_AUTH_TOKEN: 'secret', GITHUB_WEBHOOK_REF: 'branches/whatever' do
|
8 | 10 | example.run
|
|
122 | 124 | }
|
123 | 125 | end
|
124 | 126 |
|
125 |
| - before do |
126 |
| - stub_request(:get, 'https://github.com/me/my-amazing-repo/raw/branches/whatever/ja-JP/code/dont-collide-starter/astronaut1.png').to_return(status: 200, body: '', headers: {}) |
127 |
| - stub_request(:get, 'https://github.com/me/my-amazing-repo/raw/branches/whatever/ja-JP/code/dont-collide-starter/music.mp3').to_return(status: 200, body: '', headers: {}) |
128 |
| - stub_request(:get, 'https://github.com/me/my-amazing-repo/raw/branches/whatever/ja-JP/code/dont-collide-starter/video.mp4').to_return(status: 200, body: '', headers: {}) |
129 |
| - end |
130 |
| - |
131 | 127 | context 'with the build flag undefined' do
|
132 | 128 | let(:raw_response) { modifiable_response }
|
133 | 129 |
|
134 | 130 | before do
|
135 | 131 | allow(GithubApi::Client).to receive(:query).and_return(graphql_response)
|
136 | 132 | allow(ProjectImporter).to receive(:new).and_call_original
|
| 133 | + |
| 134 | + stub_request(:get, 'https://github.com/me/my-amazing-repo/raw/branches/whatever/ja-JP/code/dont-collide-starter/astronaut1.png').to_return(status: 200, body: '', headers: {}) |
| 135 | + stub_request(:get, 'https://github.com/me/my-amazing-repo/raw/branches/whatever/ja-JP/code/dont-collide-starter/music.mp3').to_return(status: 200, body: '', headers: {}) |
| 136 | + stub_request(:get, 'https://github.com/me/my-amazing-repo/raw/branches/whatever/ja-JP/code/dont-collide-starter/video.mp4').to_return(status: 200, body: '', headers: {}) |
137 | 137 | end
|
138 | 138 |
|
139 | 139 | it 'enqueues the job' do
|
|
188 | 188 | let(:raw_response) { modifiable_response.deep_dup }
|
189 | 189 |
|
190 | 190 | before do
|
| 191 | + stub_request(:get, 'https://github.com/me/my-amazing-repo/raw/branches/whatever/ja-JP/code/dont-collide-starter/astronaut1.png').to_return(status: 200, body: '', headers: {}) |
| 192 | + stub_request(:get, 'https://github.com/me/my-amazing-repo/raw/branches/whatever/ja-JP/code/dont-collide-starter/music.mp3').to_return(status: 200, body: '', headers: {}) |
| 193 | + stub_request(:get, 'https://github.com/me/my-amazing-repo/raw/branches/whatever/ja-JP/code/dont-collide-starter/video.mp4').to_return(status: 200, body: '', headers: {}) |
| 194 | + |
191 | 195 | project_dir_entry = raw_response['data']['repository']['object']['entries'].find do |entry|
|
192 | 196 | entry['name'] == 'dont-collide-starter'
|
193 | 197 | end
|
|
207 | 211 | end
|
208 | 212 | end
|
209 | 213 |
|
210 |
| - context 'with a graphql error response' do |
211 |
| - let(:raw_response) do |
212 |
| - { |
213 |
| - errors: [ |
214 |
| - { |
215 |
| - 'message' => 'Simulated INTERNAL_SERVER_ERROR message', |
216 |
| - 'locations' => [{ 'line' => 2, 'column' => 4 }], |
217 |
| - 'path' => %w[query repository object], |
218 |
| - 'extensions' => { 'code' => 'INTERNAL_SERVER_ERROR' } |
219 |
| - } |
220 |
| - ] |
221 |
| - } |
| 214 | + context 'when repository is not found' do |
| 215 | + let(:graphql_response) do |
| 216 | + GraphQL::Client::Response.new( |
| 217 | + { |
| 218 | + 'errors' => [ |
| 219 | + { |
| 220 | + 'message' => 'Simulated NOT_FOUND error message', |
| 221 | + 'locations' => [{ 'line' => 2, 'column' => 4 }], |
| 222 | + 'path' => %w[query repository], |
| 223 | + 'extensions' => { 'code' => 'NOT_FOUND' } |
| 224 | + } |
| 225 | + ] |
| 226 | + }, |
| 227 | + data: nil |
| 228 | + ) |
222 | 229 | end
|
223 | 230 |
|
224 | 231 | before do
|
225 |
| - stub_request(:post, 'https://api.github.com/graphql').to_return(status: 200, body: raw_response.to_json, headers: {}) |
| 232 | + allow(GithubApi::Client).to receive(:query).and_return(graphql_response) |
226 | 233 | end
|
227 | 234 |
|
228 |
| - it 'raises a GraphQL::Client::Error' do |
229 |
| - expect { described_class.perform_now(payload) }.to raise_error(GraphQL::Client::Error, /Simulated INTERNAL_SERVER_ERROR message/) |
| 235 | + it 'raises RepositoryNotFoundError' do |
| 236 | + expect do |
| 237 | + described_class.perform_now(payload) |
| 238 | + end.to raise_error(RepositoryNotFoundError, 'Repository not found: my-amazing-repo') |
230 | 239 | end
|
231 | 240 | end
|
232 | 241 | end
|
0 commit comments