dropz:mandrill-stub

v1.1.2Published 11 years ago

This package has not had recent updates. Please investigate it's current state before committing to using it in your project.

mandrill-stub

A stub for use in testing Meteor apps. It's also nice for reducing your dependencies in local development.

Works on top of the excellent wylio:mandrill package.

Usage:

If you are using wylio:mandrill, add this package like this:

meteor add dropz:mandrill-stub

Your app will no longer send real API calls to Mandrill in development mode and will instead log your API calls to a local mongoDB collection, from where you can assert on the existence and correctness of your calls.

The stubbing happens automatically.

This package does not affect production as it is a debugOnly package.

Currently Stubbed API Calls

  • Mandrill.messages.sendTemplate

  • Can add more if needed

Asserting on Successful Mandrill API Calls

1Meteor.call('mandrillStub/getAPICalls')

In case one or more API calls would've been made, you'll get a response like

1{
2    "_id" : "rTkLCM4L3b9n79axD",
3    "key" : "SOME KEY",
4    "template_name" : "thank-you-for-suggesting-a-company",
5    "template_content" : null,
6    "message" : {
7        "global_merge_vars" : [ 
8            {
9                "name" : "firstName",
10                "content" : "Florian"
11            }, 
12            {
13                "name" : "companyName",
14                "content" : "dropz"
15            }
16        ],
17        "to" : [ 
18            {
19                "email" : "flo@dropz.io"
20            }
21        ]
22    }
23}

...for each of them.

Resetting your local DB Log of API Calls

1Meteor.call('mandrillStub/reset');

If using cucumber, it's a good idea to do that in a reset hook after every Scenario.

What if I want to test email sending in development mode?

You can disable the stub whenever you want to do actual Mandrill calls in development, by setting the DEBUG_MANDRILL_EMAILS=1 environment variable prior to starting up meteor.

What if I want to dance a haka?

Nothing's stopping you, mate!

Thanks

Inspired by xolvio:meteor-email-stub and all of Xolvio's amazing work on providing a great testing experience in the Meteor landscape. Thanks!

Requires wylio:mandrill. Thx for that package!