diff --git a/test/sanity/configuration_test.rb b/test/sanity/configuration_test.rb index e6ca17c..6caf840 100644 --- a/test/sanity/configuration_test.rb +++ b/test/sanity/configuration_test.rb @@ -5,6 +5,17 @@ describe Sanity::Configuration do subject { Sanity::Configuration.new } + after do + Sanity.use_global_config = false + Sanity.configure do |config| + config.project_id = "" + config.dataset = "" + config.api_version = "" + config.token = "" + config.use_cdn = false + end + end + it { assert_equal "", subject.project_id } it { assert_equal "", subject.dataset } it { assert_equal "", subject.api_version } diff --git a/test/sanity/http/where_test.rb b/test/sanity/http/where_test.rb new file mode 100644 index 0000000..e12aaf9 --- /dev/null +++ b/test/sanity/http/where_test.rb @@ -0,0 +1,61 @@ +# frozen_string_literal: true + +require "test_helper" + +describe Sanity::Http::Where do + let(:klass) { Sanity::Http::Where } + let(:resource_class) do + Class.new do + def self.where_api_endpoint + "test" + end + end + end + + describe "query parameter serialization" do + describe "with GET requests" do + subject { klass.new(resource_klass: resource_class, variables: variables) } + + describe "with different variable types" do + let(:variables) do + { + string_var: "hello", + array_var: [1, 2, 3], + array_of_strings: ["foo", "bar"], + hash_var: {"foo" => "bar"}, + number_var: 42, + boolean_var: true + } + end + + it "properly serializes variables in the query string" do + uri = subject.send(:uri) + decoded_query = URI.decode_www_form_component(uri.query) + + assert_includes decoded_query, "$string_var=\"hello\"" + assert_includes decoded_query, "$array_var=[1,2,3]" + assert_includes decoded_query, "$array_of_strings=[\"foo\",\"bar\"]" + assert_includes decoded_query, "$hash_var={\"foo\":\"bar\"}" + assert_includes decoded_query, "$number_var=42" + assert_includes decoded_query, "$boolean_var=true" + end + end + end + + describe "with POST requests" do + subject { klass.new(resource_klass: resource_class, variables: variables, use_post: true) } + + let(:variables) do + { + "string_var" => "hello", + "array_var" => [1, 2, 3] + } + end + + it "includes variables in the request body" do + body = JSON.parse(subject.send(:request_body)) + assert_equal variables, body["params"] + end + end + end +end