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

Retirement warn in days only #18637

Merged
merged 2 commits into from
Apr 22, 2019
Merged
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
12 changes: 4 additions & 8 deletions app/models/service/dialog_properties/retirement.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,6 @@ def parse_options
if @options['dialog_service_retires_on'].present?
field_name = 'dialog_service_retires_on'
self.retire_on_date = time_parse(@options[field_name])
elsif @options['dialog_service_retires_in_hours'].present?
field_name = 'dialog_service_retires_in_hours'
retires_in_duration(@options[field_name], :hours)
elsif @options['dialog_service_retires_in_days'].present?
field_name = 'dialog_service_retires_in_days'
retires_in_duration(@options[field_name], :days)
Expand All @@ -51,7 +48,10 @@ def retire_on_date=(value)

def retirement_warning
warn_value = parse_retirement_warn
@attributes[:retirement_warn] = warn_value if warn_value
if warn_value
days_between_warn_and_retirement = (@attributes[:retires_on] - warn_value).to_i / 1.day
@attributes[:retirement_warn] = days_between_warn_and_retirement
end
end

def parse_retirement_warn
Expand All @@ -62,12 +62,8 @@ def parse_retirement_warn
time_parse(value)
when 'warn_in_days'
time_now + offset_set(value, :days)
when 'warn_in_hours'
time_now + offset_set(value, :hours)
when 'warn_offset_days'
@attributes[:retires_on] - offset_set(value, :days)
when 'warn_offset_hours'
@attributes[:retires_on] - offset_set(value, :hours)
end
end

Expand Down
56 changes: 7 additions & 49 deletions spec/models/service/dialog_properties/retirement_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,26 +42,6 @@
end
end

describe 'retires_in_hours' do
it 'with invalid time' do
options = {'dialog_service_retires_in_hours' => 'xyz'}
parsed_results = described_class.parse(options, nil)

expect(parsed_results[:retires_on]).to be_nil
expect(parsed_results[:retirement_warn]).to be_nil
end

it 'with valid time' do
Timecop.freeze(time) do
options = {'dialog_service_retires_in_hours' => 5}
parsed_results = described_class.parse(options, nil)

expect(parsed_results[:retires_on]).to eq(time + 5.hours)
expect(parsed_results[:retirement_warn]).to be_nil
end
end
end

describe 'retires_in_days' do
it 'with invalid time' do
options = {'dialog_service_retires_in_days' => 'xyz'}
Expand Down Expand Up @@ -94,51 +74,29 @@
parsed_results = described_class.parse(options, user)

expect(parsed_results[:retires_on]).to eq(time + 5.days)
expect(parsed_results[:retirement_warn]).to eq(time + 1.day)
expect(parsed_results[:retirement_warn]).to eq(4)
end
end

it 'with retirement_warn_in_days' do
Timecop.freeze(time) do
options = {'dialog_service_retires_in_days' => 5,
'dialog_service_retirement_warn_in_days' => 1}
'dialog_service_retirement_warn_in_days' => 2}
parsed_results = described_class.parse(options, nil)

expect(parsed_results[:retires_on]).to eq(time + 5.days)
expect(parsed_results[:retirement_warn]).to eq(time + 1.day)
expect(parsed_results[:retirement_warn]).to eq(3)
end
end

it 'with retirement_warn_offset_days' do
Timecop.freeze(time) do
options = {'dialog_service_retires_in_days' => 5,
'dialog_service_retirement_warn_offset_days' => 4}
parsed_results = described_class.parse(options, nil)

expect(parsed_results[:retires_on]).to eq(time + 5.days)
expect(parsed_results[:retirement_warn]).to eq(time + 1.day)
end
end

it 'with retirement_warn_in_hours' do
Timecop.freeze(time) do
options = {'dialog_service_retires_in_hours' => 5,
'dialog_service_retirement_warn_in_hours' => 1}
parsed_results = described_class.parse(options, nil)

expect(parsed_results[:retires_on]).to eq(time + 5.hours)
expect(parsed_results[:retirement_warn]).to eq(time + 1.hour)
end
end

it 'with retirement_warn_offset_hours' do
Timecop.freeze(time) do
options = {'dialog_service_retires_in_hours' => 5,
'dialog_service_retirement_warn_offset_hours' => 4}
options = {'dialog_service_retires_in_days' => 10,
'dialog_service_retirement_warn_offset_days' => 3}
parsed_results = described_class.parse(options, nil)

expect(parsed_results[:retires_on]).to eq(time + 5.hours)
expect(parsed_results[:retirement_warn]).to eq(time + 1.hour)
expect(parsed_results[:retires_on]).to eq(time + 10.days)
expect(parsed_results[:retirement_warn]).to eq(3)
end
end
end
Expand Down