This repository has been archived by the owner on Aug 8, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 15
WIP: hit backend api #85
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
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
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
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
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 |
---|---|---|
|
@@ -13,31 +13,76 @@ describe('disclosureApi', function() { | |
disclosureApi = _disclosureApi_; | ||
})); | ||
|
||
it('exists', function() { | ||
expect(disclosureApi).to.be.ok; | ||
}); | ||
|
||
it('has contributions', function() { | ||
expect(disclosureApi).to.have.property('contributions'); | ||
}); | ||
|
||
it('has elections', function() { | ||
expect(disclosureApi).to.have.property('elections'); | ||
// locality.search | ||
it('get a locality', function() { | ||
// Search for any locality | ||
disclosureApi.locality.search({q: ''}) | ||
.then(function(localities) { | ||
localities.each(function(locality) { | ||
expect(locality).to.have.property('name'); | ||
expect(locality).to.have.property('type'); | ||
expect(locality).to.have.property('id'); | ||
}); | ||
}); | ||
}); | ||
|
||
it('has locations', function() { | ||
expect(disclosureApi).to.have.property('locations'); | ||
// locality.current_ballot | ||
it('get a ballot', function() { | ||
// Search for any locality | ||
disclosureApi.locality.search({q: ''}) | ||
.then(function(localities) { | ||
// Get the current ballot for the first locality | ||
var locality = localities[0]; | ||
disclosureApi.locality.current_ballot({locality_id: locality.id}) | ||
.then(function(ballot) { | ||
expect(ballot).to.have.property('locality_id'); | ||
expect(ballot).to.have.property('ballot_id'); | ||
expect(ballot).to.have.property('ballot_items'); | ||
}); | ||
}); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would just use a known-good locality id. Otherwise it's testing too much IMHO. |
||
}); | ||
|
||
it('has search', function() { | ||
expect(disclosureApi).to.have.property('search'); | ||
// office_election.get | ||
it('get an office election', function() { | ||
// Search for any locality | ||
disclosureApi.locality.search({q: ''}) | ||
.then(function(localities) { | ||
// Get the current ballot for the first locality | ||
var locality = localities[0]; | ||
disclosureApi.locality.current_ballot({locality_id: locality.id}) | ||
.then(function(ballot) { | ||
// Get the office election details from the ballot | ||
disclosureApi.office_election.get({ballot_id: ballot.ballot_id}) | ||
.then(function(officeElection) { | ||
expect(officeElection).to.have.property('candidates'); | ||
}); | ||
}); | ||
}); | ||
}); | ||
|
||
it('lists some contributions', function() { | ||
// This hits a live API, so changes outside of this project could fail this test :( | ||
return disclosureApi.contributions.list() | ||
.then(function(contributions) { | ||
expect(contributions[0]).to.have.property('amount'); | ||
// candidate.get | ||
it('get a candidate', function() { | ||
// Search for any locality | ||
disclosureApi.locality.search({q: ''}) | ||
.then(function(localities) { | ||
// Get the current ballot for the first locality | ||
var locality = localities[0]; | ||
disclosureApi.locality.current_ballot({locality_id: locality.id}) | ||
.then(function(ballot) { | ||
// Get the office election details from the ballot | ||
disclosureApi.office_election.get({ballot_id: ballot.ballot_id}) | ||
.then(function(officeElection) { | ||
// Get details from the first candidate. | ||
var candidate = officeElection.candidates[0]; | ||
disclosureApi.candidate.get({candidate_id: candidate.id}) | ||
.then(function(candidate) { | ||
expect(candidate).to.have.property('last_name'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @adborden The API is more granular, so it is necessary to chain API calls to get needed info. I was able to validate the first two tests, but after a while, things didn't seem to be getting through to the backend, and tests seemed to pass regardless of what was inside. Please take a look. |
||
}); | ||
}); | ||
}); | ||
}); | ||
}); | ||
|
||
|
||
}); |
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@adborden This is more complex than before; I like the way this API is defined, but not sure if this is the right way to chain API calls.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This works, but your hunch is right. angular ui-router cleans this up for us: