mangopay-1.11.3: Bindings to the MangoPay API

Safe HaskellNone
LanguageHaskell98

Web.MangoPay.TestUtils

Contents

Synopsis

Initialization

withMangoPayTestUtils Source

Arguments

:: (Credentials -> AccessToken -> Manager -> IO a)

Action to run while being able to use functions from this module.

-> IO a 

Creates and initializes the MangoPay infrastructure needed to use the test helpers from this module. Tears down the server at the end.

You may want to use ensureNoEvents at the end of your action before tearing down the server.

This module uses global, shared state. You have to wrap your entire test suite with this function, and you can't use withMangoPayTests more than once.

Reads two files from the current directory:

  • client.test.conf (can be generated by mangopay-passphrase).
  • hook.test.conf, json file containing object with Url and Port fields. The first is the URL used to access this server's root, while the second is the port this server should listen to.

Test helpers

testMP :: (AccessToken -> MangoPayT (LoggingT (ResourceT IO)) b) -> IO b Source

Test MangoPay API call, logging in with the client credentials. Expects a file called client.test.conf containing the JSON of client credentials in the current directory.

testEventTypes :: [EventType] -> IO (Maybe Text) -> Assertion Source

Run the given test, then check that we've received events of the given types which reference resource id returned by the test.

testEventTypes' :: [EventType] -> IO (Maybe Text) -> IO (Maybe Text) Source

Same as testEventTypes, but also return the resource id.

Credit card registration

unsafeFullRegistration :: MPUsableMonad m => AnyUserId -> Currency -> CardInfo -> AccessToken -> MangoPayT m CardRegistration Source

Perform the full registration of a card.

This function is UNSAFE, because if you use this, YOU handle the user's credit card details so you need to be PCI compliant!

unsafeRegisterCard :: CardInfo -> CardRegistration -> IO CardRegistration Source

Register a card with the registration URL.

This function is UNSAFE, because if you use this, YOU handle the user's credit card details so you need to be PCI compliant!

XXX This is not working anymore.

Tear down

ensureNoEvents :: Int -> Assertion Source

Wait for the given number of seconds and check if any MangoPay event has arrived. Fails if so. Use this function at the end of your test run to ensure that you're aware of every MangoPay event.

Bug workarounds

withWorkaroundManager :: (MonadIO m, MonadBaseControl IO m) => (Manager -> ResourceT m a) -> m a Source

Same as withManager, but without TLS 1.2 support.

As of 2014-11-22, there's a bug on the tls package that prevents connections to be made to the MangoPay servers. For some reason, disabling TLS 1.2 works around this problem. Cf. https://github.com/vincenthz/hs-tls/issues/87.

This function isn't named withTLS11Manager because it will eventually be changed to be the same as withManager as soon as this bug is fixed.

newWorkaroundManager :: MonadIO m => m Manager Source

Create a new Manager with the same workarounds as withWorkaroundManager, but does not automatically release it so that you have full control of its life cycle.