-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- transpiling es6 - eslint based on airbnb - inital stub of lambda funtion to find district by lat,lng - uses congressional-district-finder - inital stub of spec for lambda function - mocha and instanbul/nyc test coverage - bash script for compiling zip for upload to aws - circle.yml file for CI - README info
- Loading branch information
Chris Edwards
authored and
Chris Edwards
committed
Dec 31, 2016
0 parents
commit 63b2748
Showing
11 changed files
with
265 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"presets": ["es2015"], | ||
"plugins": ["array-includes"] | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
{ | ||
"rules": { | ||
// General JavaScript // | ||
"no-undef": [2], | ||
"no-trailing-spaces": [1], | ||
"space-before-blocks": [1, "always"], | ||
"no-unused-expressions": [0], | ||
"no-underscore-dangle": [0], | ||
"quote-props": [1, "as-needed"], | ||
"no-multi-spaces": [0], | ||
"no-unused-vars": [1], | ||
"no-loop-func": [0], | ||
"key-spacing": [0], | ||
"max-len": [1, 79], | ||
"strict": [0], | ||
"eol-last": [1], | ||
"no-console": [1], | ||
"indent": [1, 4, { "SwitchCase": 1 }], | ||
"quotes": [1, "single", "avoid-escape"], | ||
"curly": [0], | ||
"comma-dangle": [0], | ||
"semi": [0], | ||
"padded-blocks": [0], | ||
"spaced-comment": [0], | ||
|
||
// ES6 // | ||
"generator-star-spacing": 1, | ||
"new-cap": 0, | ||
"object-curly-spacing": 0, | ||
"object-shorthand": 1, | ||
|
||
// Babel // | ||
"babel/new-cap": 1, | ||
"babel/object-curly-spacing": [1, "always"], | ||
}, | ||
"parserOptions": { | ||
"ecmaFeatures": { | ||
"experimentalObjectRestSpread": true | ||
} | ||
}, | ||
"plugins": [ | ||
"babel" | ||
], | ||
"settings": { | ||
"ecmascript": 6 | ||
}, | ||
"env": { | ||
"browser": true, | ||
"node": true | ||
}, | ||
"extends" : "airbnb/base" | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
.DS_Store | ||
node_modules | ||
public | ||
*.log | ||
# Thumbnail cache files | ||
._* | ||
Thumbs.db | ||
|
||
.idea | ||
.vscode/ | ||
|
||
dist | ||
.coverage | ||
.nyc_output | ||
|
||
files | ||
files.zip |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"reporter": [ | ||
"html", | ||
"text-summary", | ||
"lcovonly" | ||
], | ||
"report-dir": ".coverage" | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
Congressman by Location for AWS Lambda | ||
======================================== | ||
Simple lambda function for a microservice that finds your congressman by Lat, Lng coordinates or address. | ||
|
||
[![CircleCI](https://circleci.com/gh/chrisdevwords/congressman-by-location-lambda/tree/master.svg?style=shield)](https://circleci.com/gh/chrisdevwords/congressman-by-location-lambda/tree/master) | ||
[![Coverage Status](https://coveralls.io/repos/github/chrisdevwords/congressman-by-location-lambda/badge.svg?branch=master)](https://coveralls.io/github/chrisdevwords/congressman-by-location-lambda?branch=master) | ||
[![Dependency Status](https://david-dm.org/chrisdevwords/congressman-by-location-lambda.svg)](https://david-dm.org/chrisdevwords/congressman-by-location-lambda) | ||
[![Dev Dependency Status](https://david-dm.org/chrisdevwords/congressman-by-location-lambda/dev-status.svg)](https://david-dm.org/chrisdevwords/congressman-by-location-lambda?type=dev) | ||
[![Known Vulnerabilities](https://snyk.io/test/github/chrisdevwords/congressman-by-location-lambda/badge.svg)](https://snyk.io/test/github/chrisdevwords/congressman-by-location-lambda) | ||
|
||
Uses [congressional-district-finder](https://github.com/chrisdevwords/congressional-district-finder) to find the district by latitude and longitude. | ||
|
||
Requirements | ||
------------ | ||
* Requires Node v4.3.2 | ||
* Package engine is set to strict to match [AWS Lambda Environment](https://aws.amazon.com/blogs/compute/node-js-4-3-2-runtime-now-available-on-lambda/) | ||
* I recommend using [NVM](https://github.com/creationix/nvm) | ||
|
||
## Running Tests | ||
This project includes [Mocha](https://mochajs.org/) and [Chai](http://chaijs.com/) w/ [Chai-as-promised](https://www.npmjs.com/package/chai-as-promised) for testing service data parsing. If you add to this, write more tests. And run them: | ||
```` | ||
$ npm test | ||
```` | ||
|
||
### Contributing | ||
All code is transpiled from ES6 with Babel. The lint config is based on [AirBnB's eslint](https://www.npmjs.com/package/eslint-config-airbnb). | ||
To lint the code run: | ||
``` | ||
$ npm run lint | ||
``` | ||
|
||
###Compiling For Upload | ||
Make sure the bin directory has executable permissions: | ||
```` | ||
$ chmod +x ./bin/build.sh | ||
```` | ||
If this throws an error, trying using sudo: | ||
``` | ||
$ sudo chmod +x .bin/build.sh | ||
``` | ||
|
||
Transpile the ES6 and zip up the relevant files for upload by running: | ||
```` | ||
$ npm run build | ||
```` | ||
This should output files.zip to the project root for upload to the AWS Lambda Console. |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#!/bin/bash | ||
rm -rf files.zip | ||
mkdir files | ||
cp ./package.json ./files/ | ||
cp -r ./dist ./files | ||
cd ./files && npm i --production | ||
cd ../ | ||
zip -r files.zip files | ||
rm -rf files |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
test: | ||
post: | ||
- mkdir -p $CIRCLE_ARTIFACTS/nyc/json_output | ||
- mv .nyc_output/*.json $CIRCLE_ARTIFACTS/nyc/json_output | ||
- mv .coverage $CIRCLE_ARTIFACTS/nyc/coverage | ||
- cat $CIRCLE_ARTIFACTS/nyc/coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js | ||
deployment: | ||
staging: | ||
branch: master | ||
commands: | ||
- npm run build | ||
- aws lambda update-function-code --function-name $FUNCTION_NAME --region us-east-1 --zip-file fileb://files.zip |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
{ | ||
"name": "congressman-by-location-lambda", | ||
"version": "0.0.1", | ||
"description": "An Amazon Lambda Service for listing members of congress by location.", | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/chrisdevwords/congressman-by-location-lambda.git" | ||
}, | ||
"main": "./dist/index", | ||
"scripts": { | ||
"test": "nyc mocha ./test", | ||
"lint": "eslint src/", | ||
"compile": "rm -rf dist && babel -d dist/ src/", | ||
"zip": "./bin/build-zip.sh", | ||
"build": "npm run compile && npm run zip" | ||
}, | ||
"keywords": [ | ||
"lambda", | ||
"democracy", | ||
"data", | ||
"congress", | ||
"senate" | ||
], | ||
"engines": { | ||
"node": "4.3.2" | ||
}, | ||
"engine-strict": true, | ||
"author": "chrisedwards82@gmail.com", | ||
"license": "ISC", | ||
"devDependencies": { | ||
"babel-cli": "^6.18.0", | ||
"babel-core": "^6.21.0", | ||
"babel-plugin-array-includes": "^2.0.3", | ||
"babel-polyfill": "^6.20.0", | ||
"babel-preset-es2015": "^6.18.0", | ||
"chai": "^3.5.0", | ||
"coveralls": "^2.11.15", | ||
"eslint": "^3.12.2", | ||
"eslint-config-airbnb": "^13.0.0", | ||
"eslint-plugin-babel": "^4.0.0", | ||
"eslint-plugin-import": "^2.2.0", | ||
"eslint-plugin-jsx-a11y": "^2.2.3", | ||
"eslint-plugin-react": "^6.8.0", | ||
"mocha": "^3.2.0", | ||
"mocha-lcov-reporter": "^1.2.0", | ||
"nyc": "^10.0.0", | ||
"sinon": "^1.17.7" | ||
}, | ||
"dependencies": { | ||
"congressional-district-finder": "0.0.1", | ||
"request": "^2.79.0", | ||
"request-promise-native": "^1.0.3" | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
|
||
import { getDistrictByLatLng } from 'congressional-district-finder'; | ||
|
||
export function handler(event, context, callback) { | ||
|
||
const { queryStringParameters } = event; | ||
const { latLng } = queryStringParameters; | ||
const [lat, lng] = latLng.split(','); | ||
|
||
getDistrictByLatLng(lat, lng) | ||
.then(({ district }) => { | ||
callback(null, { | ||
statusCode: 200, | ||
body: JSON.stringify(district), | ||
headers: { | ||
'Content-Type': 'application/json', | ||
}, | ||
}); | ||
}) | ||
.catch(({ statusCode = 500, message }) => { | ||
callback(null, { | ||
statusCode, | ||
body: JSON.stringify({ message }) | ||
}) | ||
}); | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
--recursive --compilers js:babel-core/register --timeout=4000 |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
|
||
import mocha from 'mocha'; | ||
import chai from 'chai'; | ||
import request from 'request-promise-native'; | ||
import sinon from 'sinon'; | ||
|
||
import { handler } from '../src'; | ||
|
||
const { beforeEach, afterEach, describe, it } = mocha; | ||
const { expect, config } = chai; | ||
|
||
config.includeStack = true; | ||
|
||
describe('The Index Lambda Handler', () => { | ||
context('with a valid lat, lng in the US', () => { | ||
it.skip('finds a congressional district', (done) => { | ||
done(Error('test not complete')); | ||
}); | ||
|
||
it.skip('sends 200', (done) => { | ||
done(Error('test not complete')); | ||
}); | ||
}); | ||
|
||
context('with a valid lat, lng outside the US', () => { | ||
it.skip('sends a 404', (done) => { | ||
done(Error('test not complete')); | ||
}); | ||
}); | ||
|
||
context('with an invalid lat, lng', () => { | ||
it.skip('sends a 400', (done) => { | ||
done(Error('test not complete')); | ||
}); | ||
}); | ||
}) |