Skip to content

Commit

Permalink
fix(encoding) Fix identifier encoding
Browse files Browse the repository at this point in the history
  • Loading branch information
ivannovosad committed Nov 22, 2023
1 parent 9bd9b5f commit 19ed940
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
lago-ruby-client (0.51.0.pre.beta)
lago-ruby-client (0.52.2.pre.beta)
jwt
openssl

Expand Down
2 changes: 1 addition & 1 deletion lib/lago/api/connection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def put(path = uri.path, identifier:, body:)
end

def get(path = uri.path, identifier:)
uri_path = identifier.nil? ? path : "#{path}/#{identifier}"
uri_path = identifier.nil? ? path : "#{path}/#{URI.encode_www_form_component(identifier)}"
response = http_client.send_request(
'GET',
uri_path,
Expand Down
23 changes: 22 additions & 1 deletion spec/lago/api/connection_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@
subject(:connection) do
described_class.new(
'fake-api-key',
URI('https://testapi.example.org/')
uri
)
end

let(:uri) { URI('https://testapi.example.org') }

context 'when an unsuccessful request is made' do
before do
stub_request(:post, 'https://testapi.example.org/NOTFOUND')
Expand All @@ -23,4 +25,23 @@
}
end
end

describe '#get' do
let(:identifier) { 'gid://app/Customer/1234' }
let(:http_client) { connection.send(:http_client) }

before do
stub_request(:get, 'https://testapi.example.org:443/gid:%2F%2Fapp%2FCustomer%2F1234')

allow(URI).to receive(:encode_www_form_component)
.with(identifier)
.and_return('gid:%2F%2Fapp%2FCustomer%2F1234')

connection.get(identifier:)
end

it 'encodes the identifier' do
expect(URI).to have_received(:encode_www_form_component).with(identifier)
end
end
end

0 comments on commit 19ed940

Please sign in to comment.