Skip to content

Commit

Permalink
feat(ont-runs-filter): Adds experiment_name and state to ont runs api…
Browse files Browse the repository at this point in the history
… filters
  • Loading branch information
BenTopping committed Oct 18, 2023
1 parent 462af2a commit da485d9
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 0 deletions.
2 changes: 2 additions & 0 deletions app/resources/v1/ont/run_resource.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ class RunResource < JSONAPI::Resource
foreign_key: 'ont_run_id',
class_name: 'Flowcell'

filters :experiment_name, :state

paginator :paged

def self.default_sort
Expand Down
59 changes: 59 additions & 0 deletions spec/requests/v1/ont/runs_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,65 @@ def json
end
end

describe 'filter' do
let(:run1) { create(:ont_gridion_run, flowcell_count: 5, state: 'pending') }
let(:run2) { create(:ont_gridion_run, flowcell_count: 5, state: 'restart') }

describe 'experiment_name' do
before do
get "#{v1_ont_runs_path}?filter[experiment_name]=#{run1.experiment_name}",
headers: json_api_headers
end

it 'has a success status' do
expect(response).to have_http_status(:success), response.body
end

it 'returns a list of runs' do
expect(json['data'].length).to eq(1)
end

it 'returns the correct attributes' do
json = ActiveSupport::JSON.decode(response.body)
run_attributes = json['data'][0]['attributes']

expect(run_attributes).to include(
'ont_instrument_id' => run1.instrument.id,
'experiment_name' => run1.experiment_name,
'state' => run1.state,
'created_at' => run1.created_at.to_fs(:us)
)
end
end

describe 'state' do
before do
get "#{v1_ont_runs_path}?filter[state]=#{run1.state}",
headers: json_api_headers
end

it 'has a success status' do
expect(response).to have_http_status(:success), response.body
end

it 'returns a list of runs' do
expect(json['data'].length).to eq(1)
end

it 'returns the correct attributes' do
json = ActiveSupport::JSON.decode(response.body)
run_attributes = json['data'][0]['attributes']

expect(run_attributes).to include(
'ont_instrument_id' => run1.instrument.id,
'experiment_name' => run1.experiment_name,
'state' => run1.state,
'created_at' => run1.created_at.to_fs(:us)
)
end
end
end

describe 'create' do
context 'on success' do
let(:instrument) { create(:ont_gridion) }
Expand Down

0 comments on commit da485d9

Please sign in to comment.