@@ -14,7 +14,7 @@ describe('reportRequestMetric', () => {
1414 } )
1515
1616 it ( 'reports request metrics to InfluxDB over HTTP' , async ( ) => {
17- const env = withTestEnvitronment ( )
17+ const env = givenTestEnvironment ( )
1818 const request = {
1919 url : 'https://example.com/path' ,
2020 method : 'GET' ,
@@ -40,7 +40,7 @@ describe('reportRequestMetric', () => {
4040
4141describe ( 'createMetricsFromRequest' , ( ) => {
4242 const date = new Date ( )
43- const env = withTestEnvitronment ( )
43+ const env = givenTestEnvironment ( )
4444
4545 beforeEach ( ( ) => {
4646 vi . useFakeTimers ( )
@@ -55,17 +55,13 @@ describe('createMetricsFromRequest', () => {
5555 {
5656 description : 'when request has an API key in the Authorization header' ,
5757 request : {
58- url : 'https://example.com/path' ,
59- method : 'GET' ,
6058 headers : new Map ( [ [ 'Authorization' , 'Bearer test-key' ] ] ) ,
6159 } ,
6260 expectedApiKey : 'test-key' ,
6361 } ,
6462 {
6563 description : 'when request has an API key in the api-key header' ,
6664 request : {
67- url : 'https://example.com/path' ,
68- method : 'GET' ,
6965 headers : new Map ( [ [ 'api-key' , 'test-key' ] ] ) ,
7066 } ,
7167 expectedApiKey : 'test-key' ,
@@ -74,33 +70,34 @@ describe('createMetricsFromRequest', () => {
7470 description : 'when request has an API key in the query string' ,
7571 request : {
7672 url : 'https://example.com/path?api-key=test-key' ,
77- method : 'GET' ,
78- headers : new Map ( ) ,
7973 } ,
8074 expectedApiKey : 'test-key' ,
8175 } ,
8276 {
8377 description : 'when request has no API key' ,
84- request : {
85- url : 'https://example.com/path' ,
86- method : 'GET' ,
87- headers : new Map ( ) ,
88- } ,
78+ request : { } ,
8979 expectedApiKey : 'unknown' ,
9080 } ,
9181 ]
9282
9383 testCases . forEach ( ( { description, request, expectedApiKey } ) => {
9484 it ( description , ( ) => {
95- const result = createMetricsFromRequest ( request , env )
85+ const fullRequest = {
86+ url : 'https://example.com/path' ,
87+ method : 'GET' ,
88+ headers : new Map ( ) ,
89+ ...request
90+ }
91+
92+ const result = createMetricsFromRequest ( fullRequest , env )
9693 expect ( result ) . toContain ( expectedApiKey )
9794 } )
9895 } )
9996} )
10097
10198describe ( 'writeMetrics' , ( ) => {
10299 it ( 'send request metrics to InfluxDB over HTTP' , async ( ) => {
103- const env = withTestEnvitronment ( )
100+ const env = givenTestEnvironment ( )
104101 const lineProtocolData = 'test_metric api_key="test-key"'
105102 global . fetch = vi . fn ( ) . mockResolvedValue ( new Response ( null , { status : 204 } ) )
106103
@@ -121,7 +118,7 @@ describe('writeMetrics', () => {
121118 } )
122119} )
123120
124- const withTestEnvitronment = ( ) => {
121+ const givenTestEnvironment = ( ) => {
125122 return {
126123 INFLUX_METRIC_NAME : 'test_metric' ,
127124 INFLUX_URL : 'https://influx.example.com' ,
0 commit comments