Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DPL-670-8 Add Sequencescape API Key config for V2 API #279

Merged
merged 3 commits into from
Dec 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions lib/sequencescape_client_v2.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ class SequencescapeClientV2::Model < JsonApiClient::Resource # rubocop:todo Styl
# set the api base url in an abstract base class
self.site = "#{Rails.configuration.ss_api_v2_uri}/api/v2/"
self.sync = false

# set the api key in the header for all requests
connection_options[:headers] = { 'X-Sequencescape-Client-Id' => Rails.configuration.ss_authorisation }
end

class SequencescapeClientV2::Asset < SequencescapeClientV2::Model
Expand Down
48 changes: 48 additions & 0 deletions spec/lib/sequencescape_client_v2_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# frozen_string_literal: true

require 'rails_helper'
require './lib/sequencescape_client_v2'

RSpec.describe SequencescapeClientV2 do
describe 'SequencescapeClientV2::Model' do
it 'sets the api base url in an abstract base class' do
expect(SequencescapeClientV2::Model.site).to eq("#{Rails.configuration.ss_api_v2_uri}/api/v2/")
end

it 'sets the sync attribute to false' do
expect(SequencescapeClientV2::Model.sync).to be_falsey
end

it 'sets the api key in the connection options headers' do
headers = SequencescapeClientV2::Model.connection_options[:headers]
expect(headers['X-Sequencescape-Client-Id']).to eq(Rails.configuration.ss_authorisation)
end
end

# Checks a class using the SequencescapeClientV2::Model class has the correct data
describe 'SequencescapeClientV2::Plate' do
it 'sets the api base url in an abstract base class' do
expect(SequencescapeClientV2::Plate.site).to eq("#{Rails.configuration.ss_api_v2_uri}/api/v2/")
end

it 'sets the sync attribute to true' do
expect(SequencescapeClientV2::Plate.sync).to be_truthy
end

it 'sets the api key in the connection options headers' do
headers = SequencescapeClientV2::Plate.connection_options[:headers]
expect(headers['X-Sequencescape-Client-Id']).to eq(Rails.configuration.ss_authorisation)
end

it 'has the api key header set correctly in the requests' do
# We can assert that the resource has the correct api key in the headers by the fact it is
# being successfully stubbed
stub_request(:get, %r{api/v2/plates})
# If you changed this header key or value it would fail as it would not reflect reality
.with(headers: { 'X-Sequencescape-Client-Id' => Rails.configuration.ss_authorisation })
.to_return(File.new('./spec/support/responses/sequencescape/v2/plate_uuid_response.txt'))
plate = SequencescapeClientV2::Plate.first
expect(plate.type).to eq('plates')
end
end
end
Loading