11import type { ErrorResponse } from '../interfaces' ;
22import { Resend } from '../resend' ;
3- import {
4- mockErrorResponse ,
5- mockSuccessResponse ,
6- } from '../test-utils/mock-fetch' ;
3+ import { mockSuccessResponse } from '../test-utils/mock-fetch' ;
74import type {
85 CreateApiKeyOptions ,
96 CreateApiKeyResponseSuccess ,
@@ -22,8 +19,12 @@ describe('API Keys', () => {
2219 id : '430eed87-632a-4ea6-90db-0aace67ec228' ,
2320 } ;
2421
25- mockSuccessResponse ( response , {
26- headers : { Authorization : 'Bearer re_924b3rjh2387fbewf823' } ,
22+ fetchMock . mockOnce ( JSON . stringify ( response ) , {
23+ status : 201 ,
24+ headers : {
25+ 'content-type' : 'application/json' ,
26+ Authorization : 'Bearer re_924b3rjh2387fbewf823' ,
27+ } ,
2728 } ) ;
2829
2930 const resend = new Resend ( 're_zKa4RCko_Lhm9ost2YjNCctnPjbLw8Nop' ) ;
@@ -37,11 +38,6 @@ describe('API Keys', () => {
3738 "token": "re_PKr4RCko_Lhm9ost2YjNCctnPjbLw8Nqk",
3839 },
3940 "error": null,
40- "rateLimiting": {
41- "limit": 2,
42- "remainingRequests": 2,
43- "shouldResetAfter": 1,
44- },
4541}
4642` ) ;
4743 } ) ;
@@ -55,8 +51,12 @@ describe('API Keys', () => {
5551 name : 'validation_error' ,
5652 } ;
5753
58- mockErrorResponse ( response , {
59- headers : { Authorization : 'Bearer re_924b3rjh2387fbewf823' } ,
54+ fetchMock . mockOnce ( JSON . stringify ( response ) , {
55+ status : 422 ,
56+ headers : {
57+ 'content-type' : 'application/json' ,
58+ Authorization : 'Bearer re_924b3rjh2387fbewf823' ,
59+ } ,
6060 } ) ;
6161
6262 const resend = new Resend ( 're_zKa4RCko_Lhm9ost2YjNCctnPjbLw8Nop' ) ;
@@ -70,11 +70,6 @@ describe('API Keys', () => {
7070 "message": "String must contain at least 1 character(s)",
7171 "name": "validation_error",
7272 },
73- "rateLimiting": {
74- "limit": 2,
75- "remainingRequests": 2,
76- "shouldResetAfter": 1,
77- },
7873}
7974` ) ;
8075 } ) ;
@@ -91,8 +86,12 @@ describe('API Keys', () => {
9186 id : '430eed87-632a-4ea6-90db-0aace67ec228' ,
9287 } ;
9388
94- mockSuccessResponse ( response , {
95- headers : { Authorization : 'Bearer re_924b3rjh2387fbewf823' } ,
89+ fetchMock . mockOnce ( JSON . stringify ( response ) , {
90+ status : 201 ,
91+ headers : {
92+ 'content-type' : 'application/json' ,
93+ Authorization : 'Bearer re_924b3rjh2387fbewf823' ,
94+ } ,
9695 } ) ;
9796
9897 const resend = new Resend ( 're_zKa4RCko_Lhm9ost2YjNCctnPjbLw8Nop' ) ;
@@ -106,11 +105,6 @@ describe('API Keys', () => {
106105 "token": "re_PKr4RCko_Lhm9ost2YjNCctnPjbLw8Nqk",
107106 },
108107 "error": null,
109- "rateLimiting": {
110- "limit": 2,
111- "remainingRequests": 2,
112- "shouldResetAfter": 1,
113- },
114108}
115109` ) ;
116110 } ) ;
@@ -125,8 +119,12 @@ describe('API Keys', () => {
125119 id : '430eed87-632a-4ea6-90db-0aace67ec228' ,
126120 } ;
127121
128- mockSuccessResponse ( response , {
129- headers : { Authorization : 'Bearer re_924b3rjh2387fbewf823' } ,
122+ fetchMock . mockOnce ( JSON . stringify ( response ) , {
123+ status : 201 ,
124+ headers : {
125+ 'content-type' : 'application/json' ,
126+ Authorization : 'Bearer re_924b3rjh2387fbewf823' ,
127+ } ,
130128 } ) ;
131129
132130 const resend = new Resend ( 're_zKa4RCko_Lhm9ost2YjNCctnPjbLw8Nop' ) ;
@@ -140,11 +138,6 @@ describe('API Keys', () => {
140138 "token": "re_PKr4RCko_Lhm9ost2YjNCctnPjbLw8Nqk",
141139 },
142140 "error": null,
143- "rateLimiting": {
144- "limit": 2,
145- "remainingRequests": 2,
146- "shouldResetAfter": 1,
147- },
148141}
149142` ) ;
150143 } ) ;
@@ -155,8 +148,12 @@ describe('API Keys', () => {
155148 message : 'Access must be "full_access" | "sending_access"' ,
156149 } ;
157150
158- mockErrorResponse ( response , {
159- headers : { Authorization : 'Bearer re_924b3rjh2387fbewf823' } ,
151+ fetchMock . mockOnce ( JSON . stringify ( response ) , {
152+ status : 422 ,
153+ headers : {
154+ 'content-type' : 'application/json' ,
155+ Authorization : 'Bearer re_924b3rjh2387fbewf823' ,
156+ } ,
160157 } ) ;
161158
162159 const resend = new Resend ( 're_zKa4RCko_Lhm9ost2YjNCctnPjbLw8Nop' ) ;
@@ -175,11 +172,6 @@ describe('API Keys', () => {
175172 "message": "Access must be "full_access" | "sending_access"",
176173 "name": "invalid_access",
177174 },
178- "rateLimiting": {
179- "limit": 2,
180- "remainingRequests": 2,
181- "shouldResetAfter": 1,
182- },
183175}
184176` ) ;
185177 } ) ;
@@ -291,11 +283,6 @@ describe('API Keys', () => {
291283 expect ( result ) . toEqual ( {
292284 data : response ,
293285 error : null ,
294- rateLimiting : {
295- limit : 2 ,
296- remainingRequests : 2 ,
297- shouldResetAfter : 1 ,
298- } ,
299286 } ) ;
300287
301288 expect ( fetchMock ) . toHaveBeenCalledWith (
@@ -319,11 +306,6 @@ describe('API Keys', () => {
319306 expect ( result ) . toEqual ( {
320307 data : response ,
321308 error : null ,
322- rateLimiting : {
323- limit : 2 ,
324- remainingRequests : 2 ,
325- shouldResetAfter : 1 ,
326- } ,
327309 } ) ;
328310
329311 expect ( fetchMock ) . toHaveBeenCalledWith (
@@ -348,11 +330,6 @@ describe('API Keys', () => {
348330 expect ( result ) . toEqual ( {
349331 data : response ,
350332 error : null ,
351- rateLimiting : {
352- limit : 2 ,
353- remainingRequests : 2 ,
354- shouldResetAfter : 1 ,
355- } ,
356333 } ) ;
357334
358335 expect ( fetchMock ) . toHaveBeenCalledWith (
@@ -377,11 +354,6 @@ describe('API Keys', () => {
377354 expect ( result ) . toEqual ( {
378355 data : response ,
379356 error : null ,
380- rateLimiting : {
381- limit : 2 ,
382- remainingRequests : 2 ,
383- shouldResetAfter : 1 ,
384- } ,
385357 } ) ;
386358
387359 expect ( fetchMock ) . toHaveBeenCalledWith (
@@ -400,8 +372,12 @@ describe('API Keys', () => {
400372 const response : RemoveApiKeyResponseSuccess = { } ;
401373
402374 it ( 'removes an api key' , async ( ) => {
403- mockSuccessResponse ( response , {
404- headers : { Authorization : 'Bearer re_924b3rjh2387fbewf823' } ,
375+ fetchMock . mockOnce ( JSON . stringify ( response ) , {
376+ status : 200 ,
377+ headers : {
378+ 'content-type' : 'application/json' ,
379+ Authorization : 'Bearer re_924b3rjh2387fbewf823' ,
380+ } ,
405381 } ) ;
406382
407383 const resend = new Resend ( 're_zKa4RCko_Lhm9ost2YjNCctnPjbLw8Nop' ) ;
@@ -410,11 +386,6 @@ describe('API Keys', () => {
410386{
411387 "data": {},
412388 "error": null,
413- "rateLimiting": {
414- "limit": 2,
415- "remainingRequests": 2,
416- "shouldResetAfter": 1,
417- },
418389}
419390` ) ;
420391 } ) ;
@@ -425,8 +396,12 @@ describe('API Keys', () => {
425396 message : 'Something went wrong' ,
426397 } ;
427398
428- mockErrorResponse ( response , {
429- headers : { Authorization : 'Bearer re_924b3rjh2387fbewf823' } ,
399+ fetchMock . mockOnce ( JSON . stringify ( response ) , {
400+ status : 500 ,
401+ headers : {
402+ 'content-type' : 'application/json' ,
403+ Authorization : 'Bearer re_924b3rjh2387fbewf823' ,
404+ } ,
430405 } ) ;
431406
432407 const resend = new Resend ( 're_zKa4RCko_Lhm9ost2YjNCctnPjbLw8Nop' ) ;
@@ -440,11 +415,6 @@ describe('API Keys', () => {
440415 "message": "Something went wrong",
441416 "name": "application_error",
442417 },
443- "rateLimiting": {
444- "limit": 2,
445- "remainingRequests": 2,
446- "shouldResetAfter": 1,
447- },
448418}
449419` ) ;
450420 } ) ;
@@ -455,8 +425,12 @@ describe('API Keys', () => {
455425 message : 'API key not found' ,
456426 } ;
457427
458- mockErrorResponse ( response , {
459- headers : { Authorization : 'Bearer re_924b3rjh2387fbewf823' } ,
428+ fetchMock . mockOnce ( JSON . stringify ( response ) , {
429+ status : 404 ,
430+ headers : {
431+ 'content-type' : 'application/json' ,
432+ Authorization : 'Bearer re_924b3rjh2387fbewf823' ,
433+ } ,
460434 } ) ;
461435
462436 const resend = new Resend ( 're_zKa4RCko_Lhm9ost2YjNCctnPjbLw8Nop' ) ;
@@ -472,11 +446,6 @@ describe('API Keys', () => {
472446 "message": "API key not found",
473447 "name": "not_found",
474448 },
475- "rateLimiting": {
476- "limit": 2,
477- "remainingRequests": 2,
478- "shouldResetAfter": 1,
479- },
480449}
481450` ) ;
482451 } ) ;
0 commit comments