Skip to content
This repository has been archived by the owner on Jan 5, 2022. It is now read-only.

Commit

Permalink
adds monitoring to complaint detail timeline
Browse files Browse the repository at this point in the history
  • Loading branch information
jduss4 committed Nov 1, 2021
1 parent 34c2780 commit 911927b
Show file tree
Hide file tree
Showing 8 changed files with 214 additions and 11 deletions.
6 changes: 5 additions & 1 deletion app/controllers/complaints_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,11 @@ def show
@issue_tta_reports = inject_access_token(IssueTtaReport)
@issue_monitoring_reviews = inject_access_token(IssueMonitoringReview)

@timeline = Timeline.new(@complaint.attributes, @issue_tta_reports)
@timeline = Timeline.new(
@complaint.attributes,
@issue_tta_reports,
@issue_monitoring_reviews
)
render layout: "details"
end

Expand Down
12 changes: 12 additions & 0 deletions app/models/monitoring_review.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,22 @@ def initialize(id, access_token)
@errors = []
end

def itams_url
get_api_data_field :links, :html
end

def review_type
get_api_data_field :attributes, :reviewType
end

def start_date
get_api_data_field :attributes, :reviewStartDate
end

def status
get_api_data_field :attributes, :status
end

def valid?
review_data.error.nil?
end
Expand Down
5 changes: 3 additions & 2 deletions app/models/timeline.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,12 @@ class Timeline
initialContactDate: "Initial contact from complaint"
}.with_indifferent_access.freeze

def initialize(complaint_attributes, tta_reports)
def initialize(complaint_attributes, tta_reports = [], monitoring_reviews = [])
@complaint_events = needed_attributes(complaint_attributes)
.map { |event| ComplaintEvent.new(event) }

@tta_events = tta_reports.map { |report| TtaEvent.new(report) }
@monitoring_events = monitoring_reviews.map { |review| MonitoringEvent.new(review) }
end

def events
Expand All @@ -25,7 +26,7 @@ def events
private

def all_events
@complaint_events + @tta_events
@complaint_events + @tta_events + @monitoring_events
end

def needed_attributes(attributes)
Expand Down
27 changes: 27 additions & 0 deletions app/models/timeline/monitoring_event.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
class Timeline::MonitoringEvent < Timeline::Event
include ActionView::Helpers::TagHelper

attr_reader :review
delegate :api_error_message, :status, :review_type, to: :review

def initialize(issue_monitoring_review)
@name = issue_monitoring_review.review_id
@date = issue_monitoring_review.start_date
@review = issue_monitoring_review.monitoring_review
end

def api_call_succeeded?
review.valid?
end

def review_link
# using content_tag for the link will properly escape any dangerous characters that sneak into name or ttahub_url
content_tag(:a, name, class: "usa-link", href: review.itams_url, target: "_blank")
rescue Api::Error
name
end

def timeline_partial
"monitoring_timeline_event"
end
end
18 changes: 18 additions & 0 deletions app/views/complaints/_monitoring_timeline_event.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<h3 class="usa-process-list__heading ct-timeline__two-part-container">
<span>Monitoring Activity: <%= event.review_link %></span>
<span class="ct-timeline__date"><%= event.formatted_date %></span>
</h3>
<% if event.api_call_succeeded? %>
<div>
<ul class="usa-list usa-list--unstyled">
<li><strong>Status:</strong> <%= event.status %></li>
<li><strong>Type:</strong> <%= event.review_type %></li>
</ul>
</div>
<% else %>
<div class="usa-alert usa-alert--error">
<div class="usa-alert__body">
<p class="usa-alert__text"><%= event.api_error_message %></p>
</div>
</div>
<% end %>
18 changes: 18 additions & 0 deletions spec/models/monitoring_review_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,30 @@
described_class.new id, access_token
end

describe "#itams_url" do
it "returns a URL" do
expect(subject.start_date).to be_a(String)
end
end

describe "#review_type" do
it "returns the URL to view the report in IT-AMS" do
expect(subject.itams_url).to eq "https://example.com/TODO"
end
end

describe "#start_date" do
it "returns a start date" do
expect(subject.start_date).to be_a(String)
end
end

describe "#status" do
it "returns a status" do
expect(subject.status).to be_a(String)
end
end

describe "#valid?" do
context "with no errors" do
it "is valid" do
Expand Down
53 changes: 53 additions & 0 deletions spec/models/timeline/monitoring_review_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
require "rails_helper"

RSpec.describe Timeline::MonitoringEvent do
let(:date) { 1.day.ago.strftime("%F") }
let(:review_id) { "Test-Review-ID" }
let(:issue_id) { "Test-Issue-ID" }
# just setting the start_date manually because we aren't triggering the before_validation callback
let(:event_param) { IssueMonitoringReview.new review_id: review_id, issue_id: issue_id, start_date: date }
let(:monitoring_review) { event_param.monitoring_review }
subject { Timeline::MonitoringEvent.new(event_param) }

describe "#init" do
it "assigns attr_readers inherited from Timeline::Event" do
expect(subject.name).to eq review_id
expect(subject.date).to eq Date.parse(date)
end
end

describe "#review_link" do
it "returns a link that opens in a new tab" do
expect(subject.review_link).to match /\A<a .*>#{review_id}<\/a>\z/
expect(subject.review_link).to include 'target="_blank"'
end

context "authorization error loading Monitoring API" do
xit "returns just the review ID with no link"
end
end

describe "#review_type" do
it "returns the review type" do
expect(subject.review_type).to be_a(String)
end
end

describe "#status" do
it "returns the review status" do
expect(subject.status).to be_a(String)
end
end

describe "#timeline_partial" do
it "returns the monitoring event timeline partial" do
expect(subject.timeline_partial).to eq "monitoring_timeline_event"
end
end

describe "#formatted_date" do
it "returns the date formatted '%m/%d/%Y'" do
expect(subject.formatted_date).to eq Date.parse(date).strftime("%m/%d/%Y")
end
end
end
86 changes: 78 additions & 8 deletions spec/models/timeline_spec.rb
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
require "rails_helper"

RSpec.describe Timeline do
let(:display_id) { "First-Display-ID" }
let(:display_id_2) { "Second-Display-ID" }
let(:tta_activity_report) { IssueTtaReport.create tta_report_display_id: display_id, issue_id: "1" }
let(:tta_activity_report_2) { IssueTtaReport.create tta_report_display_id: display_id_2, issue_id: "1" }
let(:tta_display_id) { "First-Display-ID" }
let(:tta_display_id_2) { "Second-Display-ID" }
let(:review_id) { "First-Review-ID" }
let(:review_id_2) { "Second-Review-ID" }
let(:tta_activity_report) { IssueTtaReport.create tta_report_display_id: tta_display_id, issue_id: "1" }
let(:tta_activity_report_2) { IssueTtaReport.create tta_report_display_id: tta_display_id_2, issue_id: "1" }
let(:monitoring_review) { IssueMonitoringReview.create review_id: review_id, issue_id: "1" }
let(:monitoring_review_2) { IssueMonitoringReview.create review_id: review_id_2, issue_id: "2" }

describe "#events" do
describe "no complaint attributes" do
describe "no TTA activity reports" do
describe "no TTA activity reports or monitoring reviews" do
it "returns an empty array" do
timeline = Timeline.new({}, [])
timeline = Timeline.new({})
expect(timeline.events).to eq []
end
end
Expand All @@ -21,7 +25,7 @@

expect(timeline.events.count).to be 1
expect(timeline.events.first).to be_a Timeline::TtaEvent
expect(timeline.events.first.name).to eql display_id
expect(timeline.events.first.name).to eql tta_display_id
end
end

Expand All @@ -35,6 +39,42 @@
expect(first_report.date >= second_report.date).to be true
end
end

describe "with a monitoring review" do
it "returns an array with only a monitoring review" do
timeline = Timeline.new({}, [], [monitoring_review])

expect(timeline.events.count).to be 1
expect(timeline.events.first).to be_a Timeline::MonitoringEvent
expect(timeline.events.first.name).to eql review_id
end
end

describe "multiple monitoring reviews" do
it "returns an array with reviews in desc order" do
timeline = Timeline.new({}, [], [monitoring_review, monitoring_review_2])
first_review = timeline.events.first
second_review = timeline.events.last

expect(timeline.events.count).to be 2
expect(first_review.date >= second_review.date).to be true
end
end

describe "both TTA reports and monitoring reviews" do
it "returns an array with reports and reviews in desc order" do
timeline = Timeline.new(
{},
[tta_activity_report, tta_activity_report_2],
[monitoring_review, monitoring_review_2]
)
first = timeline.events.first
last = timeline.events.last

expect(timeline.events.count).to be 4
expect(first.date >= last.date).to be true
end
end
end

describe "no needed complaint attributes" do
Expand All @@ -58,7 +98,7 @@

expect(timeline.events.count).to be 1
expect(timeline.events.first).to be_a Timeline::TtaEvent
expect(timeline.events.first.name).to eql display_id
expect(timeline.events.first.name).to eql tta_display_id
end
end

Expand All @@ -72,6 +112,16 @@
expect(first_report.date >= second_report.date).to be true
end
end

describe "with a monitoring review" do
it "returns an array with only a monitoring review" do
timeline = Timeline.new(events, [], [monitoring_review])

expect(timeline.events.count).to be 1
expect(timeline.events.first).to be_a Timeline::MonitoringEvent
expect(timeline.events.first.name).to eql review_id
end
end
end

describe "with needed complaint events" do
Expand Down Expand Up @@ -113,6 +163,26 @@
expect(timeline.events.count).to be 4
end
end

describe "with a monitoring review" do
it "returns an array with all the necessary events" do
timeline = Timeline.new(events, [], [monitoring_review])

expect(timeline.events.count).to be 4
end
end

describe "both TTA reports and monitoring reviews" do
it "returns an array with reports and reviews in desc order" do
timeline = Timeline.new(
events,
[tta_activity_report, tta_activity_report_2],
[monitoring_review, monitoring_review_2]
)

expect(timeline.events.count).to be 7
end
end
end
end
end

0 comments on commit 911927b

Please sign in to comment.