|
60 | 60 | expect(result.status) |
61 | 61 | .to eq(200) |
62 | 62 | end |
| 63 | + |
| 64 | + it 'makes a legal_entities GET call' do |
| 65 | + legal_entity_id = 'LE322JV223222D5F4K62J7465' |
| 66 | + response_body = json_from_file('mocks/responses/LegalEntityManagement/get_legal_entity.json') |
| 67 | + |
| 68 | + url = @shared_values[:client].service_url(@shared_values[:service], "legalEntities/#{legal_entity_id}", |
| 69 | + @shared_values[:client].legal_entity_management.version) |
| 70 | + WebMock.stub_request(:get, url) |
| 71 | + .with( |
| 72 | + headers: { |
| 73 | + 'x-api-key' => @shared_values[:client].api_key |
| 74 | + } |
| 75 | + ) |
| 76 | + .to_return( |
| 77 | + body: response_body |
| 78 | + ) |
| 79 | + |
| 80 | + result = @shared_values[:client].legal_entity_management.legal_entities_api.get_legal_entity(legal_entity_id) |
| 81 | + response_hash = result.response |
| 82 | + |
| 83 | + expect(result.status) |
| 84 | + .to eq(200) |
| 85 | + expect(response_hash) |
| 86 | + .to eq(JSON.parse(response_body)) |
| 87 | + expect(response_hash) |
| 88 | + .to be_a Adyen::HashWithAccessors |
| 89 | + expect(response_hash) |
| 90 | + .to be_a_kind_of Hash |
| 91 | + end |
| 92 | + |
| 93 | + it 'raises an error when calling legal_entities GET call' do |
| 94 | + invalid_legal_entity_id = 'NON_EXISTENT_ID' |
| 95 | + error_response_body = { status: 404, errorCode: '100', message: 'Legal entity not found', errorType: 'validation' }.to_json |
| 96 | + |
| 97 | + url = @shared_values[:client].service_url(@shared_values[:service], "legalEntities/#{invalid_legal_entity_id}", |
| 98 | + @shared_values[:client].legal_entity_management.version) |
| 99 | + WebMock.stub_request(:get, url) |
| 100 | + .with( |
| 101 | + headers: { |
| 102 | + 'x-api-key' => @shared_values[:client].api_key |
| 103 | + } |
| 104 | + ) |
| 105 | + .to_return( |
| 106 | + status: 404, |
| 107 | + body: error_response_body |
| 108 | + ) |
| 109 | + |
| 110 | + expect do |
| 111 | + @shared_values[:client].legal_entity_management.legal_entities_api.get_legal_entity(invalid_legal_entity_id) |
| 112 | + end.to raise_error(Adyen::NotFoundError) do |error| |
| 113 | + expect(error.code).to eq(404) |
| 114 | + expect(error.msg).to eq('Legal entity not found ErrorCode: 100') |
| 115 | + end |
| 116 | + end |
63 | 117 | end |
0 commit comments