Skip to content

solydhq/strapi-provider-email-test

Repository files navigation

strapi-provider-email-test Tests Actions Status

A zero-dependency in memory email mock provider for strapi v4

💾 Installation

npm install --save-dev trapi-provider-email-test
# or
yarn add -D strapi-provider-email-test

🧑‍💻 Usage

Add the plugin configuration in the plugin.js as you would with any other plugin.

// ...
email: {
  config: {
    provider: 'strapi-provider-email-test',
    providerOptions: {},
    settings: {
      defaultFrom: '[email protected]',
      defaultReplyTo: '[email protected]',
    },
  },
},
//...

In your tests you can then get the used instance of the in-memory storage to access the sent emails:

declare let strapi: IStrapi;

const { inboxes } = strapi.plugin('email').provider;

it('sends confirmation email after register', async () => {
  const response = await graphqlRequest.Register({
    ...testUser,
  });

  const lastEmail = inbox.getLastEmail(testUser.email);
  expect(lastEmail).toBe(expectedValue);
});

🧐 API

The API of in-memory inbox (inboxes) is kept simple and allows for the usual operations |

class InboxStorage {
  private readonly storage;
  constructor();
  getEmails(emailAddress: string): Record<string, unknown>[];
  getLastEmail(emailAddress: string, pop?: boolean): Record<string, unknown> | undefined;
  sendEmail(emailAddress: string, message: Record<string, unknown>): void;
  clearInbox(emailAddress: string): void;
  clear(): void;
}

🛠️ Contributing

Interested in contributing? Great!

To fix a bug or add a feature, follow these steps:

  • Create a Fork of the repo
  • Create a new branch (git checkout -b your-branch)
  • Add your changes and new tests if necessary
  • Make sure all tests pass
  • Commit your changes (git commit -am 'feat: fantastic feature')
  • Push the branch (git push origin your-branch)
  • Create a Pull Request

Development

The required packages to start development can be installed with

npm install
# or
yarn install

The tests can be run with

npm run test
# or
yarn test

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Packages

No packages published