Commit cffc8899 authored by Matija Čupić's avatar Matija Čupić

Rename CheckGcpProjectBillingService to ListGcpProjectsService

parent d1052289
class CheckGcpProjectBillingService class ListGcpProjectsService
def execute(token) def execute(token)
client = GoogleApi::CloudPlatform::Client.new(token, nil) client = GoogleApi::CloudPlatform::Client.new(token, nil)
# Lists only projects with billing enabled
client.projects_list.select do |project| client.projects_list.select do |project|
begin begin
client.projects_get_billing_info(project.project_id).billing_enabled client.projects_get_billing_info(project.project_id).billing_enabled
......
...@@ -37,7 +37,7 @@ class CheckGcpProjectBillingWorker ...@@ -37,7 +37,7 @@ class CheckGcpProjectBillingWorker
return unless token return unless token
return unless try_obtain_lease_for(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) update_billing_change_counter(self.class.get_billing_state(token), billing_enabled_state)
self.class.set_billing_state(token, billing_enabled_state) self.class.set_billing_state(token, billing_enabled_state)
end end
......
require 'spec_helper' require 'spec_helper'
describe CheckGcpProjectBillingService do describe ListGcpProjectsService do
include GoogleApi::CloudPlatformHelpers include GoogleApi::CloudPlatformHelpers
let(:service) { described_class.new } let(:service) { described_class.new }
......
...@@ -22,13 +22,13 @@ describe CheckGcpProjectBillingWorker do ...@@ -22,13 +22,13 @@ describe CheckGcpProjectBillingWorker do
end end
it 'calls the service' do 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 subject
end end
it 'stores billing status in redis' do 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) expect(described_class).to receive(:set_billing_state).with(token, true)
subject subject
...@@ -41,7 +41,7 @@ describe CheckGcpProjectBillingWorker do ...@@ -41,7 +41,7 @@ describe CheckGcpProjectBillingWorker do
end end
it 'does not call the service' do it 'does not call the service' do
expect(CheckGcpProjectBillingService).not_to receive(:new) expect(ListGcpProjectsService).not_to receive(:new)
subject subject
end end
...@@ -54,7 +54,7 @@ describe CheckGcpProjectBillingWorker do ...@@ -54,7 +54,7 @@ describe CheckGcpProjectBillingWorker do
end end
it 'does not call the service' do it 'does not call the service' do
expect(CheckGcpProjectBillingService).not_to receive(:new) expect(ListGcpProjectsService).not_to receive(:new)
subject subject
end end
...@@ -77,7 +77,7 @@ describe CheckGcpProjectBillingWorker do ...@@ -77,7 +77,7 @@ describe CheckGcpProjectBillingWorker do
context 'when the current state is false' do context 'when the current state is false' do
before do before do
expect(CheckGcpProjectBillingService).to receive_message_chain(:new, :execute).and_return([]) expect(ListGcpProjectsService).to receive_message_chain(:new, :execute).and_return([])
end end
it 'increments the billing change counter' do it 'increments the billing change counter' do
...@@ -89,7 +89,7 @@ describe CheckGcpProjectBillingWorker do ...@@ -89,7 +89,7 @@ describe CheckGcpProjectBillingWorker do
context 'when the current state is true' do context 'when the current state is true' do
before 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 end
it 'increments the billing change counter' do it 'increments the billing change counter' do
...@@ -103,7 +103,7 @@ describe CheckGcpProjectBillingWorker do ...@@ -103,7 +103,7 @@ describe CheckGcpProjectBillingWorker do
context 'when previous state was true' do context 'when previous state was true' do
before do before do
expect(described_class).to receive(:get_billing_state).and_return(true) 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 end
it 'increment the billing change counter' do it 'increment the billing change counter' do
......
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