|
12 | 12 | let(:api_instance_mock) { double("MessageApi") }
|
13 | 13 | let(:api_class_mock) { double("MessageApiClass") }
|
14 | 14 |
|
15 |
| - # Mock out the API calls |
16 |
| - before(:each) do |
17 |
| - stub_const("Svix::MessageApi", api_class_mock) |
18 |
| - expect(api_class_mock).to receive(:new).with(param_mock).and_return(api_instance_mock) |
| 15 | + describe "message_in_raw" do |
| 16 | + it "works without content-type" do |
| 17 | + payload = "{ \"x\": true }" |
| 18 | + msg_in = Svix.message_in_raw(event_type: "x", payload: payload) |
| 19 | + |
| 20 | + expect(msg_in.event_type).to eq("x") |
| 21 | + expect(msg_in.payload).to eq({}) |
| 22 | + expect(msg_in.transformations_params[:rawPayload]).to eq(payload) |
| 23 | + expect(msg_in.transformations_params[:headers]).to eq(nil) |
| 24 | + end |
| 25 | + |
| 26 | + it "works with content-type" do |
| 27 | + payload = "Hello, World!" |
| 28 | + content_type = "text/plain" |
| 29 | + msg_in = Svix.message_in_raw(event_type: "x", payload: payload, content_type: content_type) |
| 30 | + |
| 31 | + expect(msg_in.event_type).to eq("x") |
| 32 | + expect(msg_in.payload).to eq({}) |
| 33 | + expect(msg_in.transformations_params[:rawPayload]).to eq(payload) |
| 34 | + expect(msg_in.transformations_params[:headers][:'content-type']).to eq(content_type) |
| 35 | + end |
| 36 | + |
| 37 | + it "works with other transformations params" do |
| 38 | + payload = "Hello, World!" |
| 39 | + content_type = "text/plain" |
| 40 | + msg_in = Svix.message_in_raw( |
| 41 | + event_type: "x", |
| 42 | + payload: payload, |
| 43 | + content_type: content_type, |
| 44 | + transformations_params: { |
| 45 | + :foo => "bar", |
| 46 | + :headers => { |
| 47 | + :'x-custom' => "baz", |
| 48 | + }, |
| 49 | + }, |
| 50 | + ) |
| 51 | + |
| 52 | + expect(msg_in.event_type).to eq("x") |
| 53 | + expect(msg_in.payload).to eq({}) |
| 54 | + expect(msg_in.transformations_params[:foo]).to eq("bar") |
| 55 | + expect(msg_in.transformations_params[:rawPayload]).to eq(payload) |
| 56 | + expect(msg_in.transformations_params[:headers][:'content-type']).to eq(content_type) |
| 57 | + expect(msg_in.transformations_params[:headers][:'x-custom']).to eq("baz") |
| 58 | + end |
19 | 59 | end
|
20 | 60 |
|
21 | 61 | describe "#get" do
|
| 62 | + # Mock out the API calls |
| 63 | + before(:each) do |
| 64 | + stub_const("Svix::MessageApi", api_class_mock) |
| 65 | + expect(api_class_mock).to receive(:new).with(param_mock).and_return(api_instance_mock) |
| 66 | + end |
| 67 | + |
22 | 68 | it "passes it's parameters to the correct method" do
|
23 | 69 | # Assert that the correct method is called with the correct parameters
|
24 | 70 | expect(api_instance_mock).to receive(:v1_message_get).with(app_id, msg_id, options)
|
|
0 commit comments