-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
CRM457-2216 part 4: Allow storage of pending (mid-adjustments) states…
… and non-timestamp-affecting events (#324) ## Description of change The app store needs to be able to hold onto the state of a submission as each adjustment is made by the caseworker without bumping the submission version each time. It achieves this by putting everything in a "pending" version that can be built up over time and eventually replaced by the full new version. [Link to relevant ticket](https://dsdmoj.atlassian.net/browse/CRM457-2216)
- Loading branch information
1 parent
3d56b4c
commit 3df8687
Showing
11 changed files
with
151 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
module V1 | ||
class AdjustmentsController < ApplicationController | ||
def create | ||
::Submissions::AdjustmentService.call(current_submission, params) | ||
head :created | ||
rescue ActiveRecord::RecordInvalid => e | ||
render json: { errors: e.message }, status: :unprocessable_entity | ||
end | ||
|
||
private | ||
|
||
def current_submission | ||
@current_submission ||= Submission.find(params[:submission_id]) | ||
end | ||
|
||
def authorization_object | ||
current_submission | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
module Submissions | ||
class AdjustmentService | ||
class << self | ||
def call(submission, params) | ||
submission.with_lock do | ||
pending_version = submission.ordered_submission_versions.find_or_initialize_by(pending: true) do |new_pending_version| | ||
new_pending_version.version = submission.current_version + 1 | ||
new_pending_version.json_schema_version = submission.latest_version.json_schema_version | ||
end | ||
|
||
pending_version.update!(application: params[:application]) | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
db/migrate/20241111091017_add_pending_to_application_version.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
class AddPendingToApplicationVersion < ActiveRecord::Migration[7.2] | ||
def change | ||
add_column :application_version, :pending, :boolean, default: false | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
require "rails_helper" | ||
|
||
RSpec.describe "Adjust submission" do | ||
before { allow(Tokens::VerificationService).to receive(:call).and_return(valid: true, role: :caseworker) } | ||
|
||
let(:submission) { create(:submission) } | ||
|
||
it "validates" do | ||
post "/v1/submissions/#{submission.id}/adjustments", params: {} | ||
expect(response).to have_http_status(:unprocessable_entity) | ||
end | ||
|
||
context "when there is no pending version" do | ||
it "adds a new pending version" do | ||
post "/v1/submissions/#{submission.id}/adjustments", params: { application: { new: :data } } | ||
expect(response).to have_http_status(:created) | ||
expect(submission.reload.current_version).to eq 1 | ||
expect(submission.latest_version).to have_attributes( | ||
application: { "new" => "data" }, | ||
version: 2, | ||
) | ||
end | ||
end | ||
|
||
context "when there is a pending version" do | ||
let(:pending_version) { create(:submission_version, submission:, application: { "old" => "data" }, pending: true) } | ||
|
||
before { pending_version } | ||
|
||
it "replaces the pending version data" do | ||
post "/v1/submissions/#{submission.id}/adjustments", params: { application: { new: :data } } | ||
expect(response).to have_http_status(:created) | ||
expect(pending_version.reload).to have_attributes( | ||
application: { "new" => "data" }, | ||
) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters