Skip to content

Commit

Permalink
Add signed workflow PDF endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
developer88 committed Nov 22, 2023
1 parent 5f17841 commit 9731052
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 4 deletions.
4 changes: 4 additions & 0 deletions lib/onfido/resources/workflow_run.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,9 @@ def find(workflow_run_id)
def all(query_params = {})
get(path: "workflow_runs?#{stringify_query_params(query_params)}")
end

def evidence(workflow_run_id)
get(path: "workflow_runs/#{workflow_run_id}/signed_evidence_file")
end
end
end
10 changes: 9 additions & 1 deletion spec/integrations/workflow_run_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,17 @@

describe '#all' do
it 'returns the workflow runs' do
response = workflow_run.all({ page: 1, sort: "asc" })
response = workflow_run.all({ page: 1, sort: 'asc' })

expect(response.count).to eq(2)
end
end

describe '#evidence' do
it 'returns the signed PDF' do
response = workflow_run.evidence(workflow_run_id)

expect(response[0..4]).to eq('%PDF-')
end
end
end
18 changes: 15 additions & 3 deletions spec/support/fake_onfido_api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
class FakeOnfidoAPI < Sinatra::Base # rubocop:disable Metrics/ClassLength
before do
begin
if request.content_type == "application/json; charset=utf-8"
if request.content_type == 'application/json; charset=utf-8'
body_parameters = JSON.parse(request.body.read)
params.merge!(body_parameters) if body_parameters
end
Expand Down Expand Up @@ -249,6 +249,10 @@ class FakeOnfidoAPI < Sinatra::Base # rubocop:disable Metrics/ClassLength
json_response(200, 'workflow_run.json')
end

get '/v3.6/workflow_runs/:id/signed_evidence_file' do
pdf_response(200, 'signed_workflow_run.pdf')
end

get '/v3.6/workflow_runs' do
json_response(200, 'workflow_runs.json')
end
Expand All @@ -270,9 +274,17 @@ class FakeOnfidoAPI < Sinatra::Base # rubocop:disable Metrics/ClassLength
private

def json_response(response_code, file_name)
content_type 'application/json; charset=utf-8'
fixture_response(response_code, file_name, 'application/json')
end

def fixture_response(response_code, file_name, custom_content_type)
content_type "#{custom_content_type}; charset=utf-8"
status response_code
File.open("#{File.dirname(__FILE__)}/fixtures/#{file_name}", 'rb').read
File.binread("#{File.dirname(__FILE__)}/fixtures/#{file_name}")
end

def pdf_response(response_code, file_name)
fixture_response(response_code, file_name, 'application/pdf')
end

def pagination_range
Expand Down
Binary file added spec/support/fixtures/signed_workflow_run.pdf
Binary file not shown.

0 comments on commit 9731052

Please sign in to comment.