Skip to content

Commit 55bb078

Browse files
committed
Add testing API endpoint to enqueue vaccinations search in NHS
Allow end-to-end tests to trigger `EnqueueVaccinationsSearchInNHSJob` directly rather than through the Sidekiq Scheduler's `/sidekiq/recurring-jobs/{name}` URL. Mirrors the existing `reporting_refresh` controller: `?wait=true` runs `perform_now` and returns 200, otherwise enqueues with `perform_later` and returns 202. Inherits the `:testing_api` Flipper / local-env gate from `API::Testing::BaseController`.
1 parent edc4163 commit 55bb078

3 files changed

Lines changed: 44 additions & 0 deletions

File tree

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# frozen_string_literal: true
2+
3+
class API::Testing::VaccinationsSearchInNHSController < API::Testing::BaseController
4+
def create
5+
if params[:wait].present?
6+
EnqueueVaccinationsSearchInNHSJob.perform_now
7+
render status: :ok
8+
else
9+
EnqueueVaccinationsSearchInNHSJob.perform_later
10+
render status: :accepted
11+
end
12+
end
13+
end

config/routes.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,8 @@
116116
resources :teams, only: :destroy, param: :workgroup
117117
post "/onboard", to: "onboard#create"
118118
get "refresh-reporting", to: "reporting_refresh#create"
119+
post "vaccinations-search-in-nhs",
120+
to: "vaccinations_search_in_nhs#create"
119121
end
120122
end
121123

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# frozen_string_literal: true
2+
3+
describe "/api/testing/vaccinations-search-in-nhs" do
4+
before { Flipper.enable(:testing_api) }
5+
after { Flipper.disable(:testing_api) }
6+
7+
describe "POST" do
8+
context "without wait param" do
9+
it "enqueues the job and responds with accepted" do
10+
expect {
11+
post "/api/testing/vaccinations-search-in-nhs"
12+
}.to have_enqueued_job(EnqueueVaccinationsSearchInNHSJob)
13+
expect(response).to have_http_status(:accepted)
14+
end
15+
end
16+
17+
context "with wait=true" do
18+
before do
19+
allow(EnqueueVaccinationsSearchInNHSJob).to receive(:perform_now)
20+
end
21+
22+
it "runs the job synchronously and responds with ok" do
23+
post "/api/testing/vaccinations-search-in-nhs", params: { wait: "true" }
24+
expect(EnqueueVaccinationsSearchInNHSJob).to have_received(:perform_now)
25+
expect(response).to have_http_status(:ok)
26+
end
27+
end
28+
end
29+
end

0 commit comments

Comments
 (0)