Add specs for billing_enabled change counter
This commit is contained in:
parent
0dd202007f
commit
7f430a91bd
1 changed files with 66 additions and 0 deletions
|
@ -6,6 +6,11 @@ describe CheckGcpProjectBillingWorker do
|
|||
|
||||
subject { described_class.new.perform('token_key') }
|
||||
|
||||
before do
|
||||
allow_any_instance_of(described_class).to receive(:check_previous_state)
|
||||
allow_any_instance_of(described_class).to receive(:update_billing_change_counter)
|
||||
end
|
||||
|
||||
context 'when there is a token in redis' do
|
||||
before do
|
||||
allow(described_class).to receive(:get_session_token).and_return(token)
|
||||
|
@ -58,4 +63,65 @@ describe CheckGcpProjectBillingWorker do
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe 'billing change counter' do
|
||||
subject { described_class.new.perform('token_key') }
|
||||
|
||||
before do
|
||||
allow(described_class).to receive(:get_session_token).and_return('bogustoken')
|
||||
allow_any_instance_of(described_class).to receive(:try_obtain_lease_for).and_return('randomuuid')
|
||||
Gitlab::Redis::SharedState.with do |redis|
|
||||
allow(redis).to receive(:set)
|
||||
end
|
||||
end
|
||||
|
||||
context 'when previous state was false' do
|
||||
before do
|
||||
expect_any_instance_of(described_class).to receive(:check_previous_state).and_return('false')
|
||||
end
|
||||
|
||||
context 'when the current state is false' do
|
||||
before do
|
||||
expect(CheckGcpProjectBillingService).to receive_message_chain(:new, :execute).and_return([])
|
||||
end
|
||||
|
||||
it 'does not increment the billing change counter' do
|
||||
Gitlab::Redis::SharedState.with do |redis|
|
||||
expect(redis).not_to receive(:incr)
|
||||
end
|
||||
|
||||
subject
|
||||
end
|
||||
end
|
||||
|
||||
context 'when the current state is true' do
|
||||
before do
|
||||
expect(CheckGcpProjectBillingService).to receive_message_chain(:new, :execute).and_return([double])
|
||||
end
|
||||
|
||||
it 'increments the billing change counter' do
|
||||
Gitlab::Redis::SharedState.with do |redis|
|
||||
expect(redis).to receive(:incr)
|
||||
end
|
||||
|
||||
subject
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'when previous state was true' do
|
||||
before do
|
||||
expect_any_instance_of(described_class).to receive(:check_previous_state).and_return('true')
|
||||
expect(CheckGcpProjectBillingService).to receive_message_chain(:new, :execute).and_return([double])
|
||||
end
|
||||
|
||||
it 'does not increment the billing change counter' do
|
||||
Gitlab::Redis::SharedState.with do |redis|
|
||||
expect(redis).not_to receive(:incr)
|
||||
end
|
||||
|
||||
subject
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue