serverless-ses-sns
Version:
Serverless plugin to add a SNS destination to a SES ConfigurationSet
81 lines (66 loc) • 2.59 kB
JavaScript
const { makeCreateSNSDestinationHook, makeRemoveSNSDestinationHook } = require('./plugin');
const logger = { log: () => { } };
const provider = { stage: 'test' };
const service = 'test-service';
describe('plugin', () => {
describe('createSNSDestinationHook', () => {
test('if a SNS topic is provided, none are created', async () => {
const createTopic = jest.fn();
const createOrUpdateSNSDestination = jest.fn();
const hook = makeCreateSNSDestinationHook(createTopic, createOrUpdateSNSDestination, logger);
await hook({
service,
provider,
custom: {
snsDestination: {
topicArn: 'arn:....'
}
}
});
expect(createTopic.mock.calls.length).toBe(0);
});
test('if a SNS topic is not provided, one is created', async () => {
const createTopic = jest.fn(() => ({}));
const createOrUpdateSNSDestination = jest.fn();
const hook = makeCreateSNSDestinationHook(createTopic, createOrUpdateSNSDestination, logger);
await hook({
service,
provider,
custom: {
snsDestination: {}
}
});
expect(createTopic.mock.calls.length).toBe(1);
});
});
describe('removeSNSDestinationHook', () => {
test('if a SNS topic is provided, none are removed', async () => {
const removeTopic = jest.fn();
const removeSNSDestination = jest.fn();
const hook = makeRemoveSNSDestinationHook(removeTopic, removeSNSDestination, logger);
await hook({
service,
provider,
custom: {
snsDestination: {
topicArn: 'arn:....'
}
}
});
expect(removeTopic.mock.calls.length).toBe(0);
});
test('if a SNS topic is not provided, one is removed', async () => {
const removeTopic = jest.fn();
const removeSNSDestination = jest.fn();
const hook = makeRemoveSNSDestinationHook(removeTopic, removeSNSDestination, logger);
await hook({
service,
provider,
custom: {
snsDestination: {}
}
});
expect(removeTopic.mock.calls.length).toBe(1);
});
});
});