summaryrefslogtreecommitdiff
path: root/qa/spec/runtime/feature_spec.rb
blob: 192299b78574161963be663be669dde6c5c91a81 (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
32
33
34
35
36
37
38
39
40
41
# frozen_string_literal: true

describe QA::Runtime::Feature do
  let(:api_client) { double('QA::Runtime::API::Client') }
  let(:request) { Struct.new(:url).new('http://api') }
  let(:response) { Struct.new(:code).new(201) }

  before do
    allow(described_class).to receive(:api_client).and_return(api_client)
  end

  describe '.enable' do
    it 'enables a feature flag' do
      expect(QA::Runtime::API::Request)
        .to receive(:new)
        .with(api_client, "/features/a-flag")
        .and_return(request)
      expect(described_class)
        .to receive(:post)
        .with(request.url, { value: true })
        .and_return(response)

      subject.enable('a-flag')
    end
  end

  describe '.disable' do
    it 'disables a feature flag' do
      expect(QA::Runtime::API::Request)
        .to receive(:new)
        .with(api_client, "/features/a-flag")
        .and_return(request)
      expect(described_class)
        .to receive(:post)
        .with(request.url, { value: false })
        .and_return(response)

      subject.disable('a-flag')
    end
  end
end