summaryrefslogtreecommitdiff
path: root/spec/services/check_gcp_project_billing_service_spec.rb
blob: f0e39ba6f4960e468f0f31f2fb12b61d8fefdd00 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
require 'spec_helper'

describe CheckGcpProjectBillingService do
  let(:service) { described_class.new }
  let(:projects) { [double(name: 'first_project'), double(name: 'second_project')] }

  describe '#execute' do
    before do
      expect_any_instance_of(GoogleApi::CloudPlatform::Client)
        .to receive(:projects_list).and_return(projects)

      allow_any_instance_of(GoogleApi::CloudPlatform::Client)
        .to receive_message_chain(:projects_get_billing_info, :billingEnabled)
        .and_return(project_billing_enabled)
    end

    subject { service.execute('bogustoken') }

    context 'google account has a billing enabled gcp project' do
      let(:project_billing_enabled) { true }

      it { is_expected.to eq(projects) }
    end

    context 'google account does not have a billing enabled gcp project' do
      let(:project_billing_enabled) { false }

      it { is_expected.to eq([]) }
    end
  end
end