|
| 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