Skip to content

Commit

Permalink
reflect actual school constraints in API specification
Browse files Browse the repository at this point in the history
  • Loading branch information
starswan committed Oct 24, 2024
1 parent 197adf2 commit 0f7e93c
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 39 deletions.
8 changes: 5 additions & 3 deletions app/controllers/api/v2/vacancies_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions app/views/api/v2/vacancies/_show.json.jbuilder
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,16 @@ 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
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?
112 changes: 80 additions & 32 deletions spec/requests/api/v2/vacancies_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 },
Expand All @@ -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,
Expand Down Expand Up @@ -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 },
Expand All @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -223,7 +272,7 @@
},
}

response(200, "successful") do
response(201, "successful") do
let(:api_version) { "2" }

after do |example|
Expand Down Expand Up @@ -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] = {
Expand All @@ -282,7 +332,6 @@

response(200, "successful") do
let(:api_version) { "2" }
let(:id) { "123" }

after do |example|
example.metadata[:response][:content] = {
Expand All @@ -300,7 +349,6 @@

response(204, "successful") do
let(:api_version) { "2" }
let(:id) { "123" }

run_test!
end
Expand Down

0 comments on commit 0f7e93c

Please sign in to comment.