Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/mindee/parsing/v2/job_webhook.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def initialize(server_response)
@id = server_response['id']
@created_at = parse_date(server_response['created_at'])
@status = server_response['status']
@error = ErrorResponse.new(server_response['error']) if server_response.key?('error')
@error = ErrorResponse.new(server_response['error']) unless server_response['error'].nil?
end

# RST display.
Expand Down
2 changes: 1 addition & 1 deletion sig/mindee/parsing/v2/job_webhook.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module Mindee
module V2
class JobWebhook
attr_reader created_at: DateTime?
attr_reader error: ErrorResponse
attr_reader error: ErrorResponse?
attr_reader id: String
attr_reader status: String

Expand Down
61 changes: 61 additions & 0 deletions spec/v2/parsing/job_webhook_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,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
Loading