From 8feda79ad79c9a284fd58106c733098ba4e6a512 Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Wed, 4 Dec 2024 20:03:58 +0100 Subject: [PATCH] ruby: Add tests for message_in_raw --- ruby/spec/message_api_spec.rb | 54 ++++++++++++++++++++++++++++++++--- 1 file changed, 50 insertions(+), 4 deletions(-) diff --git a/ruby/spec/message_api_spec.rb b/ruby/spec/message_api_spec.rb index 65718ba63..8b99264c3 100644 --- a/ruby/spec/message_api_spec.rb +++ b/ruby/spec/message_api_spec.rb @@ -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)