@@ -235,4 +235,41 @@ defmodule SentryTest do
235235 assert Sentry . get_dsn ( ) == random_dsn
236236 end
237237 end
238+
239+ describe "send_transaction/2" do
240+ setup do
241+ transaction =
242+ Sentry.Transaction . new ( % {
243+ transaction: "test-transaction" ,
244+ start_timestamp: System . system_time ( :second ) ,
245+ timestamp: System . system_time ( :second )
246+ } )
247+
248+ { :ok , transaction: transaction }
249+ end
250+
251+ test "sends transaction to Sentry when configured properly" , % {
252+ bypass: bypass ,
253+ transaction: transaction
254+ } do
255+ Bypass . expect_once ( bypass , "POST" , "/api/1/envelope/" , fn conn ->
256+ { :ok , body , conn } = Plug.Conn . read_body ( conn )
257+ assert [ { headers , transaction_body } ] = decode_envelope! ( body )
258+
259+ assert headers [ "type" ] == "transaction"
260+ assert Map . has_key? ( headers , "length" )
261+ assert transaction_body [ "transaction" ] == "test-transaction"
262+
263+ Plug.Conn . send_resp ( conn , 200 , ~s< {"id": "340"}> )
264+ end )
265+
266+ assert { :ok , "340" } = Sentry . send_transaction ( transaction )
267+ end
268+
269+ test "ignores transaction when dsn is not configured" , % { transaction: transaction } do
270+ put_test_config ( dsn: nil , test_mode: false )
271+
272+ assert :ignored = Sentry . send_transaction ( transaction )
273+ end
274+ end
238275end
0 commit comments