Lollipop

Fake email provider designed to automate transactional email unit tests.

Few developers have time to write unit tests, so many don’t.

Imagine a signup route that sends an email confirmation link that includes an access token and another route that checks if the right access token is provided.

Wouldn’t it be amazing if unit tests could programmatically use the access token found in that email and provide it to other unit tests synchronously?

We couldn't find anything of the sort so we developed Lollipop!

Features

Super simple to use

Implements live preview

Implements both instance methods and a restful API to query the message store (that’s where sent emails are temporarily stored)

Uses trusted dependencies (hapi, cheerio, query-string, etc...)

Written in TypeScript (builds include type definitions)

Great test coverage ( npm test or npm run test-lp to enable live preview)

or to enable live preview) Actively maintained and used in production by the Lickstats team

Very light codebase to audit

Getting started

Lollipop works the same way as any other email provider. It is used to "send" emails.

This means Lollipop is implemented in a codebase alongside email providers such as Sengrid.

At Lickstats, we use an environment variable to switch between Lollipop (developement) and Sendgrid (production).

Installation

npm install lollipop --save-dev

Configuration

By default, the Lollipop API port is set randomly using get-port.

Environment variables

Variable Type Required Default Purpose LOLLIPOP_PORT number no random Sets API port DEBUG true or false no false Enables debug mode

Instance properties

Property Values Required Default Purpose livePreview true or false no false Enables live preview

Usage

When should you use instance methods vs the restful API?

Instance methods are great when unit tests inject queries directly to the API (for example, when using inject with hapi).

The restful API is the way to go when your API doesn’t run on the same thread as your unit tests (for example, when using supertest).

Create instance

" use strict " import lollipop from " lollipop " lollipopInstance . init ( )

Send email using instance method (this doesn’t actually send the email, but rather adds it to the message store)

Get latest email from message store using instance method and read access_token query string

. access_token

Get latest email from message store using API and read access_token query string

import { getLink } from " lollipop " import request from " request-promise-native " . query . access_token

Get specific email from message store using instance method and read access_token query string

. access_token

Get specific email from message store using API and read access_token query string

import { getLink } from " lollipop " import request from " request-promise-native " . query . access_token

Contributors

Sun Knudsen

Licence

MIT