@@ -38,6 +38,107 @@ describe('Constructor', function () {
3838 bitgo . cookiesPropagationEnabled . should . equal ( false ) ;
3939 } ) ;
4040 } ) ;
41+
42+ describe ( 'requestIdPrefix argument' , function ( ) {
43+ afterEach ( function ( ) {
44+ nock . cleanAll ( ) ;
45+ } ) ;
46+
47+ it ( 'should prepend requestIdPrefix to Request-ID header when set' , async function ( ) {
48+ const bitgo = new BitGoAPI ( {
49+ env : 'custom' ,
50+ customRootURI : 'https://app.example.local' ,
51+ requestIdPrefix : 'test-prefix-' ,
52+ } ) ;
53+
54+ const scope = nock ( 'https://app.example.local' )
55+ . get ( '/api/v1/ping' )
56+ . matchHeader ( 'Request-ID' , / ^ t e s t - p r e f i x - / )
57+ . reply ( 200 , { status : 'ok' } ) ;
58+
59+ await bitgo . ping ( {
60+ reqId : {
61+ toString : ( ) => '12345' ,
62+ inc : ( ) => {
63+ /* mock */
64+ } ,
65+ } as any ,
66+ } ) ;
67+
68+ scope . isDone ( ) . should . be . true ( ) ;
69+ } ) ;
70+
71+ it ( 'should not modify Request-ID header when requestIdPrefix is not set' , async function ( ) {
72+ const bitgo = new BitGoAPI ( {
73+ env : 'custom' ,
74+ customRootURI : 'https://app.example.local' ,
75+ } ) ;
76+
77+ const scope = nock ( 'https://app.example.local' )
78+ . get ( '/api/v1/ping' )
79+ . matchHeader ( 'Request-ID' , / ^ 1 2 3 4 5 $ / )
80+ . reply ( 200 , { status : 'ok' } ) ;
81+
82+ await bitgo . ping ( {
83+ reqId : {
84+ toString : ( ) => '12345' ,
85+ inc : ( ) => {
86+ /* mock */
87+ } ,
88+ } as any ,
89+ } ) ;
90+
91+ scope . isDone ( ) . should . be . true ( ) ;
92+ } ) ;
93+
94+ it ( 'should correctly format Request-ID with prefix and numeric sequence' , async function ( ) {
95+ const bitgo = new BitGoAPI ( {
96+ env : 'custom' ,
97+ customRootURI : 'https://app.example.local' ,
98+ requestIdPrefix : 'myapp-v1-' ,
99+ } ) ;
100+
101+ const scope = nock ( 'https://app.example.local' )
102+ . get ( '/api/v1/ping' )
103+ . matchHeader ( 'Request-ID' , 'myapp-v1-trace-123' )
104+ . reply ( 200 , { status : 'ok' } ) ;
105+
106+ await bitgo . ping ( {
107+ reqId : {
108+ toString : ( ) => 'trace-123' ,
109+ inc : ( ) => {
110+ /* mock */
111+ } ,
112+ } as any ,
113+ } ) ;
114+
115+ scope . isDone ( ) . should . be . true ( ) ;
116+ } ) ;
117+
118+ it ( 'should work with empty string prefix' , async function ( ) {
119+ const bitgo = new BitGoAPI ( {
120+ env : 'custom' ,
121+ customRootURI : 'https://app.example.local' ,
122+ requestIdPrefix : '' ,
123+ } ) ;
124+
125+ const scope = nock ( 'https://app.example.local' )
126+ . get ( '/api/v1/ping' )
127+ . matchHeader ( 'Request-ID' , 'abc-123' )
128+ . reply ( 200 , { status : 'ok' } ) ;
129+
130+ await bitgo . ping ( {
131+ reqId : {
132+ toString : ( ) => 'abc-123' ,
133+ inc : ( ) => {
134+ /* mock */
135+ } ,
136+ } as any ,
137+ } ) ;
138+
139+ scope . isDone ( ) . should . be . true ( ) ;
140+ } ) ;
141+ } ) ;
41142 describe ( 'http proxy agent' , function ( ) {
42143 it ( 'http proxy agent shall be created when proxy(customProxyagent) is set' , function ( ) {
43144 const customProxyAgent = new ProxyAgent ( {
0 commit comments