Skip to content

Commit

Permalink
Return whole household
Browse files Browse the repository at this point in the history
  • Loading branch information
martha committed Feb 5, 2025
1 parent 239e750 commit 358a029
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
4 changes: 2 additions & 2 deletions drivers/hmis/app/graphql/mutations/join_household.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class JoinHousehold < BaseMutation
argument :joining_enrollment_inputs, [Types::HmisSchema::EnrollmentRelationshipInput], required: true

field :receiving_household, Types::HmisSchema::Household, null: false
field :donor_enrollment, Types::HmisSchema::Enrollment, null: true # Will be null if there are no remaining members
field :donor_household, Types::HmisSchema::Household, null: true # Will be null if there are no remaining members

def resolve(receiving_household_id:, joining_enrollment_inputs:)
# note: viewable_by takes care of filtering by data source via project with_access
Expand Down Expand Up @@ -88,7 +88,7 @@ def resolve(receiving_household_id:, joining_enrollment_inputs:)

{
receiving_household: receiving_household,
donor_enrollment: remaining_hoh,
donor_household: remaining_enrollments.any? ? donor_household : nil,
}
end
end
Expand Down
2 changes: 1 addition & 1 deletion drivers/hmis/app/graphql/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -5653,7 +5653,7 @@ type JoinHouseholdPayload {
A unique identifier for the client performing the mutation.
"""
clientMutationId: String
donorEnrollment: Enrollment
donorHousehold: Household
errors: [ValidationError!]!
receivingHousehold: Household!
}
Expand Down
16 changes: 8 additions & 8 deletions drivers/hmis/spec/requests/hmis/join_household_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
}
}
}
donorEnrollment {
donorHousehold {
id
}
}
Expand Down Expand Up @@ -73,15 +73,15 @@ def perform_mutation(

expect(response.status).to eq(200), result.inspect
result = result.dig('data', 'joinHousehold')
return result['receivingHousehold'], result['donorEnrollment']
return result['receivingHousehold'], result['donorHousehold']
end

it 'should successfully join households' do
expect do
joined_household, donor_enrollment = perform_mutation
joined_household, donor_household = perform_mutation
expect(joined_household.dig('id')).to eq(receiving_enrollment.household_id)
expect(joined_household.dig('householdSize')).to eq(3)
expect(donor_enrollment).to be_nil # No remaining members in donor household
expect(donor_household).to be_nil # No remaining members in donor household
receiving_enrollment.reload
donor_hoh.reload
donor_child.reload
Expand Down Expand Up @@ -110,9 +110,9 @@ def perform_mutation(

it 'returns the remaining donor household' do
expect do
joined_household, donor_enrollment = perform_mutation
joined_household, donor_household = perform_mutation
expect(joined_household.dig('id')).to eq(receiving_enrollment.household_id)
expect(donor_enrollment.dig('id')).to eq(remaining_member.id.to_s)
expect(donor_household.dig('id')).to eq(remaining_member.household_id.to_s)
donor_hoh.reload
donor_child.reload
remaining_member.reload
Expand Down Expand Up @@ -148,9 +148,9 @@ def perform_mutation(
relationship_to_hoh: 'SPOUSE_OR_PARTNER',
},
]
joined_household, donor_enrollment = perform_mutation(receiving_enrollment.household_id, joining_enrollment_inputs)
joined_household, donor_household = perform_mutation(receiving_enrollment.household_id, joining_enrollment_inputs)
expect(joined_household.dig('id')).to eq(receiving_enrollment.household_id)
expect(donor_enrollment.dig('id')).to eq(donor_hoh.id.to_s)
expect(donor_household.dig('id')).to eq(donor_hoh.household_id.to_s)
donor_child.reload
end.to change(donor_child, :household_id).to(receiving_enrollment.household_id)
end
Expand Down

0 comments on commit 358a029

Please sign in to comment.