@@ -18,6 +18,7 @@ describe("lib/api/resources/ApiTokens: ", () => {
1818 describe ( "class ApiTokensApi(): " , ( ) => {
1919 describe ( "init: " , ( ) => {
2020 it ( "initializes with all necessary params." , ( ) => {
21+ expect ( apiTokensAPI ) . toHaveProperty ( "getList" ) ;
2122 expect ( apiTokensAPI ) . toHaveProperty ( "create" ) ;
2223 expect ( apiTokensAPI ) . toHaveProperty ( "get" ) ;
2324 expect ( apiTokensAPI ) . toHaveProperty ( "reset" ) ;
@@ -41,6 +42,53 @@ describe("lib/api/resources/ApiTokens: ", () => {
4142 mock . reset ( ) ;
4243 } ) ;
4344
45+ describe ( "getList(): " , ( ) => {
46+ const responseData = [
47+ {
48+ id : 12345 ,
49+ name : "My API Token" ,
50+ last_4_digits : "x7k9" ,
51+ created_by : "user@example.com" ,
52+ expires_at : null ,
53+ resources : [
54+ {
55+ resource_type : "account" ,
56+ resource_id : 3229 ,
57+ access_level : 100 ,
58+ } ,
59+ ] ,
60+ } ,
61+ ] ;
62+
63+ it ( "gets the list of API tokens." , async ( ) => {
64+ const endpoint = `${ GENERAL_ENDPOINT } /api/accounts/${ accountId } /api_tokens` ;
65+
66+ expect . assertions ( 2 ) ;
67+
68+ mock . onGet ( endpoint ) . reply ( 200 , responseData ) ;
69+ const result = await apiTokensAPI . getList ( ) ;
70+
71+ expect ( mock . history . get [ 0 ] . url ) . toEqual ( endpoint ) ;
72+ expect ( result ) . toEqual ( responseData ) ;
73+ } ) ;
74+
75+ it ( "fails with error." , async ( ) => {
76+ const expectedErrorMessage = "Request failed with status code 404" ;
77+
78+ expect . assertions ( 2 ) ;
79+
80+ try {
81+ await apiTokensAPI . getList ( ) ;
82+ } catch ( error ) {
83+ expect ( error ) . toBeInstanceOf ( MailtrapError ) ;
84+
85+ if ( error instanceof MailtrapError ) {
86+ expect ( error . message ) . toEqual ( expectedErrorMessage ) ;
87+ }
88+ }
89+ } ) ;
90+ } ) ;
91+
4492 describe ( "create(): " , ( ) => {
4593 const params = {
4694 name : "My API Token" ,
0 commit comments