Skip to content

Instantly share code, notes, and snippets.

@marekkrzynowek
Created December 4, 2019 15:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save marekkrzynowek/679e37c2fc3d44ec98f14429e53a9169 to your computer and use it in GitHub Desktop.
Save marekkrzynowek/679e37c2fc3d44ec98f14429e53a9169 to your computer and use it in GitHub Desktop.
/* eslint-env mocha */
/* eslint prefer-arrow-callback: off */
const sinon = require('sinon');
const AWS = require('aws-sdk-mock');
const { utils } = require('@ucapp/unioncore-test-utils');
const expect = require('expect');
const hello = require('../hello.js');
let SNS_SPY;
describe('Hello world tests', function() {
beforeEach( async function() {
SNS_SPY = sinon.spy((params, callback) => {
callback(null, {});
});
AWS.mock('SNS', 'publish', SNS_SPY);
});
afterEach(async () => {
AWS.restore('SNS', 'publish');
});
it.only('Hello world', async () => {
const payloadFixture = { message: 'Hello World' }
const sqsPayload = utils.generateSNSFixture(payloadFixture);
const event = utils.createAwsEvent({
template: 'aws:apiGateway',
merge: sqsPayload
});
const resp = await hello.helloWorld(event, {});
expect(resp.statusCode).toBe(200);
console.log(resp);
expect(resp.body).toBe(JSON.stringify(payloadFixture));
utils.expectSNSWithPayload(
SNS_SPY,
process.env.HELLO_TOPIC,
payloadFixture
);
utils.expectNoUnknownSNS(SNS_SPY);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment