Skip to content

Commit

Permalink
feat: order demand efforts by start time to computation
Browse files Browse the repository at this point in the history
  • Loading branch information
wptussolini committed Oct 14, 2024
1 parent 443f3ba commit efd642d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
4 changes: 4 additions & 0 deletions app/graphql/types/demand_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions spec/graphql/types/query_type_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
}
)
Expand All @@ -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

Expand Down

0 comments on commit efd642d

Please sign in to comment.