Skip to content
This repository has been archived by the owner on May 25, 2022. It is now read-only.

Commit

Permalink
Feat[issuer]: find
Browse files Browse the repository at this point in the history
  • Loading branch information
benoror committed Mar 22, 2017
1 parent 6091902 commit e0000ab
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 6 deletions.
10 changes: 10 additions & 0 deletions lib/ditto/issuer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ def save
client.refresh_token = key
end

def self.find(id, token)
client = Ditto::Client.new
attrs = client.get("SearchEmisor/#{id}?Token=#{token}")
new(attrs)
end

def documents
@documents ||=
Ditto::Resource.new(
Expand All @@ -34,6 +40,10 @@ def documents
)
end

def token
client.token
end

private
def create_path
"SaveEmisorMaster/Emisor?UserId=#{Ditto.api_key}"
Expand Down
26 changes: 20 additions & 6 deletions spec/ditto/issuer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,16 +52,30 @@
end

describe '#find' do
it 'fails to find an issuer with wrong token', :vcr do
expect { Ditto::Issuer.find('123', 'meep') }.to raise_error(Faraday::ClientError)
end

it 'fails to find an unknown issuer', :vcr do
pending('pending to implement')
expect { Ditto::Issuer.find('123') }.to raise_error(Faraday::ClientError)
pending('this always returns the same issuer')
issuer1 = Ditto::Issuer.create(attributes)
issuer2 = Ditto::Issuer.find('123', issuer1.token)
expect(issuer1.id).to_not eq(issuer2.id)
end

it 'succeed to find same issuer', :vcr do
issuer1 = Ditto::Issuer.create(attributes)
issuer2 = Ditto::Issuer.find(issuer1.id, issuer1.token)
expect(issuer2.id).to eq(issuer1.id)
end

it 'succeed to find an issuer', :vcr do
pending('pending to implement')
it 'succeed to find different issuer', :vcr do
pending("this also returns the token's issuer, not the one we're looking for")
issuer1 = Ditto::Issuer.create(attributes)
issuer2 = Ditto::Issuer.find(issuer1.id)
expect(issuer2.id).to_not be_nil
issuer2 = Ditto::Issuer.create(attributes)
issuer3 = Ditto::Issuer.find(issuer1.id, issuer2.token)
expect(issuer3.id).to eq(issuer1.id)
expect(issuer3.id).to_not eq(issuer2.id)
end
end
end

0 comments on commit e0000ab

Please sign in to comment.