From f7a51bbcf8ecd3f3dbb29ccbcee90c3706c2e50d Mon Sep 17 00:00:00 2001 From: Owen Nelson Date: Wed, 23 Oct 2024 22:06:11 -0700 Subject: [PATCH] Libs(Ruby): add a kitchen sink test This test is like the others added across our other libs. It walks through some light API interactions just to check how the serialization is working WRT nullable containers and empty response bodies. Setting `SVIX_TOKEN` and `SVIX_SERVER_URL` env vars will optionally enable the test which is skipped otherwise. --- ruby/spec/kitchen_sink_spec.rb | 51 ++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 ruby/spec/kitchen_sink_spec.rb diff --git a/ruby/spec/kitchen_sink_spec.rb b/ruby/spec/kitchen_sink_spec.rb new file mode 100644 index 000000000..aec5973d4 --- /dev/null +++ b/ruby/spec/kitchen_sink_spec.rb @@ -0,0 +1,51 @@ +# frozen_string_literal: true + +require_relative "../lib/svix" + +token = ENV["SVIX_TOKEN"] +server_url = ENV["SVIX_SERVER_URL"] +test_client = nil + +if token.nil? || server_url.nil? + warn("Unable to instantiate test client without both `SVIX_TOKEN` and `SVIX_SERVER_URL`") +else + opts = Svix::SvixOptions.new(false, server_url) + test_client = Svix::Client.new(token, opts) +end + +RSpec.describe Svix::Client do + describe "Endpoint CRUD", :if => !test_client.nil? do + it "seems to work okay" do + app = test_client.application.create(Svix::ApplicationIn.new(name: "App")) + + begin + test_client.event_type.create(Svix::EventTypeIn.new(name: "event.started", description: "Something started")) + rescue Svix::ApiError => err + # Conflicts are expected from test run to test run, but other statuses are not. + expect(err.code).to eq(409) + end + begin + test_client.event_type.create(Svix::EventTypeIn.new(name: "event.ended", description: "Something ended")) + rescue Svix::ApiError => err + # Conflicts are expected from test run to test run, but other statuses are not. + expect(err.code).to eq(409) + end + + ep = test_client.endpoint.create( + app.id, + Svix::EndpointIn.new(url: "https://example.svix.com/", channels: %w[ch0 ch1]) + ) + + expect(ep.channels.to_set).to eq(%w[ch0 ch1].to_set) + expect(ep.filter_types).to be_nil + + ep_patched = test_client.endpoint.patch(app.id, ep.id, Svix::EndpointPatch.new(filter_types: %w[event.started event.ended])) + + expect(ep_patched.channels.to_set).to eq(%w[ch0 ch1].to_set) + expect(ep_patched.filter_types.to_set).to eq(%w[event.started event.ended].to_set) + + # If the serialization is handling empty response bodies, this should not throw an exception + test_client.endpoint.delete(app.id, ep.id) + end + end +end