@@ -197,3 +197,43 @@ describe('updateRateLimits()', () => {
197197 expect ( updatedRateLimits . all ) . toEqual ( 60_000 ) ;
198198 } ) ;
199199} ) ;
200+
201+ describe ( 'data category "metric_bucket"' , ( ) => {
202+ test ( 'should add limit for `metric_bucket` category when namespaces contain "custom"' , ( ) => {
203+ const rateLimits : RateLimits = { } ;
204+ const headers = {
205+ 'retry-after' : null ,
206+ 'x-sentry-rate-limits' : '42:metric_bucket:::custom' ,
207+ } ;
208+ const updatedRateLimits = updateRateLimits ( rateLimits , { headers } , 0 ) ;
209+ expect ( updatedRateLimits . metric_bucket ) . toEqual ( 42 * 1000 ) ;
210+ } ) ;
211+
212+ test ( 'should not add limit for `metric_bucket` category when namespaces do not contain "custom"' , ( ) => {
213+ const rateLimits : RateLimits = { } ;
214+ const headers = {
215+ 'retry-after' : null ,
216+ 'x-sentry-rate-limits' : '42:metric_bucket:::namespace1;namespace2' ,
217+ } ;
218+ const updatedRateLimits = updateRateLimits ( rateLimits , { headers } , 0 ) ;
219+ expect ( updatedRateLimits . metric_bucket ) . toBeUndefined ( ) ;
220+ } ) ;
221+
222+ test ( 'should add limit for `metric_bucket` category when namespaces are empty' , ( ) => {
223+ const rateLimits : RateLimits = { } ;
224+
225+ const headers1 = {
226+ 'retry-after' : null ,
227+ 'x-sentry-rate-limits' : '42:metric_bucket' , // without semicolon at the end
228+ } ;
229+ const updatedRateLimits1 = updateRateLimits ( rateLimits , { headers : headers1 } , 0 ) ;
230+ expect ( updatedRateLimits1 . metric_bucket ) . toEqual ( 42 * 1000 ) ;
231+
232+ const headers2 = {
233+ 'retry-after' : null ,
234+ 'x-sentry-rate-limits' : '42:metric_bucket:organization:quota_exceeded:' , // with semicolon at the end
235+ } ;
236+ const updatedRateLimits2 = updateRateLimits ( rateLimits , { headers : headers2 } , 0 ) ;
237+ expect ( updatedRateLimits2 . metric_bucket ) . toEqual ( 42 * 1000 ) ;
238+ } ) ;
239+ } ) ;
0 commit comments