From 59d514df342760b9472b9a87a596396e2dd9cc07 Mon Sep 17 00:00:00 2001 From: Blake Erickson Date: Thu, 7 Jul 2022 20:04:50 -0500 Subject: [PATCH] DEV: Fix missing optional site.json fields (#17364) The site.json endpoint was missing some optional fields on the categories property that is returned. This commit documents the `parent_category_id` which is present if there are subcategories and it also documents the `custom_fields` property which the chat plugin is using causing some flaky tests. --- .../api/schemas/json/site_response.json | 10 ++++++++++ spec/requests/api/site_spec.rb | 20 +++++++++++++------ 2 files changed, 24 insertions(+), 6 deletions(-) diff --git a/spec/requests/api/schemas/json/site_response.json b/spec/requests/api/schemas/json/site_response.json index 62055ef4b51..4b5c4af24c0 100644 --- a/spec/requests/api/schemas/json/site_response.json +++ b/spec/requests/api/schemas/json/site_response.json @@ -634,6 +634,16 @@ }, "can_edit": { "type": "boolean" + }, + "custom_fields": { + "type": [ + "object", + "null" + ], + "additionalProperties": true + }, + "parent_category_id": { + "type": "integer" } }, "required": [ diff --git a/spec/requests/api/site_spec.rb b/spec/requests/api/site_spec.rb index ee8016f5189..9d026b5dfbb 100644 --- a/spec/requests/api/site_spec.rb +++ b/spec/requests/api/site_spec.rb @@ -3,7 +3,9 @@ require 'swagger_helper' describe 'site' do - let(:admin) { Fabricate(:admin) } + fab!(:admin) { Fabricate(:admin) } + fab!(:category) { Fabricate(:category) } + fab!(:subcategory) { Fabricate(:category, parent_category: category) } before do Jobs.run_immediately! @@ -21,12 +23,18 @@ describe 'site' do produces 'application/json' response '200', 'success response' do - expected_response_schema = load_spec_schema('site_response') - schema expected_response_schema + begin + Site.preloaded_category_custom_fields << "no_oddjob" - it_behaves_like "a JSON endpoint", 200 do - let(:expected_response_schema) { expected_response_schema } - let(:expected_request_schema) { expected_request_schema } + expected_response_schema = load_spec_schema('site_response') + schema expected_response_schema + + it_behaves_like "a JSON endpoint", 200 do + let(:expected_response_schema) { expected_response_schema } + let(:expected_request_schema) { expected_request_schema } + end + ensure + Site.preloaded_category_custom_fields = Set.new end end end