@@ -626,6 +626,35 @@ describe('M2MToken', () => {
626626 expect ( response . totalCount ) . toBe ( 2 ) ;
627627 } ) ;
628628
629+ it ( 'lists m2m tokens using machine secret key option' , async ( ) => {
630+ const apiClient = createBackendApiClient ( {
631+ apiUrl : 'https://api.clerk.test' ,
632+ } ) ;
633+
634+ server . use (
635+ http . get (
636+ 'https://api.clerk.test/m2m_tokens' ,
637+ validateHeaders ( ( { request } ) => {
638+ expect ( request . headers . get ( 'Authorization' ) ) . toBe ( 'Bearer ak_xxxxx' ) ;
639+ const url = new URL ( request . url ) ;
640+ expect ( url . searchParams . get ( 'subject' ) ) . toBe ( machineId ) ;
641+ expect ( url . searchParams . has ( 'machineSecretKey' ) ) . toBe ( false ) ;
642+ return HttpResponse . json ( mockM2MTokenList ) ;
643+ } ) ,
644+ ) ,
645+ ) ;
646+
647+ const response = await apiClient . m2m . list ( {
648+ machineSecretKey : 'ak_xxxxx' ,
649+ subject : machineId ,
650+ } ) ;
651+
652+ expect ( response . data ) . toHaveLength ( 2 ) ;
653+ expect ( response . data [ 0 ] . id ) . toBe ( 'mt_1xxxxxxxxxxxxx' ) ;
654+ expect ( response . data [ 1 ] . id ) . toBe ( 'mt_2xxxxxxxxxxxxx' ) ;
655+ expect ( response . totalCount ) . toBe ( 2 ) ;
656+ } ) ;
657+
629658 it ( 'requires a machine secret or instance secret to list m2m tokens' , async ( ) => {
630659 const apiClient = createBackendApiClient ( {
631660 apiUrl : 'https://api.clerk.test' ,
0 commit comments