Skip to content

Commit

Permalink
Update source for BOPS production cases
Browse files Browse the repository at this point in the history
  • Loading branch information
benbaumann95 committed Aug 14, 2024
1 parent e80b389 commit 9c3aaec
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 10 deletions.
6 changes: 2 additions & 4 deletions app/services/apis/bops/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,8 @@ class Client
def call(local_authority, submission)
faraday(local_authority).post("planning_applications") do |request|
request.options[:timeout] = TIMEOUT
request.body = submission.merge(
"send_email" => "false",
"from_production" => "true"
).to_json
submission["metadata"]["source"] = "BOPS production"
request.body = submission.to_json
end
end

Expand Down
1 change: 1 addition & 0 deletions docs/schema-update.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Periodically we need to make changes based on a new release of the [ODP schema][
- Create new version directories at `engines/bops_api/schemas/odp/$VERSION/` and `engines/bops_api/spec/fixtures/examples/odp/$VERSION/`
- Update the version number and source URL in `engines/bops_api/lib/bops_api/schemas.rb`
- Save a copy of the new `schema.json` as `engines/bops_api/schemas/odp/$VERSION/submission.json`
- Within the `metadata` key, edit the `source` type to be any string as we want to enable different submission services. Currently this is set as `"const": "PlanX"` so this needs to be removed until future versions allow for other sources.
- Copy the other JSON files from the previous version to the current version: we manage these ourselves separately from the main release cycle
- Retrieve example responses from the [ODP schema examples], using the correct tag and subdirectory for the new version (e.g., tag `v3.1.4` subdirectory `v3.1.4/examples/`)
- Note that these do not all match our naming scheme but mostly do correspond in a logical way; e.g., their `lawfulDevelopmentCertificate/existing.json` becomes our `validLawfulDevelopmentCeriticateExisting.json` and so on
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def perform(planning_application:, user:, files:, params:, email_sending_permitt
@user = user
@params = params

AnonymisationService.new(planning_application:).call! if planning_application.from_production?
Application::AnonymisationService.new(planning_application:).call! if planning_application.from_production?
process_document_checklist_items(planning_application)
Application::DocumentsService.new(planning_application:, user:, files:).call!

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def call!

private

attr_reader :local_authority, :params, :user
attr_reader :local_authority, :params, :user, :email_sending_permitted

def data_params
@data_params ||= params.fetch(:data)
Expand Down Expand Up @@ -67,14 +67,14 @@ def parsers
def other_params
{
user_role: data_params[:user_role],
from_production: params[:from_production].present?
from_production: from_bops_production?
}
end

def save!(planning_application)
PlanningApplication.transaction do
if planning_application.save!
PlanningApplicationDependencyJob.perform_later(planning_application:, user:, files:, params:, email_sending_permitted: @email_sending_permitted)
PlanningApplicationDependencyJob.perform_later(planning_application:, user:, files:, params:, email_sending_permitted:)
end
end

Expand All @@ -94,6 +94,10 @@ def initialize_from_planning_application(planning_application)
def raise_not_permitted_in_production_error
raise BopsApi::Errors::NotPermittedError, "Creating planning applications using this endpoint is not permitted in production"
end

def from_bops_production?
params.dig("metadata", "source") == "BOPS production"
end
end
end
end
1 change: 0 additions & 1 deletion engines/bops_api/schemas/odp/v0.7.0/submission.json
Original file line number Diff line number Diff line change
Expand Up @@ -8464,7 +8464,6 @@
"type": "object"
},
"source": {
"const": "PlanX",
"type": "string"
},
"submittedAt": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -534,13 +534,22 @@
before do
allow(ENV).to receive(:fetch).and_call_original
allow(ENV).to receive(:fetch).with("BOPS_ENVIRONMENT", "development").and_return("production")
params[:metadata][:source] = "BOPS production"
end

it "calls the post application to staging job" do
create_planning_application

expect(BopsApi::PostApplicationToStagingJob).to have_been_enqueued
end

it "calls the anonymisation service" do
expect(BopsApi::Application::AnonymisationService).to receive(:new).and_call_original
expect(BopsApi::Application::DocumentsService).to receive(:new).and_call_original

create_planning_application
perform_enqueued_jobs
end
end
end
end
Expand Down
1 change: 0 additions & 1 deletion engines/bops_api/swagger/v2/swagger_doc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5886,7 +5886,6 @@ components:
- fee
type: object
source:
const: PlanX
type: string
submittedAt:
"$ref": "#/components/definitions/DateTime"
Expand Down

0 comments on commit 9c3aaec

Please sign in to comment.