Skip to content

Commit

Permalink
ruby: Add tests for message_in_raw
Browse files Browse the repository at this point in the history
  • Loading branch information
svix-jplatte committed Dec 4, 2024
1 parent a0b6f0b commit 8feda79
Showing 1 changed file with 50 additions and 4 deletions.
54 changes: 50 additions & 4 deletions ruby/spec/message_api_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,59 @@
let(:api_instance_mock) { double("MessageApi") }
let(:api_class_mock) { double("MessageApiClass") }

# Mock out the API calls
before(:each) do
stub_const("Svix::MessageApi", api_class_mock)
expect(api_class_mock).to receive(:new).with(param_mock).and_return(api_instance_mock)
describe "message_in_raw" do
it "works without content-type" do
payload = "{ \"x\": true }"
msg_in = Svix.message_in_raw(event_type: "x", payload: payload)

expect(msg_in.event_type).to eq("x")
expect(msg_in.payload).to eq({})
expect(msg_in.transformations_params[:rawPayload]).to eq(payload)
expect(msg_in.transformations_params[:headers]).to eq(nil)
end

it "works with content-type" do
payload = "Hello, World!"
content_type = "text/plain"
msg_in = Svix.message_in_raw(event_type: "x", payload: payload, content_type: content_type)

expect(msg_in.event_type).to eq("x")
expect(msg_in.payload).to eq({})
expect(msg_in.transformations_params[:rawPayload]).to eq(payload)
expect(msg_in.transformations_params[:headers][:'content-type']).to eq(content_type)
end

it "works with other transformations params" do
payload = "Hello, World!"
content_type = "text/plain"
msg_in = Svix.message_in_raw(
event_type: "x",
payload: payload,
content_type: content_type,
transformations_params: {
:foo => "bar",
:headers => {
:'x-custom' => "baz",
},
},
)

expect(msg_in.event_type).to eq("x")
expect(msg_in.payload).to eq({})
expect(msg_in.transformations_params[:foo]).to eq("bar")
expect(msg_in.transformations_params[:rawPayload]).to eq(payload)
expect(msg_in.transformations_params[:headers][:'content-type']).to eq(content_type)
expect(msg_in.transformations_params[:headers][:'x-custom']).to eq("baz")
end
end

describe "#get" do
# Mock out the API calls
before(:each) do
stub_const("Svix::MessageApi", api_class_mock)
expect(api_class_mock).to receive(:new).with(param_mock).and_return(api_instance_mock)
end

it "passes it's parameters to the correct method" do
# Assert that the correct method is called with the correct parameters
expect(api_instance_mock).to receive(:v1_message_get).with(app_id, msg_id, options)
Expand Down

0 comments on commit 8feda79

Please sign in to comment.