Ciaran Downey 7ba4caad0d Improves usage and documentation of SNS event sources.
When using cloudformation intrinsic functions, it is easy to assume that sns:topicName is a property that should resolve to the actual value in AWS. In reality it is only used to name the underlying cloudformation resources generated by serverless, and thus needs to be a string.
This improves the error message and code path returned when sns:topicName is not a string, as well as does some validation around usage of Fn::ImportValue. Also adds some tests and documentation demonstrating that intrinsic functions work with SNS event sources.
2018-11-04 09:34:00 -05:00

39 lines
1.1 KiB
JavaScript

'use strict';
const path = require('path');
const expect = require('chai').expect;
const Utils = require('../../../../utils/index');
const uuid = require('uuid');
describe('AWS - SNS: Existing topic with single function', () => {
const snsTopic = uuid.v4();
beforeAll(() => Utils.createSnsTopic(snsTopic)
.then((result) => {
const splitTopicArn = result.topicArn.split(':');
process.env.EXISTING_TOPIC_REGION = splitTopicArn[3];
process.env.EXISTING_TOPIC_ACCOUNT = splitTopicArn[4];
process.env.EXISTING_TOPIC_NAME = splitTopicArn[5];
})
.then(() => {
Utils.createTestService('aws-nodejs', path.join(__dirname, 'service'));
Utils.deployService();
})
);
it('should trigger function when new message is published', () => Utils
.publishSnsMessage(snsTopic, 'hello world')
.delay(60000)
.then(() => {
const logs = Utils.getFunctionLogs('hello');
expect(/aws:sns/g.test(logs)).to.equal(true);
expect(/hello world/g.test(logs)).to.equal(true);
})
);
afterAll(() => {
Utils.removeService();
Utils.removeSnsTopic(snsTopic);
});
});