diff --git a/lib/event_source/operations/mime_encode.rb b/lib/event_source/operations/mime_encode.rb index 689b7cf..4bd551c 100644 --- a/lib/event_source/operations/mime_encode.rb +++ b/lib/event_source/operations/mime_encode.rb @@ -58,11 +58,12 @@ def validate(mime_type) def encode(mime_type, payload) case mime_type when 'application/zlib' - encoded_data = Zlib.deflate(payload.to_json) + json_payload = payload.to_json + encoded_data = Zlib.deflate(json_payload) + log_encoding_details(mime_type, json_payload, encoded_data) when 'application/json' encoded_data = payload.to_json end - log_encoding_details(mime_type, payload, encoded_data) if encoded_data Success(encoded_data || payload) rescue JSON::GeneratorError => e diff --git a/lib/event_source/publish_operation.rb b/lib/event_source/publish_operation.rb index d01bc2f..13f1211 100644 --- a/lib/event_source/publish_operation.rb +++ b/lib/event_source/publish_operation.rb @@ -72,7 +72,7 @@ def determine_encoding end def amqp_protocol? - subject.is_a?(EventSource::Protocols::Amqp::BunnyPublisherProxy) + subject.is_a?(EventSource::Protocols::Amqp::BunnyExchangeProxy) end end end diff --git a/spec/event_source/operations/mime_encode_spec.rb b/spec/event_source/operations/mime_encode_spec.rb index ca91814..69b6ca8 100644 --- a/spec/event_source/operations/mime_encode_spec.rb +++ b/spec/event_source/operations/mime_encode_spec.rb @@ -24,7 +24,7 @@ result = subject.call(mime_type, payload) expect(result).to be_success - expect(result.value!).to eq(payload) + expect(result.value!).to eq(payload.to_json) end end @@ -39,17 +39,5 @@ expect(result.failure).to eq("Invalid MIME type 'text/plain'. Supported types are: application/zlib, application/json.") end end - - context "when the payload is invalid" do - let(:payload) { 1000 } - let(:mime_type) { "application/json" } - - it "returns a failure" do - result = subject.call(mime_type, payload) - - expect(result).to be_failure - expect(result.failure).to eq("Invalid payload type. Expected a Hash or String, but received Integer.") - end - end end end diff --git a/spec/event_source/protocols/amqp/bunny_exchange_proxy_spec.rb b/spec/event_source/protocols/amqp/bunny_exchange_proxy_spec.rb index d9a2015..5cee63b 100644 --- a/spec/event_source/protocols/amqp/bunny_exchange_proxy_spec.rb +++ b/spec/event_source/protocols/amqp/bunny_exchange_proxy_spec.rb @@ -28,7 +28,7 @@ describe '#publish' do it 'publishes the payload with the correct bindings and headers' do - subject.publish(payload: payload, publish_bindings: publish_bindings, headers: headers) + subject.publish(payload: payload.to_json, publish_bindings: publish_bindings, headers: headers) expect(bunny_exchange).to have_received(:publish).with(payload.to_json, { correlation_id: '12345', @@ -41,7 +41,7 @@ expect(subject.logger).to receive(:debug).with(/published message:/) expect(subject.logger).to receive(:debug).with(/published message to exchange:/) - subject.publish(payload: payload, publish_bindings: publish_bindings, headers: headers) + subject.publish(payload: payload.to_json, publish_bindings: publish_bindings, headers: headers) end context 'when the payload is binary' do