From c5d0d01a052a4fd23fae35e1d6eb3fda3d7d367f Mon Sep 17 00:00:00 2001 From: Jumpei Matsuda Date: Wed, 15 Aug 2018 02:08:35 +0900 Subject: [PATCH] Fixed specs --- lib/remocon/command/validate_command.rb | 1 + spec/remocon/command/lib/request_spec.rb | 18 +++++++++++ spec/remocon/command/validate_command_spec.rb | 31 ++----------------- 3 files changed, 21 insertions(+), 29 deletions(-) diff --git a/lib/remocon/command/validate_command.rb b/lib/remocon/command/validate_command.rb index e37dc5d..4659658 100644 --- a/lib/remocon/command/validate_command.rb +++ b/lib/remocon/command/validate_command.rb @@ -43,6 +43,7 @@ def run else # validation api cannot validate etag STDERR.puts "the latest etag was updated" + false end else # https://firebase.google.com/docs/remote-config/use-config-rest#validate_before_publishing diff --git a/spec/remocon/command/lib/request_spec.rb b/spec/remocon/command/lib/request_spec.rb index 08dfb91..e72bbe8 100644 --- a/spec/remocon/command/lib/request_spec.rb +++ b/spec/remocon/command/lib/request_spec.rb @@ -26,6 +26,24 @@ module Remocon end end + context "#validate" do + it "should send a json request with an etag and a token" do + expect(Net::HTTP::Put).to receive(:new).with(URI.parse("https://firebaseremoteconfig.googleapis.com/v1/projects/fixture/remoteConfig?validate_only=true").request_uri, any_args) do |_, headers| + expect(headers).to include( + "Authorization" => "Bearer valid_token", + "Content-Type" => "application/json; UTF8", + "If-Match" => "raw_etag" + ) + end.and_call_original + + Tempfile.open do |t| + t.write("{}") + + Request.validate(config, t) + end + end + end + context "#pull" do it "should request with a token" do expect(Request).to receive(:open).with("https://firebaseremoteconfig.googleapis.com/v1/projects/fixture/remoteConfig", { diff --git a/spec/remocon/command/validate_command_spec.rb b/spec/remocon/command/validate_command_spec.rb index be87bc0..da7a621 100644 --- a/spec/remocon/command/validate_command_spec.rb +++ b/spec/remocon/command/validate_command_spec.rb @@ -78,6 +78,8 @@ module Command before do allow(STDOUT).to receive(:puts) allow(STDERR).to receive(:puts) + allow_any_instance_of(Net::HTTPOK).to receive(:header).and_return({ "etag" => "XYZXYZXYZXYZ-0" }) + allow(Remocon::Request).to receive(:validate).and_return([Net::HTTPOK.new(nil, 200, nil), "{}"]) end context "etags are mismatch" do @@ -86,10 +88,6 @@ module Command end it "should return an error" do - expect(command).to receive(:print_errors).with(any_args) do |errors| - expect(errors.any? { |e| e.kind_of?(ValidationError) }).to be_truthy - end - expect(command.run).to be_falsey end end @@ -100,35 +98,10 @@ module Command end it "should not return any errors" do - expect(command).to receive(:print_errors).with([]) expect(command.run).to be_truthy end end end - - context "a parameters file is invalid" do - let(:options) do - { - parameters: fixture_path("invalid_parameters_1.yml"), - conditions: fixture_path("valid_conditions.yml"), - etag: fixture_path("etag_file"), - id: "dragon", - token: "valid_token" - } - end - - before do - allow(Remocon::Request).to receive(:fetch_etag).and_return("XYZXYZXYZXYZ") - end - - it "should return an error" do - expect(command).to receive(:print_errors).with(any_args) do |errors| - expect(errors.any? { |e| e.kind_of?(ValidationError) }).to be_truthy - end - - expect(command.run).to be_falsey - end - end end end end