From 0f7e93ca5cee4cbf4f17c083efc1762325d843b5 Mon Sep 17 00:00:00 2001 From: starswan Date: Thu, 24 Oct 2024 11:29:01 +0100 Subject: [PATCH] reflect actual school constraints in API specification --- .../api/v2/vacancies_controller.rb | 8 +- .../api/v2/vacancies/_show.json.jbuilder | 8 +- spec/requests/api/v2/vacancies_spec.rb | 112 +++++++++++++----- 3 files changed, 89 insertions(+), 39 deletions(-) diff --git a/app/controllers/api/v2/vacancies_controller.rb b/app/controllers/api/v2/vacancies_controller.rb index 930ed8a37e..862cefd7c9 100644 --- a/app/controllers/api/v2/vacancies_controller.rb +++ b/app/controllers/api/v2/vacancies_controller.rb @@ -8,9 +8,11 @@ def index def create @vacancy = Vacancy.create!(vacancy_params) - # logger.warn "Errors #{@vacancy.errors.messages}" if @vacancy.errors.any? - - respond_to(&:json) + respond_to do |format| + format.json do + render status: :created + end + end end def update diff --git a/app/views/api/v2/vacancies/_show.json.jbuilder b/app/views/api/v2/vacancies/_show.json.jbuilder index 90fdaca989..a88eca1165 100644 --- a/app/views/api/v2/vacancies/_show.json.jbuilder +++ b/app/views/api/v2/vacancies/_show.json.jbuilder @@ -8,11 +8,11 @@ json.benefits_details vacancy.benefits_details json.starts_on vacancy.starts_on if vacancy.starts_on.present? json.visa_sponsorship_available vacancy.visa_sponsorship_available json.is_job_share vacancy.is_job_share if vacancy.is_job_share.present? -json.is_parental_leave_cover vacancy.is_parental_leave_cover if vacancy.is_parental_leave_cover.present? -json.school_visits vacancy.school_visits json.external_reference vacancy.external_reference json.job_roles vacancy.job_roles -json.school_urns(vacancy.organisations.map { |x| x.urn.to_i }) +json.schools do + json.school_urns(vacancy.organisations.map { |x| x.urn.to_i }) +end json.ect_suitable vacancy.ect_status == "ect_suitable" json.working_patterns vacancy.working_patterns json.contract_type vacancy.contract_type @@ -20,4 +20,4 @@ json.phases vacancy.phases if vacancy.key_stages.any? json.key_stages vacancy.key_stages end -json.subjects vacancy.subjects +json.subjects vacancy.subjects if vacancy.subjects.any? diff --git a/spec/requests/api/v2/vacancies_spec.rb b/spec/requests/api/v2/vacancies_spec.rb index a134dd9a0d..810c669a33 100644 --- a/spec/requests/api/v2/vacancies_spec.rb +++ b/spec/requests/api/v2/vacancies_spec.rb @@ -28,7 +28,7 @@ type: :object, additionalProperties: false, required: %i[external_advert_url expires_at starts_on job_title skills_and_experience salary external_reference - school_urns job_roles working_patterns contract_type phases publish_on], + job_roles working_patterns contract_type phases publish_on schools], properties: { external_advert_url: { type: :string, example: "https://example.com/jobs/123" }, publish_on: { type: :string, format: :date }, @@ -41,19 +41,43 @@ external_reference: { type: :string, example: "123GTZY" }, visa_sponsorship_available: { type: :boolean }, is_job_share: { type: :boolean }, - is_parental_leave_cover: { type: :boolean }, - school_visits: { type: :boolean }, - school_urns: { - type: :array, - minItems: 1, - items: { - type: :integer, - example: 12_345, - }, - }, - trust_uid: { - type: :integer, - example: 12_345, + schools: { + oneOf: [ + { + type: :object, + additionalProperties: false, + required: %i[school_urns], + properties: { + school_urns: { + type: :array, + minItems: 1, + items: { + type: :integer, + example: 12_345, + }, + }, + }, + }, + { + type: :object, + additionalProperties: false, + required: %i[trust_uid school_urns], + properties: { + trust_uid: { + type: :integer, + example: 12_345, + }, + school_urns: { + type: :array, + minItems: 0, + items: { + type: :integer, + example: 12_345, + }, + }, + }, + }, + ], }, job_roles: { type: :array, @@ -142,7 +166,7 @@ type: :object, additionalProperties: false, required: %i[external_advert_url expires_at job_title skills_and_experience salary visa_sponsorship_available reference - is_job_share school_visits school_urns job_roles working_patterns contract_type phase], + is_job_share job_roles working_patterns contract_type phase schools], properties: { external_advert_url: { type: :string, example: "https://example.com/jobs/123" }, publish_on: { type: :string, format: :date }, @@ -155,19 +179,43 @@ external_reference: { type: :string, example: "REF1234HYZ" }, visa_sponsorship_available: { type: :boolean }, is_job_share: { type: :boolean }, - is_parental_leave_cover: { type: :boolean }, - school_visits: { type: :boolean }, - school_urns: { - type: :array, - minItems: 1, - items: { - type: :integer, - example: 12_345, - }, - }, - trust_uid: { - type: :integer, - example: 12_345, + schools: { + oneOf: [ + { + type: :object, + additionalProperties: false, + required: %i[school_urns], + properties: { + school_urns: { + type: :array, + minItems: 1, + items: { + type: :integer, + example: 12_345, + }, + }, + }, + }, + { + type: :object, + additionalProperties: false, + required: %i[trust_uid school_urns], + properties: { + trust_uid: { + type: :integer, + example: 12_345, + }, + school_urns: { + type: :array, + minItems: 0, + items: { + type: :integer, + example: 12_345, + }, + }, + }, + }, + ], }, job_roles: { type: :array, @@ -179,6 +227,7 @@ }, ect_suitable: { type: :boolean, + description: "Whether or not this role is suitable for early career teachers (ECT). Defaults to false if not supplied", }, working_patterns: { type: :array, @@ -223,7 +272,7 @@ }, } - response(200, "successful") do + response(201, "successful") do let(:api_version) { "2" } after do |example| @@ -257,13 +306,14 @@ parameter name: "api_version", in: :path, type: :string, description: "api_version" parameter name: "id", in: :path, type: :string, description: "id" + let(:id) { create(:vacancy, :external).id } + get("show vacancy") do consumes "application/json" produces "application/json" response(200, "successful") do let(:api_version) { "2" } - let(:id) { "123" } after do |example| example.metadata[:response][:content] = { @@ -282,7 +332,6 @@ response(200, "successful") do let(:api_version) { "2" } - let(:id) { "123" } after do |example| example.metadata[:response][:content] = { @@ -300,7 +349,6 @@ response(204, "successful") do let(:api_version) { "2" } - let(:id) { "123" } run_test! end