Skip to content

Commit

Permalink
53958 CHIP client initiate_check_in method (#11940)
Browse files Browse the repository at this point in the history
  • Loading branch information
randomsync authored Mar 1, 2023
1 parent 8944c00 commit 8a285a3
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
11 changes: 11 additions & 0 deletions modules/check_in/app/services/v2/chip/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,17 @@ def refresh_precheckin(token:)
raise e
end

##
# HTTP POST call to the CHIP API to initiate check-in
#
# @return [Faraday::Response]
#
def initiate_check_in(token:)
connection.post("/#{base_path}/actions/initiate-check-in/#{check_in_session.uuid}") do |req|
req.headers = default_headers.merge('Authorization' => "Bearer #{token}")
end
end

##
# HTTP DELETE call to the CHIP API to delete check-in/pre check-in data
#
Expand Down
25 changes: 25 additions & 0 deletions modules/check_in/spec/services/v2/chip/client_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,31 @@
end
end

describe '#initiate_check_in' do
let(:resp) { Faraday::Response.new(body: { 'uuid' => uuid }.to_json, status: 200) }
let(:token) { 'abc123' }

context 'when CHIP returns success' do
let(:resp) { Faraday::Response.new(body: { 'uuid' => uuid }.to_json, status: 200) }
let(:token) { 'abc123' }

before do
allow_any_instance_of(Faraday::Connection).to receive(:post).with(anything).and_return(resp)
end

it 'yields to block' do
expect_any_instance_of(Faraday::Connection).to receive(:post).with("/dev/actions/initiate-check-in/#{uuid}")
.and_yield(Faraday::Request.new)

subject.initiate_check_in(token: token)
end

it 'returns success response' do
expect(subject.initiate_check_in(token: token)).to eq(resp)
end
end
end

describe '#delete' do
context 'when CHIP returns successfully' do
let(:response) { Faraday::Response.new(body: 'Delete successful', status: 200) }
Expand Down

0 comments on commit 8a285a3

Please sign in to comment.