2 changed files with 0 additions and 75 deletions
@ -1,21 +0,0 @@ |
|||||||
class SoftValidationsController < ApplicationController |
|
||||||
before_action :authenticate_user! |
|
||||||
|
|
||||||
def show |
|
||||||
@case_log = CaseLog.find(params[:case_log_id]) |
|
||||||
page_id = request.env["PATH_INFO"].split("/")[-2] |
|
||||||
page = @case_log.form.get_page(page_id) |
|
||||||
if page_requires_soft_validation_override?(page) |
|
||||||
errors = @case_log.soft_errors.values.first |
|
||||||
render json: { show: true, label: errors.message, hint: errors.hint_text } |
|
||||||
else |
|
||||||
render json: { show: false } |
|
||||||
end |
|
||||||
end |
|
||||||
|
|
||||||
private |
|
||||||
|
|
||||||
def page_requires_soft_validation_override?(page) |
|
||||||
@case_log.soft_errors.present? && @case_log.soft_errors.keys.first == page.soft_validations&.first&.id |
|
||||||
end |
|
||||||
end |
|
@ -1,54 +0,0 @@ |
|||||||
require "rails_helper" |
|
||||||
|
|
||||||
RSpec.describe SoftValidationsController, type: :request do |
|
||||||
let(:params) { { case_log_id: case_log.id } } |
|
||||||
let(:url) { "/logs/#{case_log.id}/net-income/soft-validations" } |
|
||||||
let(:user) { FactoryBot.create(:user) } |
|
||||||
|
|
||||||
context "when a user is not signed in" do |
|
||||||
let(:case_log) { FactoryBot.create(:case_log, :in_progress) } |
|
||||||
|
|
||||||
describe "GET #show" do |
|
||||||
it "redirects to the sign in page" do |
|
||||||
get url, headers: headers, params: {} |
|
||||||
expect(response).to redirect_to("/users/sign-in") |
|
||||||
end |
|
||||||
end |
|
||||||
end |
|
||||||
|
|
||||||
context "when a user is signed in" do |
|
||||||
before do |
|
||||||
sign_in user |
|
||||||
get url, params: {} |
|
||||||
end |
|
||||||
|
|
||||||
describe "GET #show" do |
|
||||||
context "when a soft validation is triggered" do |
|
||||||
let(:case_log) { FactoryBot.create(:case_log, :soft_validations_triggered) } |
|
||||||
|
|
||||||
it "returns a success response" do |
|
||||||
expect(response).to be_successful |
|
||||||
end |
|
||||||
|
|
||||||
it "returns a json with the soft validation fields" do |
|
||||||
json_response = JSON.parse(response.body) |
|
||||||
expect(json_response["show"]).to eq(true) |
|
||||||
expect(json_response["label"]).to match(/Are you sure this is correct?/) |
|
||||||
end |
|
||||||
end |
|
||||||
|
|
||||||
context "when no soft validation is triggered" do |
|
||||||
let(:case_log) { FactoryBot.create(:case_log, :in_progress) } |
|
||||||
|
|
||||||
it "returns a success response" do |
|
||||||
expect(response).to be_successful |
|
||||||
end |
|
||||||
|
|
||||||
it "returns a json without the soft validation fields" do |
|
||||||
json_response = JSON.parse(response.body) |
|
||||||
expect(json_response["show"]).to eq(false) |
|
||||||
end |
|
||||||
end |
|
||||||
end |
|
||||||
end |
|
||||||
end |
|
Loading…
Reference in new issue