@@ -50,12 +50,24 @@ describe('getUsernames route', () => {
5050 const data = ( await response . json ( ) ) as ManagedAddressesResponse | { error : string } ;
5151
5252 expect ( response . status ) . toBe ( 400 ) ;
53- expect ( data ) . toEqual ( { error : 'No address provided' } ) ;
53+ expect ( data ) . toEqual ( { error : 'Invalid address provided' } ) ;
54+ } ) ;
55+
56+ it ( 'should return 400 when an invalid address is provided' , async ( ) => {
57+ const request = new NextRequest (
58+ 'https://www.base.org/api/basenames/getUsernames?address=0x123'
59+ ) ;
60+
61+ const response = await GET ( request ) ;
62+ const data = ( await response . json ( ) ) as ManagedAddressesResponse | { error : string } ;
63+
64+ expect ( response . status ) . toBe ( 400 ) ;
65+ expect ( data ) . toEqual ( { error : 'Invalid address provided' } ) ;
5466 } ) ;
5567
5668 it ( 'should return 400 when an invalid network is provided' , async ( ) => {
5769 const request = new NextRequest (
58- 'https://www.base.org/api/basenames/getUsernames?address=0x123 &network=invalid-network'
70+ 'https://www.base.org/api/basenames/getUsernames?address=0x1234567890123456789012345678901234567890 &network=invalid-network'
5971 ) ;
6072
6173 const response = await GET ( request ) ;
@@ -67,6 +79,7 @@ describe('getUsernames route', () => {
6779
6880 it ( 'should default to base-mainnet when no network is provided' , async ( ) => {
6981 mockFetch . mockResolvedValueOnce ( {
82+ ok : true ,
7083 json : jest . fn ( ) . mockResolvedValue ( mockSuccessResponse ) ,
7184 } ) ;
7285
@@ -89,6 +102,7 @@ describe('getUsernames route', () => {
89102
90103 it ( 'should use base-mainnet when explicitly provided' , async ( ) => {
91104 mockFetch . mockResolvedValueOnce ( {
105+ ok : true ,
92106 json : jest . fn ( ) . mockResolvedValue ( mockSuccessResponse ) ,
93107 } ) ;
94108
@@ -106,6 +120,7 @@ describe('getUsernames route', () => {
106120
107121 it ( 'should use base-sepolia when explicitly provided' , async ( ) => {
108122 mockFetch . mockResolvedValueOnce ( {
123+ ok : true ,
109124 json : jest . fn ( ) . mockResolvedValue ( mockSuccessResponse ) ,
110125 } ) ;
111126
@@ -123,6 +138,7 @@ describe('getUsernames route', () => {
123138
124139 it ( 'should include page parameter in URL when provided' , async ( ) => {
125140 mockFetch . mockResolvedValueOnce ( {
141+ ok : true ,
126142 json : jest . fn ( ) . mockResolvedValue ( mockSuccessResponse ) ,
127143 } ) ;
128144
@@ -140,6 +156,7 @@ describe('getUsernames route', () => {
140156
141157 it ( 'should not include page parameter when not provided' , async ( ) => {
142158 mockFetch . mockResolvedValueOnce ( {
159+ ok : true ,
143160 json : jest . fn ( ) . mockResolvedValue ( mockSuccessResponse ) ,
144161 } ) ;
145162
@@ -155,6 +172,7 @@ describe('getUsernames route', () => {
155172
156173 it ( 'should return the data from the CDP API with status 200' , async ( ) => {
157174 mockFetch . mockResolvedValueOnce ( {
175+ ok : true ,
158176 json : jest . fn ( ) . mockResolvedValue ( mockSuccessResponse ) ,
159177 } ) ;
160178
@@ -171,6 +189,7 @@ describe('getUsernames route', () => {
171189
172190 it ( 'should include authorization header with bearer token' , async ( ) => {
173191 mockFetch . mockResolvedValueOnce ( {
192+ ok : true ,
174193 json : jest . fn ( ) . mockResolvedValue ( mockSuccessResponse ) ,
175194 } ) ;
176195
@@ -192,6 +211,7 @@ describe('getUsernames route', () => {
192211
193212 it ( 'should include Content-Type header as application/json' , async ( ) => {
194213 mockFetch . mockResolvedValueOnce ( {
214+ ok : true ,
195215 json : jest . fn ( ) . mockResolvedValue ( mockSuccessResponse ) ,
196216 } ) ;
197217
@@ -241,6 +261,7 @@ describe('getUsernames route', () => {
241261 } ;
242262
243263 mockFetch . mockResolvedValueOnce ( {
264+ ok : true ,
244265 json : jest . fn ( ) . mockResolvedValue ( multipleItemsResponse ) ,
245266 } ) ;
246267
@@ -267,6 +288,7 @@ describe('getUsernames route', () => {
267288 } ;
268289
269290 mockFetch . mockResolvedValueOnce ( {
291+ ok : true ,
270292 json : jest . fn ( ) . mockResolvedValue ( emptyResponse ) ,
271293 } ) ;
272294
@@ -284,6 +306,7 @@ describe('getUsernames route', () => {
284306
285307 it ( 'should construct URL with limit parameter' , async ( ) => {
286308 mockFetch . mockResolvedValueOnce ( {
309+ ok : true ,
287310 json : jest . fn ( ) . mockResolvedValue ( mockSuccessResponse ) ,
288311 } ) ;
289312
0 commit comments