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

Fix Participants::Query filtering on training_status #2005

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion app/services/participants/query.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def where_training_status_is(training_status)
raise API::Errors::FilterValidationError, I18n.t(:invalid_training_status, valid_training_status: Application.training_statuses.keys)
end

scope.merge!(Application.where(training_status:))
scope.merge!(User.includes(:applications).where(applications: { training_status: }))
end

def where_from_participant_id_is(from_participant_id)
Expand Down
25 changes: 25 additions & 0 deletions spec/services/participants/query_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,20 @@
end
end

context "when the participant has multiple applications with different training statuses" do
let(:params) { { training_status: "withdrawn" } }

before do
participant1.applications.first.update!(training_status: ApplicationState.states[:withdrawn])
create(:application, :accepted, user: participant1, lead_provider:, training_status: :active)
end

it "filters the users by training status and only returns applications with the matching training status" do
expect(query.participants).to contain_exactly(participant1)
expect(query.participants.map(&:applications).flatten.map(&:training_status)).to all(eq("withdrawn"))
end
end

context "when a training status is not supplied" do
it "does not filter by training status" do
condition_string = %("training_status")
Expand Down Expand Up @@ -195,6 +209,17 @@
end
end

context "when the participant has multiple id changes with different from_participant_id values" do
let(:params) { { from_participant_id: } }

before { create(:participant_id_change, user: participant1, to_participant_id: participant1.ecf_id) }

it "filters the users by from_participant_id and only returns id changes with the matching from_participant_id" do
expect(query.participants).to contain_exactly(participant1)
expect(query.participants.map(&:participant_id_changes).flatten.map(&:from_participant_id)).to all(eq(from_participant_id))
end
end

context "when a from participant id is not supplied" do
it "does not filter by from participant id" do
condition_string = %("from_participant_id")
Expand Down
Loading