|
180 | 180 | envelope_download = EnvelopeDownload.last
|
181 | 181 | expect(envelope_download.envelope_community).to eq(envelope_community)
|
182 | 182 | expect(envelope_download.status).to eq('pending')
|
| 183 | + |
| 184 | + expect_json_sizes(2) |
| 185 | + expect_json('enqueued_at', nil) |
| 186 | + expect_json('status', 'pending') |
183 | 187 | end
|
184 | 188 | end
|
185 | 189 |
|
186 | 190 | # rubocop:todo RSpec/NestedGroups
|
187 | 191 | context 'with envelope download' do # rubocop:todo RSpec/MultipleMemoizedHelpers, RSpec/NestedGroups
|
188 | 192 | # rubocop:enable RSpec/NestedGroups
|
189 |
| - before do |
| 193 | + let!(:envelope_download) do |
190 | 194 | create(
|
191 | 195 | :envelope_download,
|
192 | 196 | envelope_community:,
|
|
207 | 211 | it 'returns `in progress`' do
|
208 | 212 | expect { perform_request }.not_to change(EnvelopeDownload, :count)
|
209 | 213 | expect_status(:ok)
|
| 214 | + expect_json_sizes(2) |
| 215 | + expect_json('started_at', envelope_download.started_at.as_json) |
210 | 216 | expect_json('status', 'in_progress')
|
211 | 217 | end
|
212 | 218 | end
|
|
216 | 222 | # rubocop:todo RSpec/NestedGroups
|
217 | 223 | context 'failed' do # rubocop:todo RSpec/ContextWording, RSpec/MultipleMemoizedHelpers, RSpec/NestedGroups
|
218 | 224 | # rubocop:enable RSpec/NestedGroups
|
219 |
| - let(:status) { :finished } |
220 | 225 | let(:internal_error_message) { Faker::Lorem.sentence }
|
| 226 | + let(:status) { :finished } |
| 227 | + let(:url) { Faker::Internet.url } |
221 | 228 |
|
222 | 229 | it 'returns `failed`' do
|
223 | 230 | expect { perform_request }.not_to change(EnvelopeDownload, :count)
|
224 | 231 | expect_status(:ok)
|
| 232 | + expect_json_sizes(3) |
| 233 | + expect_json('finished_at', envelope_download.finished_at.as_json) |
225 | 234 | expect_json('status', 'failed')
|
| 235 | + expect_json('url', url) |
226 | 236 | end
|
227 | 237 | end
|
228 | 238 | # rubocop:enable RSpec/MultipleMemoizedHelpers
|
|
238 | 248 | it 'returns `finished` and URL' do
|
239 | 249 | expect { perform_request }.not_to change(EnvelopeDownload, :count)
|
240 | 250 | expect_status(:ok)
|
| 251 | + expect_json_sizes(3) |
| 252 | + expect_json('finished_at', envelope_download.finished_at.as_json) |
241 | 253 | expect_json('status', 'finished')
|
242 | 254 | expect_json('url', url)
|
243 | 255 | end
|
|
280 | 292 | end
|
281 | 293 |
|
282 | 294 | context 'with valid token' do
|
| 295 | + let(:now) { Time.current.change(usec: 0) } |
| 296 | + |
283 | 297 | context 'without envelope download' do # rubocop:todo RSpec/NestedGroups
|
284 | 298 | # rubocop:todo RSpec/MultipleExpectations
|
285 |
| - it 'creates new pending download and enqueues job' do |
| 299 | + it 'creates new pending download and enqueues job' do # rubocop:todo RSpec/ExampleLength |
286 | 300 | # rubocop:enable RSpec/MultipleExpectations
|
287 |
| - expect { perform_request }.to change(EnvelopeDownload, :count).by(1) |
| 301 | + travel_to now do |
| 302 | + expect { perform_request }.to change(EnvelopeDownload, :count).by(1) |
| 303 | + end |
| 304 | + |
288 | 305 | expect_status(:created)
|
289 | 306 |
|
290 | 307 | envelope_download = EnvelopeDownload.last
|
291 | 308 | expect(envelope_download.envelope_community).to eq(envelope_community)
|
292 | 309 | expect(envelope_download.status).to eq('pending')
|
293 | 310 |
|
| 311 | + expect_json_sizes(2) |
| 312 | + expect_json('enqueued_at', now.as_json) |
| 313 | + expect_json('status', 'pending') |
| 314 | + |
294 | 315 | expect(ActiveJob::Base.queue_adapter.enqueued_jobs.size).to eq(1)
|
295 | 316 |
|
296 | 317 | job = ActiveJob::Base.queue_adapter.enqueued_jobs.first
|
|
299 | 320 | end
|
300 | 321 | end
|
301 | 322 |
|
| 323 | + # rubocop:todo RSpec/MultipleMemoizedHelpers |
302 | 324 | context 'with envelope download' do # rubocop:todo RSpec/NestedGroups
|
303 | 325 | let!(:envelope_download) do
|
304 | 326 | create(:envelope_download, :finished, envelope_community:)
|
305 | 327 | end
|
306 | 328 |
|
307 | 329 | it 'enqueues job for existing download' do
|
308 |
| - expect { perform_request }.to not_change(EnvelopeDownload, :count) |
309 |
| - .and enqueue_job(DownloadEnvelopesJob).with(envelope_download.id) |
| 330 | + travel_to now do |
| 331 | + expect { perform_request }.to not_change(EnvelopeDownload, :count) |
| 332 | + .and enqueue_job(DownloadEnvelopesJob).with(envelope_download.id) |
| 333 | + end |
| 334 | + |
310 | 335 | expect_status(:created)
|
311 | 336 | expect(envelope_download.reload.status).to eq('pending')
|
| 337 | + |
| 338 | + expect_json_sizes(2) |
| 339 | + expect_json('enqueued_at', now.as_json) |
| 340 | + expect_json('status', 'pending') |
312 | 341 | end
|
313 | 342 | end
|
| 343 | + # rubocop:enable RSpec/MultipleMemoizedHelpers |
314 | 344 | end
|
315 | 345 | end
|
316 | 346 | end
|
0 commit comments