Skip to content

Commit

Permalink
snarky dc 404 message
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris Edwards authored and Chris Edwards committed Jan 14, 2017
1 parent df3bc37 commit 956dde4
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 3 deletions.
19 changes: 17 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@

import {
getDistrictByLatLng,
getDistrictByAddress
getDistrictByAddress,
DISTRICT_NOT_FOUND
} from 'congressional-district-finder';
import { response } from './util/lambda';
import { getMembers, setProPublicaKey } from './propublica';

const NO_VOTE_404 = [
// eslint-disable babel/new-cap
DISTRICT_NOT_FOUfND('DC-0'),
DISTRICT_NOT_FOUND('PR-0')
// eslint-enable babel/new-cap
];

function handler(event, context, callback) {

Expand Down Expand Up @@ -38,7 +45,15 @@ function handler(event, context, callback) {
callback(null, response({ result }))
})
.catch(({ statusCode, message }) => {
callback(null, response({ message }, statusCode))
if (statusCode === 404 && NO_VOTE_404.includes(message)) {
callback(null, response({ message:
'Taxation without representation.'
}, 404))

} else {
callback(null, response({ message }, statusCode));

}
});
}
}
Expand Down
27 changes: 26 additions & 1 deletion test/test_index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ config.includeStack = true;
describe('The Index Lambda Handler', () => {

beforeEach((done) => {
dotenv.config({ silent: true });
dotenv.config({ silent: false });
done();
});

Expand Down Expand Up @@ -91,6 +91,31 @@ describe('The Index Lambda Handler', () => {
});
});

context('with a valid lat, lng in DC', () => {

const event = {
queryStringParameters: {
latLng: '38.909418, -77.043235'
}
};

it('sends a statusCode 404 and a snarky message', (done) => {
handler(event, {}, (err, { statusCode, body }) => {
try {

const { message } = JSON.parse(body);
expect(statusCode)
.to.eq(404);
expect(message)
.to.eq('Taxation without representation.');
done();
} catch(err) {
done(err);
}
});
});
});

context('with an invalid lat, lng', () => {

const event = {
Expand Down

0 comments on commit 956dde4

Please sign in to comment.