From 5c409d8c4065ca636e263a1cb8c9772a8a53d460 Mon Sep 17 00:00:00 2001 From: baarkerlounger Date: Tue, 19 Oct 2021 17:38:29 +0100 Subject: [PATCH] Add show method to JSON API and document not found response --- app/controllers/case_logs_controller.rb | 15 ++++++-- docs/api/DLUHC-CORE-Data.v1.json | 42 +++++++++++++++++++++-- spec/requests/case_log_controller_spec.rb | 18 ++++++++++ 3 files changed, 69 insertions(+), 6 deletions(-) diff --git a/app/controllers/case_logs_controller.rb b/app/controllers/case_logs_controller.rb index f3753058e..8201254d5 100644 --- a/app/controllers/case_logs_controller.rb +++ b/app/controllers/case_logs_controller.rb @@ -33,9 +33,18 @@ class CaseLogsController < ApplicationController end end - # We don't have a dedicated non-editable show view def show - edit + respond_to do |format| + # We don't have a dedicated non-editable show view + format.html { edit } + format.json do + if (case_log = CaseLog.find_by(id: params[:id])) + render json: case_log, status: :ok + else + render json: { error: "Case Log #{params[:id]} not found" }, status: :not_found + end + end + end end def edit @@ -90,7 +99,7 @@ class CaseLogsController < ApplicationController private - API_ACTIONS = %w[create update destroy].freeze + API_ACTIONS = %w[create show update destroy].freeze def question_responses(questions_for_page) questions_for_page.each_with_object({}) do |(question_key, question_info), result| diff --git a/docs/api/DLUHC-CORE-Data.v1.json b/docs/api/DLUHC-CORE-Data.v1.json index 00bc39473..8c796fa71 100644 --- a/docs/api/DLUHC-CORE-Data.v1.json +++ b/docs/api/DLUHC-CORE-Data.v1.json @@ -30,7 +30,22 @@ } }, "404": { - "description": "Not Found" + "description": "Not Found", + "content": { + "application/json": { + "schema": { + "type": "object", + "properties": {} + }, + "examples": { + "Not found": { + "value": { + "error": "Case Log 67 not found" + } + } + } + } + } } }, "operationId": "get-case_logs-case_logs-:id", @@ -70,7 +85,13 @@ "type": "object", "properties": {} }, - "examples": {} + "examples": { + "Not found": { + "value": { + "error": "Case Log 67 not found" + } + } + } } } }, @@ -127,7 +148,22 @@ "description": "No Content" }, "404": { - "description": "Not Found" + "description": "Not Found", + "content": { + "application/json": { + "schema": { + "type": "object", + "properties": {} + }, + "examples": { + "Not found": { + "value": { + "error": "Case Log 67 not found" + } + } + } + } + } } }, "description": "Delete a case log", diff --git a/spec/requests/case_log_controller_spec.rb b/spec/requests/case_log_controller_spec.rb index 9dab538b0..dc67b76e1 100644 --- a/spec/requests/case_log_controller_spec.rb +++ b/spec/requests/case_log_controller_spec.rb @@ -99,6 +99,24 @@ RSpec.describe CaseLogsController, type: :request do end end + describe "GET" do + let(:case_log) { FactoryBot.create(:case_log, :completed) } + let(:id) { case_log.id } + + before do + get "/case_logs/#{id}", headers: headers + end + + it "returns http success" do + expect(response).to have_http_status(:success) + end + + it "returns a serialized Case Log" do + json_response = JSON.parse(response.body) + expect(json_response["status"]).to eq(case_log.status) + end + end + describe "PATCH" do let(:case_log) do FactoryBot.create(:case_log, :in_progress, tenant_code: "Old Value", property_postcode: "Old Value")