Skip to content
This repository has been archived by the owner on Jan 11, 2024. It is now read-only.

Commit

Permalink
update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Brian Whitton committed May 22, 2017
1 parent b293418 commit 799dbca
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 105 deletions.
1 change: 1 addition & 0 deletions tests/fixtures/expectations.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

130 changes: 76 additions & 54 deletions tests/fixtures/representatives.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,54 @@
module.exports = {
"normalizedInput": {
"line1": "123 Main Street",
"city": "Flushing",
"state": "NY",
"zip": "11354"
},
"divisions": {
"ocd-division/country:us": {
"name": "United States",
"officeIndices": [
0,
1
]
},
"ocd-division/country:us/state:ny": {
"name": "New York",
"officeIndices": [
2,
4,
5,
11,
12
]
},
"ocd-division/country:us/state:ny/cd:6": {
"name": "New York's 6th congressional district",
"officeIndices": [
3
]
},
"ocd-division/country:us/state:ny/county:queens": {
"name": "Queens County",
"alsoKnownAs": [
"ocd-division/country:us/state:ny/borough:queens",
"ocd-division/country:us/state:ny/place:new_york/county:queens"
],
"officeIndices": [
9,
10
]
},
"ocd-division/country:us/state:ny/place:new_york": {
"name": "New York city",
"officeIndices": [
6,
7,
8
]
}
},
"offices": [
{
"name": "President of the United States",
Expand All @@ -23,8 +73,8 @@ module.exports = {
]
},
{
"name": "United States House of Representatives NY-07",
"divisionId": "ocd-division/country:us/state:ny/cd:7",
"name": "United States House of Representatives NY-06",
"divisionId": "ocd-division/country:us/state:ny/cd:6",
"officialIndices": [
4
]
Expand All @@ -44,36 +94,36 @@ module.exports = {
]
},
{
"name": "NY State Senate District 25",
"divisionId": "ocd-division/country:us/state:ny/sldu:25",
"name": "Mayor",
"divisionId": "ocd-division/country:us/state:ny/place:new_york",
"officialIndices": [
7
]
},
{
"name": "NY State Assembly District 52",
"divisionId": "ocd-division/country:us/state:ny/sldl:52",
"name": "Comptroller",
"divisionId": "ocd-division/country:us/state:ny/place:new_york",
"officialIndices": [
8
]
},
{
"name": "Mayor",
"name": "Public Advocate",
"divisionId": "ocd-division/country:us/state:ny/place:new_york",
"officialIndices": [
9
]
},
{
"name": "Comptroller",
"divisionId": "ocd-division/country:us/state:ny/place:new_york",
"name": "District Attorney - Queens",
"divisionId": "ocd-division/country:us/state:ny/county:queens",
"officialIndices": [
10
]
},
{
"name": "Public Advocate",
"divisionId": "ocd-division/country:us/state:ny/place:new_york",
"name": "Queens Borough President",
"divisionId": "ocd-division/country:us/state:ny/county:queens",
"officialIndices": [
11
]
Expand All @@ -91,20 +141,6 @@ module.exports = {
"officialIndices": [
13
]
},
{
"name": "County District Attorney",
"divisionId": "ocd-division/country:us/state:ny/county:kings",
"officialIndices": [
14
]
},
{
"name": "Brooklyn Borough President",
"divisionId": "ocd-division/country:us/state:ny/county:kings",
"officialIndices": [
15
]
}
],
"officials": [
Expand Down Expand Up @@ -137,10 +173,10 @@ module.exports = {
]
},
{
"name": "Nydia M. Velazquez",
"name": "Grace Meng",
"party": "Democratic",
"phones": [
"(202) 225-2361"
"(202) 225-2601"
]
},
{
Expand All @@ -157,20 +193,6 @@ module.exports = {
"(518) 474-8390"
]
},
{
"name": "Velmanette Montgomery",
"party": "Democratic",
"phones": [
"(518) 455-3451"
]
},
{
"name": "Jo Anne Simon",
"party": "Democratic",
"phones": [
"(518) 455-5426"
]
},
{
"name": "Bill de Blasio",
"party": "Democratic",
Expand All @@ -193,32 +215,32 @@ module.exports = {
]
},
{
"name": "Eric T. Schneiderman",
"party": "Democratic",
"name": "Richard A. Brown",
"party": "Unknown",
"phones": [
"(800) 771-7755"
"(718) 286-6000"
]
},
{
"name": "Thomas P. DiNapoli",
"party": "Democratic",
"name": "Melinda Katz",
"party": "Unknown",
"phones": [
"(518) 474-4044"
"(718) 286-3000"
]
},
{
"name": "Kenneth P. Thompson",
"party": "Unknown",
"name": "Eric T. Schneiderman",
"party": "Democratic",
"phones": [
"(718) 250-2000"
"(800) 771-7755"
]
},
{
"name": "Eric Adams",
"party": "Unknown",
"name": "Thomas P. DiNapoli",
"party": "Democratic",
"phones": [
"(718) 802-3700"
"(518) 474-4044"
]
}
]
}
};
4 changes: 2 additions & 2 deletions tests/google-civics-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ describe('Google Civics API Client', function() {
qs: {
key: process.env.GOOGLE_API_KEY,
address: ADDRESS,
fields: 'offices(name,officialIndices,divisionId),officials(name,party,phones)'
fields: 'offices(name,officialIndices,divisionId),officials(name,party,phones),divisions,normalizedInput'
},
json: true,
timeout: 5000
})).to.be.ok;
})).to.be.ok; // jshint ignore:line

getSpy.restore();
done();
Expand Down
57 changes: 8 additions & 49 deletions tests/lookup-route-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,56 +6,15 @@ var express = require('express');
var request = require('supertest');

var googleCivics = require('../lib/clients/google-civics');
var EXPECTATIONS = require('./fixtures/expectations');
var REPS_RESPONSE = require('./fixtures/representatives');
var fromGoogle = {
offices: REPS_RESPONSE.offices.slice(0, 3),
officials: REPS_RESPONSE.officials.slice(0, 4)

var expecting = {
normalizedInput: REPS_RESPONSE.normalizedInput,
reps: EXPECTATIONS.reps,
districts: EXPECTATIONS.districts
};

var expecting = [{
"id": 0,
"name": "Donald J. Trump",
"office": "President of the United States",
"party": "Republican",
"phones": [
"(202) 456-1111"
],
"phone": "(202) 456-1111",
"divisionId": "ocd-division/country:us"
},
{
"id": 1,
"name": "Mike Pence",
"party": "Republican",
"office": "Vice-President of the United States",
"phones": [
"(202) 456-1111"
],
"phone": "(202) 456-1111",
"divisionId": "ocd-division/country:us"
},
{
"id": 2,
"name": "Charles E. Schumer",
"office": "United States Senate",
"party": "Democratic",
"phones": [
"(202) 224-6542"
],
"phone": "(202) 224-6542",
"divisionId": "ocd-division/country:us/state:ny"
},
{
"id": 3,
"name": "Kirsten E. Gillibrand",
"office": "United States Senate",
"party": "Democratic",
"phones": [
"(202) 224-4451"
],
"phone": "(202) 224-4451",
"divisionId": "ocd-division/country:us/state:ny"
}];
var googleStub;

var app = express();
Expand All @@ -65,7 +24,7 @@ describe('lookup route', function () {
const ADDRESS = "123 Main St, Anytown, OH";

beforeEach(function () {
googleStub = sinon.stub(googleCivics, 'getReps', () => Promise.resolve(fromGoogle));
googleStub = sinon.stub(googleCivics, 'getReps', () => Promise.resolve(REPS_RESPONSE));
});
afterEach(function() {
googleCivics.getReps.restore();
Expand All @@ -76,7 +35,7 @@ describe('lookup route', function () {
request(app)
.get(`/lookup/?address=${ADDRESS}`)
.expect(function () {
expect(googleStub.calledWith(ADDRESS)).to.be.ok;
expect(googleStub.calledWith(ADDRESS)).to.be.ok; // jshint ignore:line
})
.expect(200, expecting, done);
});
Expand Down

0 comments on commit 799dbca

Please sign in to comment.