diff --git a/app/graphql/types/demand_type.rb b/app/graphql/types/demand_type.rb index 07aefab00..175b62205 100644 --- a/app/graphql/types/demand_type.rb +++ b/app/graphql/types/demand_type.rb @@ -30,6 +30,10 @@ class DemandType < Types::BaseObject field :responsibles, [Types::Teams::TeamMemberType], null: true field :team, Types::Teams::TeamType, null: false + def demand_efforts + object.demand_efforts.order(start_time_to_computation: :asc) + end + def responsibles object.memberships.map(&:team_member).uniq end diff --git a/spec/graphql/types/query_type_spec.rb b/spec/graphql/types/query_type_spec.rb index 3c4ff14e5..baa1b3202 100644 --- a/spec/graphql/types/query_type_spec.rb +++ b/spec/graphql/types/query_type_spec.rb @@ -1162,13 +1162,19 @@ describe '#demand' do context 'with valid ID' do it 'returns the demand' do + now = DateTime.current demand = Fabricate :demand + demand_effort = Fabricate :demand_effort, demand: demand, start_time_to_computation: now - 1.hour + other_demand_effort = Fabricate :demand_effort, demand: demand, start_time_to_computation: now - 2.hours query = %( query { demand(externalId: "#{demand.external_id}") { id + demandEfforts { + id + } } } ) @@ -1182,6 +1188,7 @@ result = FlowClimateSchema.execute(query, variables: nil, context: context).as_json expect(result.dig('data', 'demand')['id']).to eq demand.id.to_s + expect(result.dig('data', 'demand', 'demandEfforts')).to eq [{ 'id' => other_demand_effort.id.to_s }, { 'id' => demand_effort.id.to_s }] end end