@@ -396,7 +396,8 @@ describe('Class: ProviderService', () => {
396
396
// Act
397
397
provider . instrumentFetch ( ) ;
398
398
mockFetch ( {
399
- origin : 'https://aws.amazon.com/blogs' ,
399
+ origin : 'https://aws.amazon.com' ,
400
+ path : '/blogs' ,
400
401
headers : {
401
402
'content-length' : '100' ,
402
403
} ,
@@ -407,7 +408,7 @@ describe('Class: ProviderService', () => {
407
408
expect ( segment . addNewSubsegment ) . toHaveBeenCalledWith ( 'aws.amazon.com' ) ;
408
409
expect ( ( subsegment as HttpSubsegment ) . http ) . toEqual ( {
409
410
request : {
410
- url : 'aws.amazon.com' ,
411
+ url : 'https:// aws.amazon.com/blogs ' ,
411
412
method : 'GET' ,
412
413
} ,
413
414
response : {
@@ -438,7 +439,8 @@ describe('Class: ProviderService', () => {
438
439
// Act
439
440
provider . instrumentFetch ( ) ;
440
441
mockFetch ( {
441
- origin : new URL ( 'https://aws.amazon.com/blogs' ) ,
442
+ origin : new URL ( 'https://aws.amazon.com' ) ,
443
+ path : '/blogs' ,
442
444
headers : {
443
445
'content-type' : 'application/json' ,
444
446
} ,
@@ -447,7 +449,7 @@ describe('Class: ProviderService', () => {
447
449
// Assess
448
450
expect ( ( subsegment as HttpSubsegment ) . http ) . toEqual ( {
449
451
request : {
450
- url : 'aws.amazon.com' ,
452
+ url : 'https:// aws.amazon.com/blogs ' ,
451
453
method : 'GET' ,
452
454
} ,
453
455
response : {
@@ -568,6 +570,56 @@ describe('Class: ProviderService', () => {
568
570
expect ( subsegment . close ) . toHaveBeenCalledTimes ( 1 ) ;
569
571
expect ( provider . setSegment ) . toHaveBeenLastCalledWith ( segment ) ;
570
572
} ) ;
573
+
574
+ it ( 'skips the segment creation when the request has no origin' , async ( ) => {
575
+ // Prepare
576
+ const provider : ProviderService = new ProviderService ( ) ;
577
+ const segment = new Subsegment ( '## dummySegment' ) ;
578
+ jest . spyOn ( segment , 'addNewSubsegment' ) ;
579
+ jest . spyOn ( provider , 'getSegment' ) . mockImplementation ( ( ) => segment ) ;
580
+ jest . spyOn ( provider , 'setSegment' ) ;
581
+
582
+ // Act
583
+ provider . instrumentFetch ( ) ;
584
+ mockFetch ( { } ) ;
585
+
586
+ // Assess
587
+ expect ( segment . addNewSubsegment ) . toHaveBeenCalledTimes ( 0 ) ;
588
+ expect ( provider . setSegment ) . toHaveBeenCalledTimes ( 0 ) ;
589
+ } ) ;
590
+
591
+ it ( 'does not add any path to the segment when the request has no path' , async ( ) => {
592
+ // Prepare
593
+ const provider : ProviderService = new ProviderService ( ) ;
594
+ const segment = new Subsegment ( '## dummySegment' ) ;
595
+ const subsegment = segment . addNewSubsegment ( 'aws.amazon.com' ) ;
596
+ jest
597
+ . spyOn ( segment , 'addNewSubsegment' )
598
+ . mockImplementationOnce ( ( ) => subsegment ) ;
599
+ jest
600
+ . spyOn ( provider , 'getSegment' )
601
+ . mockImplementationOnce ( ( ) => segment )
602
+ . mockImplementationOnce ( ( ) => subsegment )
603
+ . mockImplementationOnce ( ( ) => subsegment ) ;
604
+ jest . spyOn ( subsegment , 'close' ) ;
605
+ jest . spyOn ( provider , 'setSegment' ) ;
606
+
607
+ // Act
608
+ provider . instrumentFetch ( ) ;
609
+ mockFetch ( {
610
+ origin : new URL ( 'https://aws.amazon.com' ) ,
611
+ } ) ;
612
+
613
+ // Assess
614
+ expect ( ( subsegment as HttpSubsegment ) . http ) . toEqual (
615
+ expect . objectContaining ( {
616
+ request : {
617
+ url : 'https://aws.amazon.com/' ,
618
+ method : 'GET' ,
619
+ } ,
620
+ } )
621
+ ) ;
622
+ } ) ;
571
623
} ) ;
572
624
573
625
it ( 'closes the segment and adds a fault flag when the connection fails' , async ( ) => {
0 commit comments