BigW Consortium Gitlab

Add Worker rerun action to GcpController

parent 63859419
class Projects::Clusters::GcpController < Projects::ApplicationController
before_action :authorize_read_cluster!
before_action :authorize_google_api, except: [:login]
before_action :authorize_google_project_billing, except: [:login, :check]
before_action :authorize_google_project_billing, except: [:login, :check, :run_check]
before_action :authorize_create_cluster!, only: [:new, :create]
STATUS_POLLING_INTERVAL = 1.minute.to_i
......@@ -32,6 +32,15 @@ class Projects::Clusters::GcpController < Projects::ApplicationController
end
end
def run_check
respond_to do |format|
format.json do
CheckGcpProjectBillingWorker.perform_async(token_in_session)
head :no_content
end
end
end
def new
@cluster = ::Clusters::Cluster.new.tap do |cluster|
cluster.build_provider_gcp
......
......@@ -192,6 +192,7 @@ constraints(ProjectUrlConstrainer.new) do
get '/gcp/new', to: 'clusters/gcp#new'
get '/gcp/login', to: 'clusters/gcp#login'
get '/gcp/check', to: 'clusters/gcp#check'
post '/gcp/check', to: 'clusters/gcp#run_check'
post '/gcp', to: 'clusters/gcp#create'
end
end
......
......@@ -138,6 +138,56 @@ describe Projects::Clusters::GcpController do
end
end
describe 'POST check' do
let(:user) { create(:user) }
before do
project.add_master(user)
sign_in(user)
end
describe 'functionality' do
context 'when access token is valid' do
before do
stub_google_api_validate_token
end
it 'calls check worker asynchronously' do
expect(CheckGcpProjectBillingWorker).to receive(:perform_async)
expect(go).to have_http_status(:no_content)
end
end
context 'when access token is expired' do
before do
stub_google_api_expired_token
end
it { expect(go).to redirect_to(gcp_login_project_clusters_path(project)) }
end
context 'when access token is not stored in session' do
it { expect(go).to redirect_to(gcp_login_project_clusters_path(project)) }
end
end
describe 'security' do
it { expect { go }.to be_allowed_for(:admin) }
it { expect { go }.to be_allowed_for(:owner).of(project) }
it { expect { go }.to be_allowed_for(:master).of(project) }
it { expect { go }.to be_denied_for(:developer).of(project) }
it { expect { go }.to be_denied_for(:reporter).of(project) }
it { expect { go }.to be_denied_for(:guest).of(project) }
it { expect { go }.to be_denied_for(:user) }
it { expect { go }.to be_denied_for(:external) }
end
def go
post :run_check, namespace_id: project.namespace, project_id: project, format: :json
end
end
describe 'GET new' do
describe 'functionality' do
let(:user) { create(:user) }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment