File: dsl_spec.rb

package info (click to toggle)
ruby-flipper 0.26.2-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,288 kB
  • sloc: ruby: 16,377; sh: 61; javascript: 24; makefile: 14
file content (82 lines) | stat: -rw-r--r-- 2,620 bytes parent folder | download | duplicates (2)
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
require 'flipper/cloud/configuration'
require 'flipper/cloud/dsl'
require 'flipper/adapters/operation_logger'
require 'flipper/adapters/instrumented'

RSpec.describe Flipper::Cloud::DSL do
  it 'delegates everything to flipper instance' do
    cloud_configuration = Flipper::Cloud::Configuration.new({
      token: "asdf",
      sync_secret: "tasty",
    })
    dsl = described_class.new(cloud_configuration)
    expect(dsl.features).to eq(Set.new)
    expect(dsl.enabled?(:foo)).to be(false)
  end

  it 'delegates sync to cloud configuration' do
    stub = stub_request(:get, "https://www.flippercloud.io/adapter/features").
      with({
        headers: {
          'Flipper-Cloud-Token'=>'asdf',
        },
      }).to_return(status: 200, body: '{"features": {}}', headers: {})
    cloud_configuration = Flipper::Cloud::Configuration.new({
      token: "asdf",
      sync_secret: "tasty",
    })
    dsl = described_class.new(cloud_configuration)
    dsl.sync
    expect(stub).to have_been_requested
  end

  it 'delegates sync_secret to cloud configuration' do
    cloud_configuration = Flipper::Cloud::Configuration.new({
      token: "asdf",
      sync_secret: "tasty",
    })
    dsl = described_class.new(cloud_configuration)
    expect(dsl.sync_secret).to eq("tasty")
  end

  context "when sync_method is webhook" do
    let(:local_adapter) do
      Flipper::Adapters::OperationLogger.new Flipper::Adapters::Memory.new
    end

    let(:cloud_configuration) do
      cloud_configuration = Flipper::Cloud::Configuration.new({
        token: "asdf",
        sync_secret: "tasty",
        local_adapter: local_adapter
      })
    end

    subject do
      described_class.new(cloud_configuration)
    end

    it "sends reads to local adapter" do
      subject.features
      subject.enabled?(:foo)
      expect(local_adapter.count(:features)).to be(1)
      expect(local_adapter.count(:get)).to be(1)
    end

    it "sends writes to cloud and local" do
      add_stub = stub_request(:post, "https://www.flippercloud.io/adapter/features").
        with({headers: {'Flipper-Cloud-Token'=>'asdf'}}).
        to_return(status: 200, body: '{}', headers: {})
      enable_stub = stub_request(:post, "https://www.flippercloud.io/adapter/features/foo/boolean").
        with(headers: {'Flipper-Cloud-Token'=>'asdf'}).
        to_return(status: 200, body: '{}', headers: {})

      subject.enable(:foo)

      expect(local_adapter.count(:add)).to be(1)
      expect(local_adapter.count(:enable)).to be(1)
      expect(add_stub).to have_been_requested
      expect(enable_stub).to have_been_requested
    end
  end
end