Skip to content

Commit f7a51bb

Browse files
committed
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.
1 parent 0275564 commit f7a51bb

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed

ruby/spec/kitchen_sink_spec.rb

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# frozen_string_literal: true
2+
3+
require_relative "../lib/svix"
4+
5+
token = ENV["SVIX_TOKEN"]
6+
server_url = ENV["SVIX_SERVER_URL"]
7+
test_client = nil
8+
9+
if token.nil? || server_url.nil?
10+
warn("Unable to instantiate test client without both `SVIX_TOKEN` and `SVIX_SERVER_URL`")
11+
else
12+
opts = Svix::SvixOptions.new(false, server_url)
13+
test_client = Svix::Client.new(token, opts)
14+
end
15+
16+
RSpec.describe Svix::Client do
17+
describe "Endpoint CRUD", :if => !test_client.nil? do
18+
it "seems to work okay" do
19+
app = test_client.application.create(Svix::ApplicationIn.new(name: "App"))
20+
21+
begin
22+
test_client.event_type.create(Svix::EventTypeIn.new(name: "event.started", description: "Something started"))
23+
rescue Svix::ApiError => err
24+
# Conflicts are expected from test run to test run, but other statuses are not.
25+
expect(err.code).to eq(409)
26+
end
27+
begin
28+
test_client.event_type.create(Svix::EventTypeIn.new(name: "event.ended", description: "Something ended"))
29+
rescue Svix::ApiError => err
30+
# Conflicts are expected from test run to test run, but other statuses are not.
31+
expect(err.code).to eq(409)
32+
end
33+
34+
ep = test_client.endpoint.create(
35+
app.id,
36+
Svix::EndpointIn.new(url: "https://example.svix.com/", channels: %w[ch0 ch1])
37+
)
38+
39+
expect(ep.channels.to_set).to eq(%w[ch0 ch1].to_set)
40+
expect(ep.filter_types).to be_nil
41+
42+
ep_patched = test_client.endpoint.patch(app.id, ep.id, Svix::EndpointPatch.new(filter_types: %w[event.started event.ended]))
43+
44+
expect(ep_patched.channels.to_set).to eq(%w[ch0 ch1].to_set)
45+
expect(ep_patched.filter_types.to_set).to eq(%w[event.started event.ended].to_set)
46+
47+
# If the serialization is handling empty response bodies, this should not throw an exception
48+
test_client.endpoint.delete(app.id, ep.id)
49+
end
50+
end
51+
end

0 commit comments

Comments
 (0)