Created
December 4, 2019 15:52
-
-
Save marekkrzynowek/679e37c2fc3d44ec98f14429e53a9169 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* 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