Rename CheckGcpProjectBillingService to ListGcpProjectsService

This commit is contained in:
Matija Čupić 2018-04-20 16:33:20 +02:00
parent d105228913
commit cffc8899b7
No known key found for this signature in database
GPG key ID: 4BAF84FFACD2E5DE
4 changed files with 11 additions and 10 deletions

View file

@ -1,6 +1,7 @@
class CheckGcpProjectBillingService
class ListGcpProjectsService
def execute(token)
client = GoogleApi::CloudPlatform::Client.new(token, nil)
# Lists only projects with billing enabled
client.projects_list.select do |project|
begin
client.projects_get_billing_info(project.project_id).billing_enabled

View file

@ -37,7 +37,7 @@ class CheckGcpProjectBillingWorker
return unless token
return unless try_obtain_lease_for(token)
billing_enabled_state = !CheckGcpProjectBillingService.new.execute(token).empty?
billing_enabled_state = !ListGcpProjectsService.new.execute(token).empty?
update_billing_change_counter(self.class.get_billing_state(token), billing_enabled_state)
self.class.set_billing_state(token, billing_enabled_state)
end

View file

@ -1,6 +1,6 @@
require 'spec_helper'
describe CheckGcpProjectBillingService do
describe ListGcpProjectsService do
include GoogleApi::CloudPlatformHelpers
let(:service) { described_class.new }

View file

@ -22,13 +22,13 @@ describe CheckGcpProjectBillingWorker do
end
it 'calls the service' do
expect(CheckGcpProjectBillingService).to receive_message_chain(:new, :execute).and_return([double])
expect(ListGcpProjectsService).to receive_message_chain(:new, :execute).and_return([double])
subject
end
it 'stores billing status in redis' do
expect(CheckGcpProjectBillingService).to receive_message_chain(:new, :execute).and_return([double])
expect(ListGcpProjectsService).to receive_message_chain(:new, :execute).and_return([double])
expect(described_class).to receive(:set_billing_state).with(token, true)
subject
@ -41,7 +41,7 @@ describe CheckGcpProjectBillingWorker do
end
it 'does not call the service' do
expect(CheckGcpProjectBillingService).not_to receive(:new)
expect(ListGcpProjectsService).not_to receive(:new)
subject
end
@ -54,7 +54,7 @@ describe CheckGcpProjectBillingWorker do
end
it 'does not call the service' do
expect(CheckGcpProjectBillingService).not_to receive(:new)
expect(ListGcpProjectsService).not_to receive(:new)
subject
end
@ -77,7 +77,7 @@ describe CheckGcpProjectBillingWorker do
context 'when the current state is false' do
before do
expect(CheckGcpProjectBillingService).to receive_message_chain(:new, :execute).and_return([])
expect(ListGcpProjectsService).to receive_message_chain(:new, :execute).and_return([])
end
it 'increments the billing change counter' do
@ -89,7 +89,7 @@ describe CheckGcpProjectBillingWorker do
context 'when the current state is true' do
before do
expect(CheckGcpProjectBillingService).to receive_message_chain(:new, :execute).and_return([double])
expect(ListGcpProjectsService).to receive_message_chain(:new, :execute).and_return([double])
end
it 'increments the billing change counter' do
@ -103,7 +103,7 @@ describe CheckGcpProjectBillingWorker do
context 'when previous state was true' do
before do
expect(described_class).to receive(:get_billing_state).and_return(true)
expect(CheckGcpProjectBillingService).to receive_message_chain(:new, :execute).and_return([double])
expect(ListGcpProjectsService).to receive_message_chain(:new, :execute).and_return([double])
end
it 'increment the billing change counter' do