Skip to content

Instantly share code, notes, and snippets.

@addamh
Last active April 10, 2018 16:59
Show Gist options
  • Save addamh/2ce2cf24b6cedbbcd7203495f185bda3 to your computer and use it in GitHub Desktop.
Save addamh/2ce2cf24b6cedbbcd7203495f185bda3 to your computer and use it in GitHub Desktop.
Fayetteville.js // Serverless Live Demo Project
  • Endpoint that receives GET query parameters a & b, which are integers, and returns the product of the two integers
'use strict';
module.exports.multiply = (event, context, callback) => {
let { queryStringParameters: {a, b} } = event;
const response = {
statusCode: 200,
body: a * b
};
callback(null, response);
};
const handler = require("./handler.js");
describe('Multipler', () => {
it('returns 64 if a and b are 8', () => {
const a = 8
const b = 8
const event = {
queryStringParameters: {
a,
b
}
}
const context = {}
const cb = (error, response) => {
const data = JSON.parse(response.body)
expect(data).toBe(a * b)
}
handler.multiply(event, context, cb)
})
})
{
"name": "multiplier",
"version": "1.0.0",
"description": "",
"main": "handler.js",
"directories": {
"test": "tests"
},
"scripts": {},
"author": "",
"license": "ISC",
"dependencies": {
"serverless": "^1.26.1"
},
"devDependencies": {
"jest": "^22.4.3"
}
}
service: multiplier
provider:
name: aws
runtime: nodejs6.10
functions:
hello:
handler: handler.multiply
events:
- http:
path: /multiply
method: get
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment