Skip to content

Commit

Permalink
fix: consider start time when removing assignments duplications
Browse files Browse the repository at this point in the history
  • Loading branch information
lhguerra committed Dec 16, 2024
1 parent 232b899 commit 791e386
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
2 changes: 1 addition & 1 deletion app/adapters/jira/jira_issue_adapter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ def duplicated_assignment(demand, history_date, membership)

return already_assigned.first.id if already_assigned.present?

overlapping_assignment = demand.item_assignments.where(membership: membership).where('finish_time <= :history_date', history_date: history_date)
overlapping_assignment = demand.item_assignments.where(membership: membership).where('start_time <= :history_date AND finish_time >= :history_date', history_date: history_date)
return overlapping_assignment.first.id if overlapping_assignment.present?

item_assignment = demand.item_assignments.where(membership: membership, start_time: history_date).first
Expand Down
6 changes: 4 additions & 2 deletions spec/adapters/jira/jira_issue_adapter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -218,20 +218,22 @@
end

it 'only adds new assignment if there is not one running already' do
travel_to Time.zone.local(2020, 8, 24, 10) do
travel_to Time.zone.local(2020, 8, 24, 19) do
demand = Fabricate :demand, company: company, team: team, external_id: 'CRE-726'
other_company_team_member = Fabricate :team_member, jira_account_user_email: 'bar', jira_account_id: 'xpto'

membership = Fabricate :membership, team: demand.team, team_member: team_member, member_role: :developer, start_date: 1.month.ago, end_date: nil
Fabricate :membership, team: team, team_member: other_company_team_member, hours_per_month: 120, start_date: 2.months.ago, end_date: nil

overlapping_assignment = Fabricate :item_assignment, demand: demand, membership: membership, start_time: 2.hours.ago, finish_time: 1.hour.ago
overlapping_assignment = Fabricate :item_assignment, demand: demand, membership: membership, start_time: 12.hours.ago, finish_time: 1.hour.ago
not_overlapping_assignment = Fabricate :item_assignment, demand: demand, membership: membership, start_time: 2.hours.ago, finish_time: 1.hour.ago

jira_issue_changelog = file_fixture('issue_changelog_paginated_page_one.json').read
described_class.instance.process_jira_issue_changelog(jira_account, JSON.parse(jira_issue_changelog), demand, team_member)

expect(ItemAssignment.count).to eq 2
expect(demand.item_assignments).to include(overlapping_assignment)
expect(demand.item_assignments).not_to include(not_overlapping_assignment)
end
end
end
Expand Down

0 comments on commit 791e386

Please sign in to comment.