@vagalumedigital/gatsby-plugin-mailchimp-api
Version:
A plugin written to use Mailchimp API v3 to add/update users subscribed on a list
47 lines (38 loc) • 1.58 kB
JavaScript
const { onCreateWebpackConfig } = require('../gatsby-node');
describe('gatsby-node > onCreateWebpackConfig', () => {
const plugins = {};
const actions = {};
beforeEach(() => {
plugins.define = jest.fn();
actions.setWebpackConfig = jest.fn();
});
it('Throws an error when key is not a string', () => {
const key = 123;
expect(() => onCreateWebpackConfig({ plugins, actions }, { key })).toThrow(Error);
expect(actions.setWebpackConfig).not.toHaveBeenCalled();
expect(plugins.define).not.toHaveBeenCalled();
});
it('Throws an error when id is not a string', () => {
const id = 123;
expect(() => onCreateWebpackConfig({ plugins, actions }, { id })).toThrow(Error);
expect(actions.setWebpackConfig).not.toHaveBeenCalled();
expect(plugins.define).not.toHaveBeenCalled();
});
describe('Options -> calls set setWebpackConfig and define variables correctly', () => {
it('valid values', () => {
const id = `asabvscas`;
const key = `asabvscas`;
expect(actions.setWebpackConfig).not.toHaveBeenCalled();
expect(plugins.define).not.toHaveBeenCalled();
onCreateWebpackConfig({ plugins, actions }, { id, key });
expect(actions.setWebpackConfig).toHaveBeenCalledTimes(1);
expect(plugins.define).toHaveBeenCalledTimes(1);
expect(plugins.define).toHaveBeenCalledWith(
expect.objectContaining({
__GATSBY_PLUGIN_MAILCHIMP_API_LIST_ID__: expect.any(String),
__GATSBY_PLUGIN_MAILCHIMP_API_KEY__: expect.any(String),
}),
);
});
});
});