11import type { ErrorResponse } from '../interfaces' ;
22import { Resend } from '../resend' ;
3- import {
4- mockErrorResponse ,
5- mockSuccessResponse ,
6- } from '../test-utils/mock-fetch' ;
73import type {
84 CreateApiKeyOptions ,
95 CreateApiKeyResponseSuccess ,
@@ -22,8 +18,12 @@ describe('API Keys', () => {
2218 id : '430eed87-632a-4ea6-90db-0aace67ec228' ,
2319 } ;
2420
25- mockSuccessResponse ( response , {
26- headers : { Authorization : 'Bearer re_924b3rjh2387fbewf823' } ,
21+ fetchMock . mockOnce ( JSON . stringify ( response ) , {
22+ status : 201 ,
23+ headers : {
24+ 'content-type' : 'application/json' ,
25+ Authorization : 'Bearer re_924b3rjh2387fbewf823' ,
26+ } ,
2727 } ) ;
2828
2929 const resend = new Resend ( 're_zKa4RCko_Lhm9ost2YjNCctnPjbLw8Nop' ) ;
@@ -37,11 +37,6 @@ describe('API Keys', () => {
3737 "token": "re_PKr4RCko_Lhm9ost2YjNCctnPjbLw8Nqk",
3838 },
3939 "error": null,
40- "rateLimiting": {
41- "limit": 2,
42- "remainingRequests": 2,
43- "shouldResetAfter": 1,
44- },
4540}
4641` ) ;
4742 } ) ;
@@ -55,8 +50,12 @@ describe('API Keys', () => {
5550 name : 'validation_error' ,
5651 } ;
5752
58- mockErrorResponse ( response , {
59- headers : { Authorization : 'Bearer re_924b3rjh2387fbewf823' } ,
53+ fetchMock . mockOnce ( JSON . stringify ( response ) , {
54+ status : 422 ,
55+ headers : {
56+ 'content-type' : 'application/json' ,
57+ Authorization : 'Bearer re_924b3rjh2387fbewf823' ,
58+ } ,
6059 } ) ;
6160
6261 const resend = new Resend ( 're_zKa4RCko_Lhm9ost2YjNCctnPjbLw8Nop' ) ;
@@ -70,11 +69,6 @@ describe('API Keys', () => {
7069 "message": "String must contain at least 1 character(s)",
7170 "name": "validation_error",
7271 },
73- "rateLimiting": {
74- "limit": 2,
75- "remainingRequests": 2,
76- "shouldResetAfter": 1,
77- },
7872}
7973` ) ;
8074 } ) ;
@@ -91,8 +85,12 @@ describe('API Keys', () => {
9185 id : '430eed87-632a-4ea6-90db-0aace67ec228' ,
9286 } ;
9387
94- mockSuccessResponse ( response , {
95- headers : { Authorization : 'Bearer re_924b3rjh2387fbewf823' } ,
88+ fetchMock . mockOnce ( JSON . stringify ( response ) , {
89+ status : 201 ,
90+ headers : {
91+ 'content-type' : 'application/json' ,
92+ Authorization : 'Bearer re_924b3rjh2387fbewf823' ,
93+ } ,
9694 } ) ;
9795
9896 const resend = new Resend ( 're_zKa4RCko_Lhm9ost2YjNCctnPjbLw8Nop' ) ;
@@ -106,11 +104,6 @@ describe('API Keys', () => {
106104 "token": "re_PKr4RCko_Lhm9ost2YjNCctnPjbLw8Nqk",
107105 },
108106 "error": null,
109- "rateLimiting": {
110- "limit": 2,
111- "remainingRequests": 2,
112- "shouldResetAfter": 1,
113- },
114107}
115108` ) ;
116109 } ) ;
@@ -125,8 +118,12 @@ describe('API Keys', () => {
125118 id : '430eed87-632a-4ea6-90db-0aace67ec228' ,
126119 } ;
127120
128- mockSuccessResponse ( response , {
129- headers : { Authorization : 'Bearer re_924b3rjh2387fbewf823' } ,
121+ fetchMock . mockOnce ( JSON . stringify ( response ) , {
122+ status : 201 ,
123+ headers : {
124+ 'content-type' : 'application/json' ,
125+ Authorization : 'Bearer re_924b3rjh2387fbewf823' ,
126+ } ,
130127 } ) ;
131128
132129 const resend = new Resend ( 're_zKa4RCko_Lhm9ost2YjNCctnPjbLw8Nop' ) ;
@@ -140,11 +137,6 @@ describe('API Keys', () => {
140137 "token": "re_PKr4RCko_Lhm9ost2YjNCctnPjbLw8Nqk",
141138 },
142139 "error": null,
143- "rateLimiting": {
144- "limit": 2,
145- "remainingRequests": 2,
146- "shouldResetAfter": 1,
147- },
148140}
149141` ) ;
150142 } ) ;
@@ -155,8 +147,12 @@ describe('API Keys', () => {
155147 message : 'Access must be "full_access" | "sending_access"' ,
156148 } ;
157149
158- mockErrorResponse ( response , {
159- headers : { Authorization : 'Bearer re_924b3rjh2387fbewf823' } ,
150+ fetchMock . mockOnce ( JSON . stringify ( response ) , {
151+ status : 422 ,
152+ headers : {
153+ 'content-type' : 'application/json' ,
154+ Authorization : 'Bearer re_924b3rjh2387fbewf823' ,
155+ } ,
160156 } ) ;
161157
162158 const resend = new Resend ( 're_zKa4RCko_Lhm9ost2YjNCctnPjbLw8Nop' ) ;
@@ -175,11 +171,6 @@ describe('API Keys', () => {
175171 "message": "Access must be "full_access" | "sending_access"",
176172 "name": "invalid_access",
177173 },
178- "rateLimiting": {
179- "limit": 2,
180- "remainingRequests": 2,
181- "shouldResetAfter": 1,
182- },
183174}
184175` ) ;
185176 } ) ;
@@ -400,8 +391,12 @@ describe('API Keys', () => {
400391 const response : RemoveApiKeyResponseSuccess = { } ;
401392
402393 it ( 'removes an api key' , async ( ) => {
403- mockSuccessResponse ( response , {
404- headers : { Authorization : 'Bearer re_924b3rjh2387fbewf823' } ,
394+ fetchMock . mockOnce ( JSON . stringify ( response ) , {
395+ status : 200 ,
396+ headers : {
397+ 'content-type' : 'application/json' ,
398+ Authorization : 'Bearer re_924b3rjh2387fbewf823' ,
399+ } ,
405400 } ) ;
406401
407402 const resend = new Resend ( 're_zKa4RCko_Lhm9ost2YjNCctnPjbLw8Nop' ) ;
@@ -410,11 +405,6 @@ describe('API Keys', () => {
410405{
411406 "data": {},
412407 "error": null,
413- "rateLimiting": {
414- "limit": 2,
415- "remainingRequests": 2,
416- "shouldResetAfter": 1,
417- },
418408}
419409` ) ;
420410 } ) ;
@@ -425,8 +415,12 @@ describe('API Keys', () => {
425415 message : 'Something went wrong' ,
426416 } ;
427417
428- mockErrorResponse ( response , {
429- headers : { Authorization : 'Bearer re_924b3rjh2387fbewf823' } ,
418+ fetchMock . mockOnce ( JSON . stringify ( response ) , {
419+ status : 500 ,
420+ headers : {
421+ 'content-type' : 'application/json' ,
422+ Authorization : 'Bearer re_924b3rjh2387fbewf823' ,
423+ } ,
430424 } ) ;
431425
432426 const resend = new Resend ( 're_zKa4RCko_Lhm9ost2YjNCctnPjbLw8Nop' ) ;
@@ -440,11 +434,6 @@ describe('API Keys', () => {
440434 "message": "Something went wrong",
441435 "name": "application_error",
442436 },
443- "rateLimiting": {
444- "limit": 2,
445- "remainingRequests": 2,
446- "shouldResetAfter": 1,
447- },
448437}
449438` ) ;
450439 } ) ;
@@ -455,8 +444,12 @@ describe('API Keys', () => {
455444 message : 'API key not found' ,
456445 } ;
457446
458- mockErrorResponse ( response , {
459- headers : { Authorization : 'Bearer re_924b3rjh2387fbewf823' } ,
447+ fetchMock . mockOnce ( JSON . stringify ( response ) , {
448+ status : 404 ,
449+ headers : {
450+ 'content-type' : 'application/json' ,
451+ Authorization : 'Bearer re_924b3rjh2387fbewf823' ,
452+ } ,
460453 } ) ;
461454
462455 const resend = new Resend ( 're_zKa4RCko_Lhm9ost2YjNCctnPjbLw8Nop' ) ;
@@ -472,11 +465,6 @@ describe('API Keys', () => {
472465 "message": "API key not found",
473466 "name": "not_found",
474467 },
475- "rateLimiting": {
476- "limit": 2,
477- "remainingRequests": 2,
478- "shouldResetAfter": 1,
479- },
480468}
481469` ) ;
482470 } ) ;
0 commit comments