-
Notifications
You must be signed in to change notification settings - Fork 54
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: [sc-105230] particle-api-js getEventStream does not honor setContext / X-Particle-Tool http header correctly #147
Open
joegoggins
wants to merge
9
commits into
master
Choose a base branch
from
sc-105230/event-stream-http-header-bugfix
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
3fb1350
Add options to EventStream constructor with blank header default key
988ab8f
EventStream connect() passes http headers to http request method
fd847f9
.getEventStream() computes http headers via _getDefaultHttpHeadersFor…
8cfbc89
Adds test to validate EventStream connect passes on http headers
f65b727
Adds getEventStream tests that validate X-Particle-Tool and X-Particl…
876be72
Adject linter to allow anonymous async functions in mocha
74689a0
Tooling bugfix: Move tests not designed to run in CI into their own dir
00176ae
Update docs to reflect not needing to set env vars
fbf6100
Update the docs (just source code link changes)
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
Large diffs are not rendered by default.
Oops, something went wrong.
File renamed without changes.
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
File renamed without changes.
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,10 @@ | ||
The tests in this directory do not run in CI. | ||
|
||
They can be used to do deep validations on the behavior of the library against the actual Particle API | ||
|
||
Follow the directions at in each script for how to use them. | ||
|
||
Also, you'll need set valid values for env vars like PARTICLE_API_BASE_URL | ||
and PARTICLE_API_TOKEN. | ||
|
||
Note also that these e2e-tests are not actively maintained. |
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 |
---|---|---|
|
@@ -929,14 +929,52 @@ describe('ParticleAPI', () => { | |
describe('.getEventStream', () => { | ||
before(() => { | ||
sinon.stub(EventStream.prototype, 'connect').callsFake(function connect(){ | ||
return Promise.resolve({ uri: this.uri }); | ||
return Promise.resolve({ uri: this.uri, options: this.options }); | ||
}); | ||
}); | ||
|
||
after(() => { | ||
sinon.restore(); | ||
}); | ||
|
||
describe('http headers', () => { | ||
it('initializes options correctly with a blank headers object', async () => { | ||
const { options } = await api.getEventStream({}); | ||
expect(options).to.be.an('object'); | ||
expect(options.headers).to.be.an('object'); | ||
}); | ||
|
||
it('determines http headers using ._getDefaultHttpHeadersForContext()', async () => { | ||
const fakeHeaders = { 'X-Fake-Header': 'foo' }; | ||
sinon.stub(api, '_getDefaultHttpHeadersForContext').returns(fakeHeaders); | ||
const { options } = await api.getEventStream({}); | ||
expect(options).to.be.an('object'); | ||
expect(options.headers).to.eql(fakeHeaders); | ||
}); | ||
|
||
describe('._getDefaultHttpHeadersForContext() (a way to get http headers from context)', () => { | ||
|
||
it('returns empty object when no context has been set', () => { | ||
expect(api._getDefaultHttpHeadersForContext()).to.eql({}); | ||
}); | ||
|
||
it('includes X-Particle-Tool when this.context.tool is set', () => { | ||
api.setContext('tool', { name: 'fake', version: '1.2.3' }); | ||
const r = api._getDefaultHttpHeadersForContext(); | ||
expect(r).to.be.an('object'); | ||
expect(r['X-Particle-Tool']).to.eql('[email protected]'); | ||
}); | ||
|
||
it('includes X-Particle-Project when this.context.project is set', () => { | ||
api.setContext('project', { name: 'fake', version: '1.2.3' }); | ||
const r = api._getDefaultHttpHeadersForContext(); | ||
expect(r).to.be.an('object'); | ||
expect(r['X-Particle-Project']).to.eql('[email protected]'); | ||
}); | ||
}); | ||
|
||
}); | ||
|
||
it('requests public events', () => { | ||
return api.getEventStream({ }).then(({ uri }) => { | ||
uri.should.endWith('events'); | ||
|
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.
@joegoggins
fwiw, @deleonn updated CI over in #142 to ensure at least the node-side event e2e tests ran with their required perquisites - here's an example of them running and "passing":
https://app.circleci.com/pipelines/github/particle-iot/particle-api-js/53/workflows/cd0aa933-14fd-4836-a96b-024f13e31457/jobs/156?invite=true#step-103-42
further complicating things, the reference to "
Agent
integration tests" in these docs is incorrect - it's actually thetest/EventStream-e2e-node.js
file which is running in CI.all that said, at this point i'd just delete all of those (
e2e-tests
directory and related) as they're likely to cause more confusion than help.