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