From d1f72b07ae11e10415d13a306f5b155ef6119c31 Mon Sep 17 00:00:00 2001
From: timpeat <tim@timpeat.com>
Date: Fri, 17 Jan 2025 13:23:35 +0000
Subject: [PATCH] CRIMAPP-1577 store court_type and overall_result for
 decisions

---
 Gemfile                                                   | 2 +-
 Gemfile.lock                                              | 8 ++++----
 app/api/datastore/v1/reviewing.rb                         | 2 ++
 ...5032_add_court_type_and_overall_result_to_decisions.rb | 6 ++++++
 db/schema.rb                                              | 4 +++-
 .../datastore/v1/reviewing/complete_application_spec.rb   | 6 +++++-
 6 files changed, 21 insertions(+), 7 deletions(-)
 create mode 100644 db/migrate/20250117095032_add_court_type_and_overall_result_to_decisions.rb

diff --git a/Gemfile b/Gemfile
index 51937a3..d9da10f 100644
--- a/Gemfile
+++ b/Gemfile
@@ -29,7 +29,7 @@ gem 'aws-sdk-sns'
 
 gem 'laa-criminal-legal-aid-schemas',
     github: 'ministryofjustice/laa-criminal-legal-aid-schemas',
-    tag: 'v1.5.1'
+    tag: 'v1.5.2'
 
 group :development, :test do
   # See https://guides.rubyonrails.org/debugging_rails_applications.html#debugging-with-the-debug-gem
diff --git a/Gemfile.lock b/Gemfile.lock
index de0f624..e8abb2b 100644
--- a/Gemfile.lock
+++ b/Gemfile.lock
@@ -1,9 +1,9 @@
 GIT
   remote: https://github.com/ministryofjustice/laa-criminal-legal-aid-schemas.git
-  revision: 35163d1b4b46a921fb997f1b158fa1debc622f5b
-  tag: v1.5.1
+  revision: 8371d60c8ec53d60433a7395335698ff13dd1501
+  tag: v1.5.2
   specs:
-    laa-criminal-legal-aid-schemas (1.5.0)
+    laa-criminal-legal-aid-schemas (1.5.2)
       dry-schema (~> 1.13)
       dry-struct (~> 1.6.0)
       json-schema (~> 4.0.0)
@@ -142,7 +142,7 @@ GEM
       concurrent-ruby (~> 1.0)
       zeitwerk (~> 2.6)
     dry-inflector (1.1.0)
-    dry-initializer (3.1.1)
+    dry-initializer (3.2.0)
     dry-logic (1.5.0)
       concurrent-ruby (~> 1.0)
       dry-core (~> 1.0, < 2)
diff --git a/app/api/datastore/v1/reviewing.rb b/app/api/datastore/v1/reviewing.rb
index 6f4982d..ada2c0e 100644
--- a/app/api/datastore/v1/reviewing.rb
+++ b/app/api/datastore/v1/reviewing.rb
@@ -40,6 +40,8 @@ class Reviewing < Base
             optional :means, type: JSON
             requires :funding_decision, type: String
             optional :comment, type: String
+            optional :court_type, type: String
+            optional :overall_result, type: String
           end
         end
 
diff --git a/db/migrate/20250117095032_add_court_type_and_overall_result_to_decisions.rb b/db/migrate/20250117095032_add_court_type_and_overall_result_to_decisions.rb
new file mode 100644
index 0000000..4938ad5
--- /dev/null
+++ b/db/migrate/20250117095032_add_court_type_and_overall_result_to_decisions.rb
@@ -0,0 +1,6 @@
+class AddCourtTypeAndOverallResultToDecisions < ActiveRecord::Migration[7.1]
+  def change
+    add_column :decisions, :court_type, :string
+    add_column :decisions, :overall_result, :string
+  end
+end
diff --git a/db/schema.rb b/db/schema.rb
index 9568b28..6a00e74 100644
--- a/db/schema.rb
+++ b/db/schema.rb
@@ -10,7 +10,7 @@
 #
 # It's strongly recommended that you check this file into your version control system.
 
-ActiveRecord::Schema[7.1].define(version: 2024_11_01_173540) do
+ActiveRecord::Schema[7.1].define(version: 2025_01_17_095032) do
   # These are extensions that must be enabled in order to support this database
   enable_extension "citext"
   enable_extension "plpgsql"
@@ -61,6 +61,8 @@
     t.datetime "created_at", null: false
     t.datetime "updated_at", null: false
     t.string "case_id"
+    t.string "court_type"
+    t.string "overall_result"
     t.index ["crime_application_id"], name: "index_decisions_on_crime_application_id"
   end
 
diff --git a/spec/api/datastore/v1/reviewing/complete_application_spec.rb b/spec/api/datastore/v1/reviewing/complete_application_spec.rb
index 2c2662d..1c9b38f 100644
--- a/spec/api/datastore/v1/reviewing/complete_application_spec.rb
+++ b/spec/api/datastore/v1/reviewing/complete_application_spec.rb
@@ -94,7 +94,9 @@
               'interests_of_justice' => interests_of_justice,
               'means' => means,
               'funding_decision' => 'granted',
-              'comment' => 'test comment'
+              'comment' => 'test comment',
+              'court_type' => 'crown',
+              'overall_result' => 'Granted - failed means'
             }.as_json
           ]
         end
@@ -138,6 +140,8 @@
           expect(decisions.first.means).to eq(means)
           expect(decisions.first.funding_decision).to eq('granted')
           expect(decisions.first.comment).to eq('test comment')
+          expect(decisions.first.court_type).to eq('crown')
+          expect(decisions.first.overall_result).to eq('Granted - failed means')
         end
       end
     end