* feat: update the paths in the spec files * feat: update hardcoded paths with path helpers * chore: update hardcoded paths to path helpers * chore: hardcode describe blocks * chore: oops * feat: update some more hardcoded to use link_to's * fix broken tests * chore: admin_articles path * chore: oops remove rails helper * feat: add starting / * chore: more pre slashes * chore: add pre slashes * chore: some small typos * fix: oops
88 lines
2.8 KiB
Ruby
88 lines
2.8 KiB
Ruby
require "rails_helper"
|
|
|
|
RSpec.describe "/admin/advanced/data_update_scripts", type: :request do
|
|
let(:get_resource) { get admin_data_update_scripts_path }
|
|
|
|
context "when the user is not an tech admin" do
|
|
let(:user) { create(:user) }
|
|
|
|
before do
|
|
sign_in user
|
|
allow(Flipper).to receive(:enabled?).and_call_original
|
|
allow(Flipper).to receive(:enabled?).with(:data_update_scripts).and_return(true)
|
|
end
|
|
|
|
describe "GET /admin/advanced/data_update_scripts" do
|
|
it "blocks the request" do
|
|
expect { get_resource }.to raise_error(StandardError)
|
|
end
|
|
end
|
|
end
|
|
|
|
context "when the user is a tech admin" do
|
|
let(:user) { create(:user, :admin, :tech_admin) }
|
|
|
|
before do
|
|
sign_in user
|
|
allow(Flipper).to receive(:enabled?).and_call_original
|
|
allow(Flipper).to receive(:enabled?).with(:data_update_scripts).and_return(true)
|
|
end
|
|
|
|
describe "GET /admin/advanced/data_update_scripts" do
|
|
it "allows the request" do
|
|
get_resource
|
|
expect(response).to have_http_status(:ok)
|
|
end
|
|
|
|
it "displays the data_update_scripts" do
|
|
script = create(:data_update_script)
|
|
get_resource
|
|
|
|
expect(response.body).to include(script.id.to_s)
|
|
expect(response.body).to include(script.run_at.to_s)
|
|
expect(response.body).to include(script.created_at.to_s)
|
|
expect(response.body).to include(script.status.to_s)
|
|
end
|
|
|
|
it "displays a 'Rerun' button when the script status is failed" do
|
|
create(:data_update_script, status: "failed")
|
|
get_resource
|
|
expect(response.body).to include("Re-run")
|
|
end
|
|
end
|
|
|
|
describe "GET /admin/advanced/data_update_scripts/:id" do
|
|
let(:script) do
|
|
create(
|
|
:data_update_script,
|
|
file_name: "20200214151804_data_update_test_script",
|
|
status: "succeeded",
|
|
)
|
|
end
|
|
let(:script_id) { script.id }
|
|
|
|
it "returns a data update script" do
|
|
get admin_data_update_script_path(id: script_id)
|
|
|
|
expect(response).to have_http_status(:ok)
|
|
expect(script.id).to eq(response.parsed_body["response"]["id"])
|
|
expect(script.file_name).to eq(response.parsed_body["response"]["file_name"])
|
|
expect(script.status).to eq(response.parsed_body["response"]["status"])
|
|
end
|
|
end
|
|
|
|
describe "POST /admin/:id/force_run" do
|
|
let(:script) { create(:data_update_script, file_name: "20200214151804_data_update_test_script") }
|
|
let(:script_id) { script.id.to_s }
|
|
|
|
it "calls the the sidekiq worker" do
|
|
allow(DataUpdateWorker).to receive(:perform_async)
|
|
|
|
post force_run_admin_data_update_script_path(script_id)
|
|
sidekiq_perform_enqueued_jobs
|
|
|
|
expect(DataUpdateWorker).to have_received(:perform_async).with(script_id)
|
|
end
|
|
end
|
|
end
|
|
end
|