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
19 changes: 19 additions & 0 deletions spec/client_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -431,4 +431,23 @@
expect(error.msg).to eq('Not found error')
end
end

it 'raises NotFoundError on 404 response with an invalid JSON body' do
client = Adyen::Client.new(api_key: 'api_key', env: :test)
mock_faraday_connection = double(Faraday::Connection)
error_body = "this is an error message"
mock_response = Faraday::Response.new(status: 404, body: error_body)

allow(Faraday).to receive(:new).and_return(mock_faraday_connection)
allow(mock_faraday_connection).to receive_message_chain(:headers, :[]=)
allow(mock_faraday_connection).to receive(:post).and_return(mock_response)

expect {
client.payment.payments_api.authorise({})
}.to raise_error(Adyen::NotFoundError) do |error|
expect(error.code).to eq(404)
expect(error.msg).to eq('Not found error')
end
end

end
54 changes: 54 additions & 0 deletions spec/lem_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,58 @@
expect(result.status)
.to eq(200)
end

it 'makes a legal_entities GET call' do
legal_entity_id = 'LE322JV223222D5F4K62J7465'
response_body = json_from_file('mocks/responses/LegalEntityManagement/get_legal_entity.json')

url = @shared_values[:client].service_url(@shared_values[:service], "legalEntities/#{legal_entity_id}",
@shared_values[:client].legal_entity_management.version)
WebMock.stub_request(:get, url)
.with(
headers: {
'x-api-key' => @shared_values[:client].api_key
}
)
.to_return(
body: response_body
)

result = @shared_values[:client].legal_entity_management.legal_entities_api.get_legal_entity(legal_entity_id)
response_hash = result.response

expect(result.status)
.to eq(200)
expect(response_hash)
.to eq(JSON.parse(response_body))
expect(response_hash)
.to be_a Adyen::HashWithAccessors
expect(response_hash)
.to be_a_kind_of Hash
end

it 'raises an error when calling legal_entities GET call' do
invalid_legal_entity_id = 'NON_EXISTENT_ID'
error_response_body = { status: 404, errorCode: '100', message: 'Legal entity not found', errorType: 'validation' }.to_json

url = @shared_values[:client].service_url(@shared_values[:service], "legalEntities/#{invalid_legal_entity_id}",
@shared_values[:client].legal_entity_management.version)
WebMock.stub_request(:get, url)
.with(
headers: {
'x-api-key' => @shared_values[:client].api_key
}
)
.to_return(
status: 404,
body: error_response_body
)

expect do
@shared_values[:client].legal_entity_management.legal_entities_api.get_legal_entity(invalid_legal_entity_id)
end.to raise_error(Adyen::NotFoundError) do |error|
expect(error.code).to eq(404)
expect(error.msg).to eq('Legal entity not found ErrorCode: 100')
end
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"id": "LE322JV223222D5F4K62J7465",
"type": "Organization",
"status": "Active",
"legalEntityCode": "LE322JV223222D5F4K62J7465",
"reference": "MyCompany",
"capabilities": [
{
"id": "capability_1",
"requested": true,
"allowed": true
}
]
}