spec/flipper/cloud/dsl_spec.rb in flipper-cloud-0.20.0.beta1 vs spec/flipper/cloud/dsl_spec.rb in flipper-cloud-0.20.0.beta2
- old
+ new
@@ -1,8 +1,9 @@
require 'helper'
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({
@@ -38,7 +39,49 @@
sync_secret: "tasty",
sync_method: :webhook,
})
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",
+ sync_method: :webhook,
+ 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