Skip to content

Commit

Permalink
Fixed specs
Browse files Browse the repository at this point in the history
  • Loading branch information
jmatsu committed Aug 14, 2018
1 parent 889e998 commit c5d0d01
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 29 deletions.
1 change: 1 addition & 0 deletions lib/remocon/command/validate_command.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 18 additions & 0 deletions spec/remocon/command/lib/request_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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", {
Expand Down
31 changes: 2 additions & 29 deletions spec/remocon/command/validate_command_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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

0 comments on commit c5d0d01

Please sign in to comment.