Skip to content

Commit

Permalink
Libs(Ruby): add a kitchen sink test
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
svix-onelson committed Oct 24, 2024
1 parent 0275564 commit f7a51bb
Showing 1 changed file with 51 additions and 0 deletions.
51 changes: 51 additions & 0 deletions ruby/spec/kitchen_sink_spec.rb
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit f7a51bb

Please sign in to comment.