From 8dd171d47f544a64ddd525e2be0ac616fcc39870 Mon Sep 17 00:00:00 2001 From: Stephen MacVicar Date: Thu, 16 Nov 2023 10:01:29 -0500 Subject: [PATCH 01/12] add migration for tags --- .../db/migrations/009_add_request_tags.rb | 18 ++++++++++++++++++ lib/inferno/db/schema.rb | 19 +++++++++++++++++++ 2 files changed, 37 insertions(+) create mode 100644 lib/inferno/db/migrations/009_add_request_tags.rb diff --git a/lib/inferno/db/migrations/009_add_request_tags.rb b/lib/inferno/db/migrations/009_add_request_tags.rb new file mode 100644 index 000000000..cbaf6c2f9 --- /dev/null +++ b/lib/inferno/db/migrations/009_add_request_tags.rb @@ -0,0 +1,18 @@ +Sequel.migration do + change do + create_table :tags do + column :id, String, primary_key: true, null: false, size: 36 + column :name, String, size: 255, null: false + + index :name, unique: true + end + + create_table :requests_tags do + foreign_key :tags_id, :tags, index: true, type: String, null: false, size: 36, key: [:id] + foreign_key :requests_id, :requests, index: true, type: Integer, null: false, key: [:index] + + index [:tags_id, :requests_id], unique: true + index [:requests_id, :tags_id], unique: true + end + end +end diff --git a/lib/inferno/db/schema.rb b/lib/inferno/db/schema.rb index 9a25c25cc..324dd96cb 100644 --- a/lib/inferno/db/schema.rb +++ b/lib/inferno/db/schema.rb @@ -4,6 +4,15 @@ Integer :version, :default=>0, :null=>false end + create_table(:tags, :ignore_index_errors=>true) do + String :id, :size=>36, :null=>false + String :name, :size=>255, :null=>false + + primary_key [:id] + + index [:name], :unique=>true + end + create_table(:test_sessions) do String :id, :size=>36, :null=>false String :test_suite_id, :size=>255, :null=>false @@ -121,5 +130,15 @@ index [:requests_id] index [:results_id] end + + create_table(:requests_tags, :ignore_index_errors=>true) do + foreign_key :tags_id, :tags, :type=>String, :size=>36, :null=>false, :key=>[:id] + foreign_key :requests_id, :requests, :null=>false, :key=>[:index] + + index [:requests_id] + index [:requests_id, :tags_id], :unique=>true + index [:tags_id] + index [:tags_id, :requests_id], :unique=>true + end end end From 60129a900e69b6db5b5b8cd64cb998152688a851 Mon Sep 17 00:00:00 2001 From: Stephen MacVicar Date: Fri, 17 Nov 2023 11:41:30 -0500 Subject: [PATCH 02/12] add/update entities and repositories to persist tags --- lib/inferno/entities/request.rb | 15 +++++- lib/inferno/repositories/requests.rb | 55 +++++++++++++++++----- lib/inferno/repositories/tags.rb | 18 +++++++ spec/factories/request.rb | 2 + spec/inferno/repositories/requests_spec.rb | 34 ++++++------- 5 files changed, 95 insertions(+), 29 deletions(-) create mode 100644 lib/inferno/repositories/tags.rb diff --git a/lib/inferno/entities/request.rb b/lib/inferno/entities/request.rb index 9ea0a6907..2832846a9 100644 --- a/lib/inferno/entities/request.rb +++ b/lib/inferno/entities/request.rb @@ -34,7 +34,7 @@ class Request < Entity ATTRIBUTES = [ :id, :index, :verb, :url, :direction, :name, :status, :request_body, :response_body, :result_id, :test_session_id, :created_at, - :updated_at, :headers + :updated_at, :headers, :tags ].freeze SUMMARY_FIELDS = [ :id, :index, :url, :verb, :direction, :name, :status, :result_id, :created_at, :updated_at @@ -48,6 +48,18 @@ def initialize(params) @name = params[:name]&.to_sym @headers = params[:headers]&.map { |header| header.is_a?(Hash) ? Header.new(header) : header } || [] + format_tags(params[:tags] || []) + end + + def format_tags(raw_tags) + @tags = raw_tags.map do |tag| + case tag + when Hash + tag[:name] + when String + tag + end + end end # @return [Hash] @@ -124,6 +136,7 @@ def to_hash test_session_id:, request_headers: request_headers.map(&:to_hash), response_headers: response_headers.map(&:to_hash), + tags:, created_at:, updated_at: }.compact diff --git a/lib/inferno/repositories/requests.rb b/lib/inferno/repositories/requests.rb index b70a32126..ee42a04c2 100644 --- a/lib/inferno/repositories/requests.rb +++ b/lib/inferno/repositories/requests.rb @@ -1,19 +1,19 @@ module Inferno module Repositories class Requests < Repository - include Import[headers_repo: 'inferno.repositories.headers'] + include Import[ + headers_repo: 'inferno.repositories.headers', + tags_repo: 'inferno.repositories.tags' + ] def create(params) request = self.class::Model.create(db_params(params)) - request_headers = (params[:request_headers] || []).map do |header| - request.add_header(header.merge(request_id: request.index, type: 'request')) - end - response_headers = (params[:response_headers] || []).map do |header| - request.add_header(header.merge(request_id: request.index, type: 'response')) - end + headers = create_headers(request, params) - headers = (request_headers + response_headers).map { |header| headers_repo.build_entity(header.to_hash) } + params[:tags]&.each do |tag| + request.add_tag(name: tag, request_id: request.index) + end build_entity( request.to_hash @@ -22,6 +22,17 @@ def create(params) ) end + def create_headers(request, params) + request_headers = (params[:request_headers] || []).map do |header| + request.add_header(header.merge(request_id: request.index, type: 'request')) + end + response_headers = (params[:response_headers] || []).map do |header| + request.add_header(header.merge(request_id: request.index, type: 'response')) + end + + (request_headers + response_headers).map { |header| headers_repo.build_entity(header.to_hash) } + end + def find(id) result = self.class::Model @@ -68,14 +79,25 @@ def requests_for_result(result_id) def json_serializer_options { - include: :headers + include: [:headers, :tags] } end class Model < Sequel::Model(db) - many_to_many :result, class: 'Inferno::Repositories::Results::Model', join_table: :requests_results, - left_key: :request_id, right_key: :result_id - one_to_many :headers, class: 'Inferno::Repositories::Headers::Model', key: :request_id + many_to_many :result, + class: 'Inferno::Repositories::Results::Model', + join_table: :requests_results, + left_key: :request_id, + right_key: :result_id + many_to_many :tags, + class: 'Inferno::Repositories::Tags::Model', + join_table: :requests_tags, + left_key: :requests_id, + right_key: :tags_id, + adder: :add_tag + one_to_many :headers, + class: 'Inferno::Repositories::Headers::Model', + key: :request_id def before_create self.id = SecureRandom.uuid @@ -84,6 +106,15 @@ def before_create self.updated_at ||= time super end + + def add_tag(tag_hash) + tag = Tags::Model.find_or_create(tag_hash.slice(:name)) + + Inferno::Application['db.connection'][:requests_tags].insert( + tags_id: tag.id, + requests_id: index + ) + end end end end diff --git a/lib/inferno/repositories/tags.rb b/lib/inferno/repositories/tags.rb new file mode 100644 index 000000000..1f7a44247 --- /dev/null +++ b/lib/inferno/repositories/tags.rb @@ -0,0 +1,18 @@ +module Inferno + module Repositories + class Tags < Repository + class Model < Sequel::Model(db) + many_to_many :requests, + class: 'Inferno::Repositories::Requests::Model', + join_table: :requests_tags, + left_key: :tags_id, + right_key: :requests_id + + def before_create + self.id = SecureRandom.uuid + super + end + end + end + end +end diff --git a/spec/factories/request.rb b/spec/factories/request.rb index dfece6edb..22d1b9fe7 100644 --- a/spec/factories/request.rb +++ b/spec/factories/request.rb @@ -27,6 +27,8 @@ ] end + tags { [] } + request_body { nil } sequence(:response_body) { |n| "RESPONSE_BODY #{n}" } diff --git a/spec/inferno/repositories/requests_spec.rb b/spec/inferno/repositories/requests_spec.rb index 0f98d1e19..79b5d815c 100644 --- a/spec/inferno/repositories/requests_spec.rb +++ b/spec/inferno/repositories/requests_spec.rb @@ -5,23 +5,23 @@ let(:test_run) { repo_create(:test_run) } let(:result) { repo_create(:result, test_run:) } let(:test_session) { test_run.test_session } + let(:request_params) do + { + verb: 'get', + url: 'http://example.com', + direction: 'outgoing', + status: 200, + request_body: 'REQUEST_BODY', + response_body: 'RESPONSE_BODY', + result_id: result.id, + test_session_id: test_session.id, + request_headers: [{ name: 'REQUEST_HEADER_NAME', value: 'REQUEST_HEADER_VALUE', type: 'request' }], + response_headers: [{ name: 'RESPONSE_HEADER_NAME', value: 'RESPONSE_HEADER_VALUE', type: 'response' }], + tags: ['abc', 'def'] + } + end describe '#create' do - let(:request_params) do - { - verb: 'get', - url: 'http://example.com', - direction: 'outgoing', - status: 200, - request_body: 'REQUEST_BODY', - response_body: 'RESPONSE_BODY', - result_id: result.id, - test_session_id: test_session.id, - request_headers: [{ name: 'REQUEST_HEADER_NAME', value: 'REQUEST_HEADER_VALUE', type: 'request' }], - response_headers: [{ name: 'RESPONSE_HEADER_NAME', value: 'RESPONSE_HEADER_VALUE', type: 'response' }] - } - end - it 'persists a request' do request = repo.create(request_params) @@ -67,7 +67,7 @@ end describe '#find_full_request' do - let(:persisted_request) { repo_create(:request) } + let(:persisted_request) { repo_create(:request, request_params) } it 'returns a complete request' do request = repo.find_full_request(persisted_request.id) @@ -86,6 +86,8 @@ expect(request.headers.length).to eq(persisted_request.headers.length) expect(request.request_headers.length).to eq(persisted_request.request_headers.length) expect(request.response_headers.length).to eq(persisted_request.response_headers.length) + expect(request.tags).to be_present + expect(request.tags).to match_array(persisted_request.tags) end end From 405bd616c4b9de78a763580d08e70b118cbdce7f Mon Sep 17 00:00:00 2001 From: Stephen MacVicar Date: Mon, 20 Nov 2023 12:57:16 -0500 Subject: [PATCH 03/12] WIP --- lib/inferno/dsl/request_storage.rb | 8 ++++++++ lib/inferno/repositories/requests.rb | 24 ++++++++++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/lib/inferno/dsl/request_storage.rb b/lib/inferno/dsl/request_storage.rb index 14e4e938c..06796a0ea 100644 --- a/lib/inferno/dsl/request_storage.rb +++ b/lib/inferno/dsl/request_storage.rb @@ -36,6 +36,14 @@ def resource request&.resource end + def load_tagged_requests(*tags) + return [] if tags.blank? + + Repositories::Requests.new.tagged_requests(self.test_session_id, tags).tap do |tagged_requests| + requests.concat(tagged_requests) + end + end + # @private def named_request(name) requests.find { |request| request.name == self.class.config.request_name(name.to_sym) } diff --git a/lib/inferno/repositories/requests.rb b/lib/inferno/repositories/requests.rb index ee42a04c2..a40f11c5a 100644 --- a/lib/inferno/repositories/requests.rb +++ b/lib/inferno/repositories/requests.rb @@ -67,6 +67,17 @@ def find_named_request(test_session_id, name) build_entity(result) end + def tagged_requests(test_session_id, tags) + self.class::Model + .tagged_requests(test_session_id, tags) + .all + .map! do |result_hash| + build_entity(result_hash) + .to_json_data(json_serializer_options) + .deep_symbolize_keys! + end + end + def requests_for_result(result_id) self.class::Model .order(:index) @@ -115,6 +126,19 @@ def add_tag(tag_hash) requests_id: index ) end + + def self.tagged_requests_sql + <<~SQL.gsub(/\s+/, ' ').freeze + SELECT * from requests a + WHERE test_session_id = :test_session_id + SQL + # and tags in :tags through the requests_tags join table + # and result_id belongs to the most recent result for that runnable + end + + def self.tagged_requests(test_session_id, tags) + fetch(tagged_requests_sql, test_session_id:, tags:) + end end end end From 04b13a6dd42a37985a67891c86c4d457eed5739e Mon Sep 17 00:00:00 2001 From: Stephen MacVicar Date: Mon, 20 Nov 2023 14:32:46 -0500 Subject: [PATCH 04/12] update sql for finding requests via tags --- lib/inferno/repositories/requests.rb | 38 ++++++++++++++++++++++------ 1 file changed, 30 insertions(+), 8 deletions(-) diff --git a/lib/inferno/repositories/requests.rb b/lib/inferno/repositories/requests.rb index a40f11c5a..0aadc89c4 100644 --- a/lib/inferno/repositories/requests.rb +++ b/lib/inferno/repositories/requests.rb @@ -70,11 +70,13 @@ def find_named_request(test_session_id, name) def tagged_requests(test_session_id, tags) self.class::Model .tagged_requests(test_session_id, tags) - .all - .map! do |result_hash| - build_entity(result_hash) - .to_json_data(json_serializer_options) - .deep_symbolize_keys! + .to_a + .map! do |request| + build_entity( + request + .to_json_data(json_serializer_options) + .deep_symbolize_keys! + ) end end @@ -129,15 +131,35 @@ def add_tag(tag_hash) def self.tagged_requests_sql <<~SQL.gsub(/\s+/, ' ').freeze - SELECT * from requests a - WHERE test_session_id = :test_session_id + select * from requests where requests.id in ( + select r.id request_id from requests r + inner join requests_tags rt on r.id = rt.requests_id + inner join tags t on rt.tags_id = t.id + where r.test_session_id = :test_session_id + and r.result_id in ( + SELECT a.id FROM results a + WHERE a.test_session_id = r.test_session_id + AND a.id IN ( + SELECT id + FROM results b + WHERE (b.test_session_id = a.test_session_id AND b.test_id = a.test_id) OR + (b.test_session_id = a.test_session_id AND b.test_group_id = a.test_group_id) OR + (b.test_session_id = a.test_session_id AND b.test_suite_id = a.test_suite_id) + ORDER BY updated_at DESC + LIMIT 1 + ) + ) + and t.name in :tags + group by r.id, t.id + having count(*) = :tag_count + ); SQL # and tags in :tags through the requests_tags join table # and result_id belongs to the most recent result for that runnable end def self.tagged_requests(test_session_id, tags) - fetch(tagged_requests_sql, test_session_id:, tags:) + fetch(tagged_requests_sql, test_session_id:, tags:, tag_count: tags.length) end end end From 8129378b0c4c5f38294508313516d9c73c054455 Mon Sep 17 00:00:00 2001 From: Stephen MacVicar Date: Mon, 20 Nov 2023 14:37:02 -0500 Subject: [PATCH 05/12] add basic unit tests for tagged requests --- spec/inferno/repositories/requests_spec.rb | 31 ++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/spec/inferno/repositories/requests_spec.rb b/spec/inferno/repositories/requests_spec.rb index 79b5d815c..ff948a308 100644 --- a/spec/inferno/repositories/requests_spec.rb +++ b/spec/inferno/repositories/requests_spec.rb @@ -129,4 +129,35 @@ expect(request.headers).to be_present end end + + describe '#tagged_requests' do + it 'returns an empty array when no requests match' do + request = repo_create(:request, request_params) + + requests = repo.tagged_requests(request.test_session_id, [SecureRandom.uuid]) + expect(requests).to be_an(Array) + expect(requests.length).to eq(1) + end + + it 'returns requests matching a tag' do + request = repo_create(:request, request_params) + tags = request.tags + + tags.each do |tag| + requests = repo.tagged_requests(request.test_session_id, [tag]) + + expect(requests.length).to eq(1) + expect(requests.first.id).to eq(request.id) + end + end + + it 'returns requests matching all tags' do + request = repo_create(:request, request_params) + + requests = repo.tagged_requests(request.test_session_id, request.tags) + + expect(requests.length).to eq(1) + expect(requests.first.id).to eq(request.id) + end + end end From fba385b2fcde46e5afe17d245d3db6b651346a5c Mon Sep 17 00:00:00 2001 From: Stephen MacVicar Date: Mon, 20 Nov 2023 15:03:52 -0500 Subject: [PATCH 06/12] add spec to verify that only requests from most recent results are returned --- spec/inferno/repositories/requests_spec.rb | 27 ++++++++++++++++++---- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/spec/inferno/repositories/requests_spec.rb b/spec/inferno/repositories/requests_spec.rb index ff948a308..b1d3b9fe6 100644 --- a/spec/inferno/repositories/requests_spec.rb +++ b/spec/inferno/repositories/requests_spec.rb @@ -131,16 +131,16 @@ end describe '#tagged_requests' do - it 'returns an empty array when no requests match' do - request = repo_create(:request, request_params) + let(:request) { repo_create(:request, request_params) } + it 'returns an empty array when no requests match' do requests = repo.tagged_requests(request.test_session_id, [SecureRandom.uuid]) + expect(requests).to be_an(Array) expect(requests.length).to eq(1) end it 'returns requests matching a tag' do - request = repo_create(:request, request_params) tags = request.tags tags.each do |tag| @@ -152,12 +152,29 @@ end it 'returns requests matching all tags' do - request = repo_create(:request, request_params) - requests = repo.tagged_requests(request.test_session_id, request.tags) expect(requests.length).to eq(1) expect(requests.first.id).to eq(request.id) end + + it 'only returns requests from the most recent result for a runnable' do + new_request = + repo_create( + :request, + test_session_id: request.test_session_id, + result: repo_create( + :result, + test_session_id: request.test_session_id, + updated_at: Time.now + 1.minute + ), + tags: request.tags + ) + + requests = repo.tagged_requests(request.test_session_id, request.tags) + + expect(requests.length).to eq(1) + expect(requests.first.id).to eq(new_request.id) + end end end From add1c561c28211097181335eb5a358cf496750d0 Mon Sep 17 00:00:00 2001 From: Stephen MacVicar Date: Mon, 20 Nov 2023 15:49:44 -0500 Subject: [PATCH 07/12] fix sql --- lib/inferno/repositories/requests.rb | 57 +++++++++++++--------- spec/inferno/repositories/requests_spec.rb | 2 +- 2 files changed, 34 insertions(+), 25 deletions(-) diff --git a/lib/inferno/repositories/requests.rb b/lib/inferno/repositories/requests.rb index 0aadc89c4..9b69b7e2d 100644 --- a/lib/inferno/repositories/requests.rb +++ b/lib/inferno/repositories/requests.rb @@ -130,32 +130,41 @@ def add_tag(tag_hash) end def self.tagged_requests_sql + # Find all the requests for the current session which: + # - match all supplied tags + # - are the from the most recent test run for each runnable <<~SQL.gsub(/\s+/, ' ').freeze - select * from requests where requests.id in ( - select r.id request_id from requests r - inner join requests_tags rt on r.id = rt.requests_id - inner join tags t on rt.tags_id = t.id - where r.test_session_id = :test_session_id - and r.result_id in ( - SELECT a.id FROM results a - WHERE a.test_session_id = r.test_session_id - AND a.id IN ( - SELECT id - FROM results b - WHERE (b.test_session_id = a.test_session_id AND b.test_id = a.test_id) OR - (b.test_session_id = a.test_session_id AND b.test_group_id = a.test_group_id) OR - (b.test_session_id = a.test_session_id AND b.test_suite_id = a.test_suite_id) - ORDER BY updated_at DESC - LIMIT 1 - ) - ) - and t.name in :tags - group by r.id, t.id - having count(*) = :tag_count - ); + select final_requests.* + from ( + select uncounted_requests.request_id request_id + from ( + select r.id request_id, t.id tag_id from requests r + inner join requests_tags rt on r.`index` = rt.requests_id + inner join tags t on rt.tags_id = t.id + where r.test_session_id = :test_session_id + and r.result_id in ( + SELECT a.id FROM results a + WHERE a.test_session_id = r.test_session_id + AND a.id IN ( + SELECT id + FROM results b + WHERE (b.test_session_id = a.test_session_id AND b.test_id = a.test_id) OR + (b.test_session_id = a.test_session_id AND b.test_group_id = a.test_group_id) OR + (b.test_session_id = a.test_session_id AND b.test_suite_id = a.test_suite_id) + ORDER BY updated_at DESC + LIMIT 1 + ) + ) + and t.name in :tags + group by r.id, t.id + ) as uncounted_requests + group by uncounted_requests.request_id + having count(*) = :tag_count + ) as matched_requests + inner join requests final_requests on final_requests.id = matched_requests.request_id + where final_requests.test_session_id = :test_session_id + order by final_requests.`index` SQL - # and tags in :tags through the requests_tags join table - # and result_id belongs to the most recent result for that runnable end def self.tagged_requests(test_session_id, tags) diff --git a/spec/inferno/repositories/requests_spec.rb b/spec/inferno/repositories/requests_spec.rb index b1d3b9fe6..700106c6c 100644 --- a/spec/inferno/repositories/requests_spec.rb +++ b/spec/inferno/repositories/requests_spec.rb @@ -137,7 +137,7 @@ requests = repo.tagged_requests(request.test_session_id, [SecureRandom.uuid]) expect(requests).to be_an(Array) - expect(requests.length).to eq(1) + expect(requests.length).to eq(0) end it 'returns requests matching a tag' do From 3cccf823b92d0b538701e7ba0095eb8f1fd91dae Mon Sep 17 00:00:00 2001 From: Stephen MacVicar Date: Tue, 21 Nov 2023 08:57:30 -0500 Subject: [PATCH 08/12] add tags to request dsl methods --- lib/inferno/dsl/fhir_client.rb | 63 +++++++++++++++++----------- lib/inferno/dsl/http_client.rb | 16 +++---- lib/inferno/dsl/request_storage.rb | 6 +-- lib/inferno/dsl/resume_test_route.rb | 8 +++- lib/inferno/dsl/runnable.rb | 3 +- lib/inferno/entities/request.rb | 15 ++++--- spec/inferno/dsl/fhir_client_spec.rb | 7 ++++ spec/inferno/dsl/http_client_spec.rb | 11 +++++ 8 files changed, 86 insertions(+), 43 deletions(-) diff --git a/lib/inferno/dsl/fhir_client.rb b/lib/inferno/dsl/fhir_client.rb index 2f7cf93e4..fca4ab572 100644 --- a/lib/inferno/dsl/fhir_client.rb +++ b/lib/inferno/dsl/fhir_client.rb @@ -102,8 +102,16 @@ def body_to_path(body) # @param headers [Hash] custom headers for this operation # @param operation_method [Symbol] indicates which request type to use for the operation # @return [Inferno::Entities::Request] - def fhir_operation(path, body: nil, client: :default, name: nil, headers: {}, operation_method: :post) - store_request_and_refresh_token(fhir_client(client), name) do + def fhir_operation( + path, + body: nil, + client: :default, + name: nil, + headers: {}, + operation_method: :post, + tags: [] + ) + store_request_and_refresh_token(fhir_client(client), name, tags) do tcp_exception_handler do operation_headers = fhir_client(client).fhir_headers operation_headers.merge!('Content-Type' => 'application/fhir+json') if body.present? @@ -128,8 +136,8 @@ def fhir_operation(path, body: nil, client: :default, name: nil, headers: {}, op # @param name [Symbol] Name for this request to allow it to be used by # other tests # @return [Inferno::Entities::Request] - def fhir_get_capability_statement(client: :default, name: nil) - store_request_and_refresh_token(fhir_client(client), name) do + def fhir_get_capability_statement(client: :default, name: nil, tags: []) + store_request_and_refresh_token(fhir_client(client), name, tags) do tcp_exception_handler do fhir_client(client).conformance_statement fhir_client(client).reply @@ -144,8 +152,8 @@ def fhir_get_capability_statement(client: :default, name: nil) # @param name [Symbol] Name for this request to allow it to be used by # other tests # @return [Inferno::Entities::Request] - def fhir_create(resource, client: :default, name: nil) - store_request_and_refresh_token(fhir_client(client), name) do + def fhir_create(resource, client: :default, name: nil, tags: []) + store_request_and_refresh_token(fhir_client(client), name, tags) do tcp_exception_handler do fhir_client(client).create(resource) end @@ -160,8 +168,8 @@ def fhir_create(resource, client: :default, name: nil) # @param name [Symbol] Name for this request to allow it to be used by # other tests # @return [Inferno::Entities::Request] - def fhir_read(resource_type, id, client: :default, name: nil) - store_request_and_refresh_token(fhir_client(client), name) do + def fhir_read(resource_type, id, client: :default, name: nil, tags: []) + store_request_and_refresh_token(fhir_client(client), name, tags) do tcp_exception_handler do fhir_client(client).read(fhir_class_from_resource_type(resource_type), id) end @@ -177,8 +185,8 @@ def fhir_read(resource_type, id, client: :default, name: nil) # @param name [Symbol] Name for this request to allow it to be used by # other tests # @return [Inferno::Entities::Request] - def fhir_vread(resource_type, id, version_id, client: :default, name: nil) - store_request_and_refresh_token(fhir_client(client), name) do + def fhir_vread(resource_type, id, version_id, client: :default, name: nil, tags: []) + store_request_and_refresh_token(fhir_client(client), name, tags) do tcp_exception_handler do fhir_client(client).vread(fhir_class_from_resource_type(resource_type), id, version_id) end @@ -193,8 +201,8 @@ def fhir_vread(resource_type, id, version_id, client: :default, name: nil) # @param name [Symbol] Name for this request to allow it to be used by # other tests # @return [Inferno::Entities::Request] - def fhir_update(resource, id, client: :default, name: nil) - store_request_and_refresh_token(fhir_client(client), name) do + def fhir_update(resource, id, client: :default, name: nil, tags: []) + store_request_and_refresh_token(fhir_client(client), name, tags) do tcp_exception_handler do fhir_client(client).update(resource, id) end @@ -210,8 +218,8 @@ def fhir_update(resource, id, client: :default, name: nil) # @param name [Symbol] Name for this request to allow it to be used by # other tests # @return [Inferno::Entities::Request] - def fhir_patch(resource_type, id, patchset, client: :default, name: nil) - store_request_and_refresh_token(fhir_client(client), name) do + def fhir_patch(resource_type, id, patchset, client: :default, name: nil, tags: []) + store_request_and_refresh_token(fhir_client(client), name, tags) do tcp_exception_handler do fhir_client(client).partial_update(fhir_class_from_resource_type(resource_type), id, patchset) end @@ -226,8 +234,8 @@ def fhir_patch(resource_type, id, patchset, client: :default, name: nil) # @param name [Symbol] Name for this request to allow it to be used by # other tests # @return [Inferno::Entities::Request] - def fhir_history(resource_type = nil, id = nil, client: :default, name: nil) - store_request_and_refresh_token(fhir_client(client), name) do + def fhir_history(resource_type = nil, id = nil, client: :default, name: nil, tags: []) + store_request_and_refresh_token(fhir_client(client), name, tags) do tcp_exception_handler do if id fhir_client(client).resource_instance_history(fhir_class_from_resource_type(resource_type), id) @@ -249,7 +257,14 @@ def fhir_history(resource_type = nil, id = nil, client: :default, name: nil) # other tests # @param search_method [Symbol] Use `:post` to search via POST # @return [Inferno::Entities::Request] - def fhir_search(resource_type = nil, client: :default, params: {}, name: nil, search_method: :get) + def fhir_search( + resource_type = nil, + client: :default, + params: {}, + name: nil, + search_method: :get, + tags: [] + ) search = if search_method == :post { body: params } @@ -257,7 +272,7 @@ def fhir_search(resource_type = nil, client: :default, params: {}, name: nil, se { parameters: params } end - store_request_and_refresh_token(fhir_client(client), name) do + store_request_and_refresh_token(fhir_client(client), name, tags) do tcp_exception_handler do if resource_type fhir_client(client) @@ -277,8 +292,8 @@ def fhir_search(resource_type = nil, client: :default, params: {}, name: nil, se # @param name [Symbol] Name for this request to allow it to be used by # other tests # @return [Inferno::Entities::Request] - def fhir_delete(resource_type, id, client: :default, name: nil) - store_request('outgoing', name) do + def fhir_delete(resource_type, id, client: :default, name: nil, tags: []) + store_request('outgoing', name, tags) do tcp_exception_handler do fhir_client(client).destroy(fhir_class_from_resource_type(resource_type), id) end @@ -292,8 +307,8 @@ def fhir_delete(resource_type, id, client: :default, name: nil) # @param name [Symbol] Name for this request to allow it to be used by # other tests # @return [Inferno::Entities::Request] - def fhir_transaction(bundle = nil, client: :default, name: nil) - store_request('outgoing', name) do + def fhir_transaction(bundle = nil, client: :default, name: nil, tags: []) + store_request('outgoing', name, tags) do tcp_exception_handler do fhir_client(client).transaction_bundle = bundle if bundle.present? fhir_client(client).end_transaction @@ -312,8 +327,8 @@ def fhir_class_from_resource_type(resource_type) # expired. It's combined with `store_request` so that all of the fhir # request methods don't have to be wrapped twice. # @private - def store_request_and_refresh_token(client, name, &block) - store_request('outgoing', name) do + def store_request_and_refresh_token(client, name, tags, &block) + store_request('outgoing', name, tags) do perform_refresh(client) if client.need_to_refresh? && client.able_to_refresh? block.call end diff --git a/lib/inferno/dsl/http_client.rb b/lib/inferno/dsl/http_client.rb index 8ed55ebae..167d2f50b 100644 --- a/lib/inferno/dsl/http_client.rb +++ b/lib/inferno/dsl/http_client.rb @@ -69,8 +69,8 @@ def http_clients # other tests # @param headers [Hash] Input headers here # @return [Inferno::Entities::Request] - def get(url = '', client: :default, name: nil, headers: nil) - store_request('outgoing', name) do + def get(url = '', client: :default, name: nil, headers: nil, tags: []) + store_request('outgoing', name, tags) do tcp_exception_handler do client = http_client(client) @@ -104,8 +104,8 @@ def connection # other tests # @param headers [Hash] Input headers here # @return [Inferno::Entities::Request] - def post(url = '', body: nil, client: :default, name: nil, headers: nil) - store_request('outgoing', name) do + def post(url = '', body: nil, client: :default, name: nil, headers: nil, tags: []) + store_request('outgoing', name, tags) do tcp_exception_handler do client = http_client(client) @@ -130,8 +130,8 @@ def post(url = '', body: nil, client: :default, name: nil, headers: nil) # other tests # @param headers [Hash] Input headers here # @return [Inferno::Entities::Request] - def delete(url = '', client: :default, name: :nil, headers: nil) - store_request('outgoing', name) do + def delete(url = '', client: :default, name: :nil, headers: nil, tags: []) + store_request('outgoing', name, tags) do tcp_exception_handler do client = http_client(client) @@ -160,7 +160,7 @@ def delete(url = '', client: :default, name: :nil, headers: nil) # other tests # @param headers [Hash] Input headers here # @return [Inferno::Entities::Request] - def stream(block, url = '', limit = 100, client: :default, name: nil, headers: nil) + def stream(block, url = '', limit = 100, client: :default, name: nil, headers: nil, tags: []) streamed = [] collector = proc do |chunk, bytes| @@ -169,7 +169,7 @@ def stream(block, url = '', limit = 100, client: :default, name: nil, headers: n block.call(chunk, bytes) end - store_request('outgoing', name) do + store_request('outgoing', name, tags) do tcp_exception_handler do client = http_client(client) diff --git a/lib/inferno/dsl/request_storage.rb b/lib/inferno/dsl/request_storage.rb index 06796a0ea..ee0d0ee0c 100644 --- a/lib/inferno/dsl/request_storage.rb +++ b/lib/inferno/dsl/request_storage.rb @@ -50,18 +50,18 @@ def named_request(name) end # @private - def store_request(direction, name = nil, &block) + def store_request(direction, name, tags, &block) response = block.call name = self.class.config.request_name(name) request = if response.is_a? FHIR::ClientReply Entities::Request.from_fhir_client_reply( - response, direction:, name:, test_session_id: + response, direction:, name:, test_session_id:, tags: ) else Entities::Request.from_http_response( - response, direction:, name:, test_session_id: + response, direction:, name:, test_session_id:, tags: ) end diff --git a/lib/inferno/dsl/resume_test_route.rb b/lib/inferno/dsl/resume_test_route.rb index e0ff972bb..211ae24b6 100644 --- a/lib/inferno/dsl/resume_test_route.rb +++ b/lib/inferno/dsl/resume_test_route.rb @@ -23,6 +23,11 @@ def test_run_identifier_block self.class.singleton_class.instance_variable_get(:@test_run_identifier_block) end + # @private + def tags + self.class.singleton_class.instance_variable_get(:@tags) + end + # @private def find_test_run(test_run_identifier) test_runs_repo.find_latest_waiting_by_identifier(test_run_identifier) @@ -44,7 +49,8 @@ def persist_request(request, test_run, waiting_result, test) request.to_hash.merge( test_session_id: test_run.test_session_id, result_id: waiting_result.id, - name: test.config.request_name(test.incoming_request_name) + name: test.config.request_name(test.incoming_request_name), + tags: ) ) end diff --git a/lib/inferno/dsl/runnable.rb b/lib/inferno/dsl/runnable.rb index 968ead399..c69bb4360 100644 --- a/lib/inferno/dsl/runnable.rb +++ b/lib/inferno/dsl/runnable.rb @@ -347,9 +347,10 @@ def suite # {Inferno::Entities::Request} object with the information for the # incoming request. # @return [void] - def resume_test_route(method, path, &block) + def resume_test_route(method, path, tags: [], &block) route_class = Class.new(ResumeTestRoute) do |klass| klass.singleton_class.instance_variable_set(:@test_run_identifier_block, block) + klass.singleton_class.instance_variable_set(:@tags, tags) end route(method, path, route_class) diff --git a/lib/inferno/entities/request.rb b/lib/inferno/entities/request.rb index 2832846a9..60409d16f 100644 --- a/lib/inferno/entities/request.rb +++ b/lib/inferno/entities/request.rb @@ -151,7 +151,7 @@ def resource class << self # @private - def from_hanami_request(request, name: nil) + def from_hanami_request(request, name: nil, tags: []) url = "#{request.base_url}#{request.path}" url += "?#{request.query_string}" if request.query_string.present? request_headers = @@ -166,12 +166,13 @@ def from_hanami_request(request, name: nil) direction: 'incoming', name:, request_body: request.body.string, - headers: request_headers + headers: request_headers, + tags: ) end # @private - def from_http_response(response, test_session_id:, direction: 'outgoing', name: nil) + def from_http_response(response, test_session_id:, direction: 'outgoing', name: nil, tags: []) request_headers = response.env.request_headers .map { |header_name, value| Header.new(name: header_name.downcase, value:, type: 'request') } @@ -188,12 +189,13 @@ def from_http_response(response, test_session_id:, direction: 'outgoing', name: request_body: response.env.request_body, response_body: response.body, test_session_id:, - headers: request_headers + response_headers + headers: request_headers + response_headers, + tags: ) end # @private - def from_fhir_client_reply(reply, test_session_id:, direction: 'outgoing', name: nil) + def from_fhir_client_reply(reply, test_session_id:, direction: 'outgoing', name: nil, tags: []) request = reply.request response = reply.response request_headers = request[:headers] @@ -216,7 +218,8 @@ def from_fhir_client_reply(reply, test_session_id:, direction: 'outgoing', name: request_body:, response_body: response[:body], test_session_id:, - headers: request_headers + response_headers + headers: request_headers + response_headers, + tags: ) end end diff --git a/spec/inferno/dsl/fhir_client_spec.rb b/spec/inferno/dsl/fhir_client_spec.rb index 65a5c1834..6c860aba2 100644 --- a/spec/inferno/dsl/fhir_client_spec.rb +++ b/spec/inferno/dsl/fhir_client_spec.rb @@ -387,6 +387,13 @@ def test_session_id expect(group.request).to eq(result) end + it 'adds tags to the request' do + tags = ['abc', 'def'] + request = group.fhir_get_capability_statement(tags:) + + expect(request.tags).to match_array(tags) + end + context 'with the client parameter' do it 'uses that client' do other_url = 'http://www.example.com/fhir/r4' diff --git a/spec/inferno/dsl/http_client_spec.rb b/spec/inferno/dsl/http_client_spec.rb index 0f49cac68..6729b6c06 100644 --- a/spec/inferno/dsl/http_client_spec.rb +++ b/spec/inferno/dsl/http_client_spec.rb @@ -122,6 +122,17 @@ def setup_default_client expect(request.response_body).to eq('BODY') end + it 'adds tags to a request' do + stub_request(:get, base_url) + .to_return(status: 200, body: response_body) + + tags = ['abc', 'def'] + + request = group.get(tags:) + + expect(request.tags).to match_array(tags) + end + context 'without a url argument' do let(:stub_get_request) do stub_request(:get, base_url) From e2ef87bce8be6d85a5ff4afe793a4c18e9952b22 Mon Sep 17 00:00:00 2001 From: Stephen MacVicar Date: Tue, 21 Nov 2023 12:06:04 -0500 Subject: [PATCH 09/12] add example tests to demo suite --- dev_suites/dev_demo_ig_stu1/groups/demo_group.rb | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/dev_suites/dev_demo_ig_stu1/groups/demo_group.rb b/dev_suites/dev_demo_ig_stu1/groups/demo_group.rb index 330ebfd4b..20c662471 100644 --- a/dev_suites/dev_demo_ig_stu1/groups/demo_group.rb +++ b/dev_suites/dev_demo_ig_stu1/groups/demo_group.rb @@ -330,5 +330,20 @@ class DemoGroup < Inferno::TestGroup test 'read from scratch' do run { assert scratch[:abc] == 'xyz' } end + + test 'tag a request' do + run do + fhir_read :patient, patient_id, client: :this_client_name, tags: ['example_tag_1', 'example_tag_2'] + end + end + + test 'load a tagged request' do + run do + tagged_requests = load_tagged_requests('example_tag_1', 'example_tag_2') + + assert tagged_requests.length == 1, 'Incorrect number of requests loaded' + assert request.id == tagged_requests.first.id, 'Incorrect request loaded' + end + end end end From 8341e6eb6e596c91d7aa6c03075970bfef893eec Mon Sep 17 00:00:00 2001 From: Stephen MacVicar Date: Tue, 21 Nov 2023 12:15:02 -0500 Subject: [PATCH 10/12] update docs --- lib/inferno/dsl/fhir_client.rb | 11 +++++++++++ lib/inferno/dsl/http_client.rb | 4 ++++ lib/inferno/dsl/request_storage.rb | 4 ++++ lib/inferno/dsl/runnable.rb | 3 ++- 4 files changed, 21 insertions(+), 1 deletion(-) diff --git a/lib/inferno/dsl/fhir_client.rb b/lib/inferno/dsl/fhir_client.rb index fca4ab572..2c8d65a65 100644 --- a/lib/inferno/dsl/fhir_client.rb +++ b/lib/inferno/dsl/fhir_client.rb @@ -101,6 +101,7 @@ def body_to_path(body) # other tests # @param headers [Hash] custom headers for this operation # @param operation_method [Symbol] indicates which request type to use for the operation + # @param tags [Array] a list of tags to assign to the request # @return [Inferno::Entities::Request] def fhir_operation( path, @@ -135,6 +136,7 @@ def fhir_operation( # @param client [Symbol] # @param name [Symbol] Name for this request to allow it to be used by # other tests + # @param tags [Array] a list of tags to assign to the request # @return [Inferno::Entities::Request] def fhir_get_capability_statement(client: :default, name: nil, tags: []) store_request_and_refresh_token(fhir_client(client), name, tags) do @@ -151,6 +153,7 @@ def fhir_get_capability_statement(client: :default, name: nil, tags: []) # @param client [Symbol] # @param name [Symbol] Name for this request to allow it to be used by # other tests + # @param tags [Array] a list of tags to assign to the request # @return [Inferno::Entities::Request] def fhir_create(resource, client: :default, name: nil, tags: []) store_request_and_refresh_token(fhir_client(client), name, tags) do @@ -167,6 +170,7 @@ def fhir_create(resource, client: :default, name: nil, tags: []) # @param client [Symbol] # @param name [Symbol] Name for this request to allow it to be used by # other tests + # @param tags [Array] a list of tags to assign to the request # @return [Inferno::Entities::Request] def fhir_read(resource_type, id, client: :default, name: nil, tags: []) store_request_and_refresh_token(fhir_client(client), name, tags) do @@ -184,6 +188,7 @@ def fhir_read(resource_type, id, client: :default, name: nil, tags: []) # @param client [Symbol] # @param name [Symbol] Name for this request to allow it to be used by # other tests + # @param tags [Array] a list of tags to assign to the request # @return [Inferno::Entities::Request] def fhir_vread(resource_type, id, version_id, client: :default, name: nil, tags: []) store_request_and_refresh_token(fhir_client(client), name, tags) do @@ -200,6 +205,7 @@ def fhir_vread(resource_type, id, version_id, client: :default, name: nil, tags: # @param client [Symbol] # @param name [Symbol] Name for this request to allow it to be used by # other tests + # @param tags [Array] a list of tags to assign to the request # @return [Inferno::Entities::Request] def fhir_update(resource, id, client: :default, name: nil, tags: []) store_request_and_refresh_token(fhir_client(client), name, tags) do @@ -217,6 +223,7 @@ def fhir_update(resource, id, client: :default, name: nil, tags: []) # @param client [Symbol] # @param name [Symbol] Name for this request to allow it to be used by # other tests + # @param tags [Array] a list of tags to assign to the request # @return [Inferno::Entities::Request] def fhir_patch(resource_type, id, patchset, client: :default, name: nil, tags: []) store_request_and_refresh_token(fhir_client(client), name, tags) do @@ -233,6 +240,7 @@ def fhir_patch(resource_type, id, patchset, client: :default, name: nil, tags: [ # @param client [Symbol] # @param name [Symbol] Name for this request to allow it to be used by # other tests + # @param tags [Array] a list of tags to assign to the request # @return [Inferno::Entities::Request] def fhir_history(resource_type = nil, id = nil, client: :default, name: nil, tags: []) store_request_and_refresh_token(fhir_client(client), name, tags) do @@ -256,6 +264,7 @@ def fhir_history(resource_type = nil, id = nil, client: :default, name: nil, tag # @param name [Symbol] Name for this request to allow it to be used by # other tests # @param search_method [Symbol] Use `:post` to search via POST + # @param tags [Array] a list of tags to assign to the request # @return [Inferno::Entities::Request] def fhir_search( resource_type = nil, @@ -291,6 +300,7 @@ def fhir_search( # @param client [Symbol] # @param name [Symbol] Name for this request to allow it to be used by # other tests + # @param tags [Array] a list of tags to assign to the request # @return [Inferno::Entities::Request] def fhir_delete(resource_type, id, client: :default, name: nil, tags: []) store_request('outgoing', name, tags) do @@ -306,6 +316,7 @@ def fhir_delete(resource_type, id, client: :default, name: nil, tags: []) # @param client [Symbol] # @param name [Symbol] Name for this request to allow it to be used by # other tests + # @param tags [Array] a list of tags to assign to the request # @return [Inferno::Entities::Request] def fhir_transaction(bundle = nil, client: :default, name: nil, tags: []) store_request('outgoing', name, tags) do diff --git a/lib/inferno/dsl/http_client.rb b/lib/inferno/dsl/http_client.rb index 167d2f50b..3e399a0d0 100644 --- a/lib/inferno/dsl/http_client.rb +++ b/lib/inferno/dsl/http_client.rb @@ -68,6 +68,7 @@ def http_clients # @param name [Symbol] Name for this request to allow it to be used by # other tests # @param headers [Hash] Input headers here + # @param tags [Array] a list of tags to assign to the request # @return [Inferno::Entities::Request] def get(url = '', client: :default, name: nil, headers: nil, tags: []) store_request('outgoing', name, tags) do @@ -103,6 +104,7 @@ def connection # @param name [Symbol] Name for this request to allow it to be used by # other tests # @param headers [Hash] Input headers here + # @param tags [Array] a list of tags to assign to the request # @return [Inferno::Entities::Request] def post(url = '', body: nil, client: :default, name: nil, headers: nil, tags: []) store_request('outgoing', name, tags) do @@ -129,6 +131,7 @@ def post(url = '', body: nil, client: :default, name: nil, headers: nil, tags: [ # @param name [Symbol] Name for this request to allow it to be used by # other tests # @param headers [Hash] Input headers here + # @param tags [Array] a list of tags to assign to the request # @return [Inferno::Entities::Request] def delete(url = '', client: :default, name: :nil, headers: nil, tags: []) store_request('outgoing', name, tags) do @@ -159,6 +162,7 @@ def delete(url = '', client: :default, name: :nil, headers: nil, tags: []) # @param name [Symbol] Name for this request to allow it to be used by # other tests # @param headers [Hash] Input headers here + # @param tags [Array] a list of tags to assign to the request # @return [Inferno::Entities::Request] def stream(block, url = '', limit = 100, client: :default, name: nil, headers: nil, tags: []) streamed = [] diff --git a/lib/inferno/dsl/request_storage.rb b/lib/inferno/dsl/request_storage.rb index ee0d0ee0c..7c1c1271a 100644 --- a/lib/inferno/dsl/request_storage.rb +++ b/lib/inferno/dsl/request_storage.rb @@ -36,6 +36,10 @@ def resource request&.resource end + # Returns requests which match all of the given tags + # + # @param tags [String] + # @return [Inferno::Entities::Request] def load_tagged_requests(*tags) return [] if tags.blank? diff --git a/lib/inferno/dsl/runnable.rb b/lib/inferno/dsl/runnable.rb index c69bb4360..12b46691a 100644 --- a/lib/inferno/dsl/runnable.rb +++ b/lib/inferno/dsl/runnable.rb @@ -318,7 +318,7 @@ def suite # # @see Inferno::DSL::Results#wait # @example - # resume_test_route :get, '/launch' do + # resume_test_route :get, '/launch', tags: ['launch'] do # request.query_parameters['iss'] # end # @@ -341,6 +341,7 @@ def suite # [Any of the path options available in Hanami # Router](https://github.com/hanami/router/tree/f41001d4c3ee9e2d2c7bb142f74b43f8e1d3a265#a-beautiful-dsl) # can be used here. + # @param tags [Array] a list of tags to assign to the request # @yield This method takes a block which must return the identifier # defined when a test was set to wait for the test run that hit this # route. The block has access to the `request` method which returns a From 6423aeccc991ccc811d3751daa7c00806462d50c Mon Sep 17 00:00:00 2001 From: Stephen MacVicar Date: Tue, 21 Nov 2023 12:18:23 -0500 Subject: [PATCH 11/12] fix linting errors --- lib/inferno/dsl/fhir_client.rb | 30 +++++++++++++++--------------- lib/inferno/dsl/request_storage.rb | 2 +- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/lib/inferno/dsl/fhir_client.rb b/lib/inferno/dsl/fhir_client.rb index 2c8d65a65..7f3e4c317 100644 --- a/lib/inferno/dsl/fhir_client.rb +++ b/lib/inferno/dsl/fhir_client.rb @@ -104,14 +104,14 @@ def body_to_path(body) # @param tags [Array] a list of tags to assign to the request # @return [Inferno::Entities::Request] def fhir_operation( - path, - body: nil, - client: :default, - name: nil, - headers: {}, - operation_method: :post, - tags: [] - ) + path, + body: nil, + client: :default, + name: nil, + headers: {}, + operation_method: :post, + tags: [] + ) store_request_and_refresh_token(fhir_client(client), name, tags) do tcp_exception_handler do operation_headers = fhir_client(client).fhir_headers @@ -267,13 +267,13 @@ def fhir_history(resource_type = nil, id = nil, client: :default, name: nil, tag # @param tags [Array] a list of tags to assign to the request # @return [Inferno::Entities::Request] def fhir_search( - resource_type = nil, - client: :default, - params: {}, - name: nil, - search_method: :get, - tags: [] - ) + resource_type = nil, + client: :default, + params: {}, + name: nil, + search_method: :get, + tags: [] + ) search = if search_method == :post { body: params } diff --git a/lib/inferno/dsl/request_storage.rb b/lib/inferno/dsl/request_storage.rb index 7c1c1271a..73fb648c2 100644 --- a/lib/inferno/dsl/request_storage.rb +++ b/lib/inferno/dsl/request_storage.rb @@ -43,7 +43,7 @@ def resource def load_tagged_requests(*tags) return [] if tags.blank? - Repositories::Requests.new.tagged_requests(self.test_session_id, tags).tap do |tagged_requests| + Repositories::Requests.new.tagged_requests(test_session_id, tags).tap do |tagged_requests| requests.concat(tagged_requests) end end From 861555c4657cca3b9ab9dec08bd926a1341ba7d9 Mon Sep 17 00:00:00 2001 From: Stephen MacVicar Date: Fri, 1 Dec 2023 13:59:07 -0500 Subject: [PATCH 12/12] change add_tag params --- lib/inferno/repositories/requests.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/inferno/repositories/requests.rb b/lib/inferno/repositories/requests.rb index 9b69b7e2d..56d745ce6 100644 --- a/lib/inferno/repositories/requests.rb +++ b/lib/inferno/repositories/requests.rb @@ -12,7 +12,7 @@ def create(params) headers = create_headers(request, params) params[:tags]&.each do |tag| - request.add_tag(name: tag, request_id: request.index) + request.add_tag(tag) end build_entity( @@ -120,8 +120,8 @@ def before_create super end - def add_tag(tag_hash) - tag = Tags::Model.find_or_create(tag_hash.slice(:name)) + def add_tag(tag_name) + tag = Tags::Model.find_or_create(name: tag_name) Inferno::Application['db.connection'][:requests_tags].insert( tags_id: tag.id,