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
Fix discarded draft attribution in timeline entries #1755
Conversation
The impetus to add tests for this was learning that there is actually a problem where the edition model used in this interactor is not up to date and thus a timeline entry is created with the wrong status. This adds tests for the whole file however the one on line 20 is a failing test that captures this problem.
This changes this service to take an edition as it's argument rather than a document. This change has been done in part to resolve a problem where operating on a document meant a stale edition was used in the interactor. When trying to address that problem I noticed that it seemed quite strange that this class operated on a document when its name implies an edition. I also added reload methods for associations of a document so that were a similar problem to occur again the document is up to date.
I found these tests quite hard to follow as there are quite a lot of them. I decided that it would be easier to work with them if they were in certain groupings so I've moved them into individual describe blocks. This might well be a sign that this class has too many responsibilities but that seems like a problem for another day. Aside from these I've adapted these tests to be much more edition centric and to no longer rely on any reloading. I've had to tweak a bunch of factory calls and to resolve some inconsistencies with use of brackets or not I've made them all use brackets - hopefully this isn't too controversial.
a1e2b3a
to
bf4385e
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks good to me 👍. I agree the DeleteDraftEditionService
is doing too much. Probably not the right time to do the work, so the comments are just suggestions. Perhaps a pain card would make sense here?
end | ||
|
||
it "raises an error when a base path cannot be deleted" do | ||
edition = create :edition | ||
describe "Asset Manager communication" do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we extract this part into a service?
} | ||
stub_any_publishing_api_discard_draft | ||
.to_return(status: 422, body: discard_draft_error.to_json) | ||
it "does not delete path reservations for published documents" do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we make a DeletePathReservationService
to extract this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(Especially noting the detailed edge case of having had multiple base paths.)
Thanks @benthorner I'll add something to the card AC about deciding what to tell about this (whether just fix it or add to wall of pain) |
Trello: https://trello.com/c/yqXt0RGc/1417-remove-documents-at-dwps-request
It turns out that we have a bug in the code used to assign the status of a timeline entry. The
DeleteDraftEditionService
accepts a document as input and modifies the current_edition of that. As the edition that is used in the interactor is not the same object asdocument.current_edition
the edition in the interactor becomes stale and using that to populate the timeline entry uses an out of date status.Looking on production we have 175 discarded timeline entries and only 32 of those are attributed to the correct status:
The problems seem to kick in between March 20th to 25th this year - which makes this change (by me) the likely culprit. Once this is merged I plan to fix those in the DB manually.
To resolve this I've changed the
DeleteDraftEditionService
to operate on an edition, which felt more natural anyway given the naming the class.