0

I'm writing an integration test for a component that does a transaction and after that, a webhook is called.

For that, I want to mock a webhook endpoint using suave so I can know if the webhook was hit after the transaction was done.

I'm doing the following test:

[<Tests>]
let webhookTests =
    testList
        "Webhook Domain Tests"
        [    
            ftest "Enabled webhooks must be called when a payment is processed" {

                let webhook = enabledWebhook()
                let webhookSetupRes =
                    match ApiHandlers.create webhook secCntxt logger with
                    | Success _ -> true
                    | _ -> false

                let req = transferBody ()
                let _ = ApiHandlers.send req secCntxt logger

                let mutable serverGotHit = false
                let sideEffectLambda =
                    serverGotHit <- true
                    OK ""

                let route = path "/" >=> sideEffectLambda
                let mockWebhookServer = choose [route]
                let customSuaveConfig =
                  { defaultConfig with
                      bindings =
                        [ HttpBinding.create HTTP IPAddress.Loopback 80us
                          HttpBinding.createSimple HTTP (IPAddress.Loopback.ToString()) 9002 ]
                      listenTimeout = TimeSpan.FromMilliseconds 3000. }

                startWebServer customSuaveConfig mockWebhookServer

                Expect.isTrue webhookSetupRes "The webhook was successfully setup"
                Expect.isTrue serverGotHit "The mock server was hit"
            }
        ]

I'm running into the following error:

System.Exception: Failed callback to http://127.0.0.1:9002/: No connection could be made because the target machine actively refused it.

Kanagawa Marcos
  • 100
  • 1
  • 9

0 Answers0