1+ import { Session } from '@sentry/hub' ;
12import { TransportOptions } from '@sentry/types' ;
23import { SentryError } from '@sentry/utils' ;
34import * as HttpsProxyAgent from 'https-proxy-agent' ;
@@ -7,6 +8,7 @@ import { HTTPSTransport } from '../../src/transports/https';
78const mockSetEncoding = jest . fn ( ) ;
89const dsn = 'https://[email protected] :8989/mysubpath/50622' ; 910const transportPath = '/mysubpath/api/50622/store/' ;
11+ const envelopePath = '/mysubpath/api/50622/envelope/' ;
1012let mockReturnCode = 200 ;
1113let mockHeaders = { } ;
1214
@@ -33,12 +35,12 @@ function createTransport(options: TransportOptions): HTTPSTransport {
3335 return transport ;
3436}
3537
36- function assertBasicOptions ( options : any ) : void {
38+ function assertBasicOptions ( options : any , useEnvelope : boolean = false ) : void {
3739 expect ( options . headers [ 'X-Sentry-Auth' ] ) . toContain ( 'sentry_version' ) ;
3840 expect ( options . headers [ 'X-Sentry-Auth' ] ) . toContain ( 'sentry_client' ) ;
3941 expect ( options . headers [ 'X-Sentry-Auth' ] ) . toContain ( 'sentry_key' ) ;
4042 expect ( options . port ) . toEqual ( '8989' ) ;
41- expect ( options . path ) . toEqual ( transportPath ) ;
43+ expect ( options . path ) . toEqual ( useEnvelope ? envelopePath : transportPath ) ;
4244 expect ( options . hostname ) . toEqual ( 'sentry.io' ) ;
4345}
4446
@@ -75,6 +77,28 @@ describe('HTTPSTransport', () => {
7577 }
7678 } ) ;
7779
80+ test ( 'send 200 session' , async ( ) => {
81+ const transport = createTransport ( { dsn } ) ;
82+ await transport . sendSession ( new Session ( ) ) ;
83+
84+ const requestOptions = ( transport . module ! . request as jest . Mock ) . mock . calls [ 0 ] [ 0 ] ;
85+ assertBasicOptions ( requestOptions , true ) ;
86+ expect ( mockSetEncoding ) . toHaveBeenCalled ( ) ;
87+ } ) ;
88+
89+ test ( 'send 400 session' , async ( ) => {
90+ mockReturnCode = 400 ;
91+ const transport = createTransport ( { dsn } ) ;
92+
93+ try {
94+ await transport . sendSession ( new Session ( ) ) ;
95+ } catch ( e ) {
96+ const requestOptions = ( transport . module ! . request as jest . Mock ) . mock . calls [ 0 ] [ 0 ] ;
97+ assertBasicOptions ( requestOptions , true ) ;
98+ expect ( e ) . toEqual ( new SentryError ( `HTTP Error (${ mockReturnCode } )` ) ) ;
99+ }
100+ } ) ;
101+
78102 test ( 'send x-sentry-error header' , async ( ) => {
79103 mockReturnCode = 429 ;
80104 mockHeaders = {
0 commit comments