-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathjob_webhook_spec.rb
More file actions
61 lines (51 loc) · 1.9 KB
/
job_webhook_spec.rb
File metadata and controls
61 lines (51 loc) · 1.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# frozen_string_literal: true
require 'mindee'
RSpec.describe Mindee::Parsing::V2::JobWebhook do
describe '#initialize' do
context 'when error key is present but value is nil' do
it 'does not raise an error and sets @error to nil' do
server_response = {
'id' => '12345678-1234-1234-1234-123456789012',
'status' => 'Processing',
'error' => nil,
}
webhook = described_class.new(server_response)
expect(webhook.id).to eq('12345678-1234-1234-1234-123456789012')
expect(webhook.status).to eq('Processing')
expect(webhook.error).to be_nil
end
end
context 'when error key is absent' do
it 'does not raise an error and sets @error to nil' do
server_response = {
'id' => '12345678-1234-1234-1234-123456789012',
'status' => 'Processing',
}
webhook = described_class.new(server_response)
expect(webhook.id).to eq('12345678-1234-1234-1234-123456789012')
expect(webhook.status).to eq('Processing')
expect(webhook.error).to be_nil
end
end
context 'when error key is present with valid error data' do
it 'creates an ErrorResponse object' do
server_response = {
'id' => '12345678-1234-1234-1234-123456789012',
'status' => 'Failed',
'error' => {
'status' => 500,
'detail' => 'Internal server error',
'title' => 'Server Error',
'code' => 'INTERNAL_ERROR',
},
}
webhook = described_class.new(server_response)
expect(webhook.id).to eq('12345678-1234-1234-1234-123456789012')
expect(webhook.status).to eq('Failed')
expect(webhook.error).to be_a(Mindee::Parsing::V2::ErrorResponse)
expect(webhook.error.status).to eq(500)
expect(webhook.error.detail).to eq('Internal server error')
end
end
end
end