@@ -937,6 +937,44 @@ describe('ParticleAPI', () => {
937
937
sinon . restore ( ) ;
938
938
} ) ;
939
939
940
+ describe ( 'http headers' , ( ) => {
941
+ it ( 'initializes options correctly with a blank headers object' , async ( ) => {
942
+ const { options } = await api . getEventStream ( { } ) ;
943
+ expect ( options ) . to . be . an ( 'object' ) ;
944
+ expect ( options . headers ) . to . be . an ( 'object' ) ;
945
+ } ) ;
946
+
947
+ it ( 'determines http headers using ._getDefaultHttpHeadersForContext()' , async ( ) => {
948
+ const fakeHeaders = { 'X-Fake-Header' : 'foo' } ;
949
+ sinon . stub ( api , '_getDefaultHttpHeadersForContext' ) . returns ( fakeHeaders ) ;
950
+ const { options } = await api . getEventStream ( { } ) ;
951
+ expect ( options ) . to . be . an ( 'object' ) ;
952
+ expect ( options . headers ) . to . eql ( fakeHeaders ) ;
953
+ } ) ;
954
+
955
+ describe ( '._getDefaultHttpHeadersForContext() (a way to get http headers from context)' , ( ) => {
956
+
957
+ it ( 'returns empty object when no context has been set' , ( ) => {
958
+ expect ( api . _getDefaultHttpHeadersForContext ( ) ) . to . eql ( { } ) ;
959
+ } ) ;
960
+
961
+ it ( 'includes X-Particle-Tool when this.context.tool is set' , ( ) => {
962
+ api . setContext ( 'tool' , { name : 'fake' , version : '1.2.3' } ) ;
963
+ const r = api . _getDefaultHttpHeadersForContext ( ) ;
964
+ expect ( r ) . to . be . an ( 'object' ) ;
965
+ expect ( r [ 'X-Particle-Tool' ] ) . to . eql ( 'fake@1.2.3' ) ;
966
+ } ) ;
967
+
968
+ it ( 'includes X-Particle-Project when this.context.project is set' , ( ) => {
969
+ api . setContext ( 'project' , { name : 'fake' , version : '1.2.3' } ) ;
970
+ const r = api . _getDefaultHttpHeadersForContext ( ) ;
971
+ expect ( r ) . to . be . an ( 'object' ) ;
972
+ expect ( r [ 'X-Particle-Project' ] ) . to . eql ( 'fake@1.2.3' ) ;
973
+ } ) ;
974
+ } ) ;
975
+
976
+ } ) ;
977
+
940
978
it ( 'requests public events' , ( ) => {
941
979
return api . getEventStream ( { } ) . then ( ( { uri } ) => {
942
980
uri . should . endWith ( 'events' ) ;
0 commit comments