Skip to content
This repository was archived by the owner on Mar 17, 2026. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 25 additions & 2 deletions apps/web/app/(basenames)/api/basenames/getUsernames/route.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,24 @@ describe('getUsernames route', () => {
const data = (await response.json()) as ManagedAddressesResponse | { error: string };

expect(response.status).toBe(400);
expect(data).toEqual({ error: 'No address provided' });
expect(data).toEqual({ error: 'Invalid address provided' });
});

it('should return 400 when an invalid address is provided', async () => {
const request = new NextRequest(
'https://www.base.org/api/basenames/getUsernames?address=0x123'
);

const response = await GET(request);
const data = (await response.json()) as ManagedAddressesResponse | { error: string };

expect(response.status).toBe(400);
expect(data).toEqual({ error: 'Invalid address provided' });
});

it('should return 400 when an invalid network is provided', async () => {
const request = new NextRequest(
'https://www.base.org/api/basenames/getUsernames?address=0x123&network=invalid-network'
'https://www.base.org/api/basenames/getUsernames?address=0x1234567890123456789012345678901234567890&network=invalid-network'
);

const response = await GET(request);
Expand All @@ -67,6 +79,7 @@ describe('getUsernames route', () => {

it('should default to base-mainnet when no network is provided', async () => {
mockFetch.mockResolvedValueOnce({
ok: true,
json: jest.fn().mockResolvedValue(mockSuccessResponse),
});

Expand All @@ -89,6 +102,7 @@ describe('getUsernames route', () => {

it('should use base-mainnet when explicitly provided', async () => {
mockFetch.mockResolvedValueOnce({
ok: true,
json: jest.fn().mockResolvedValue(mockSuccessResponse),
});

Expand All @@ -106,6 +120,7 @@ describe('getUsernames route', () => {

it('should use base-sepolia when explicitly provided', async () => {
mockFetch.mockResolvedValueOnce({
ok: true,
json: jest.fn().mockResolvedValue(mockSuccessResponse),
});

Expand All @@ -123,6 +138,7 @@ describe('getUsernames route', () => {

it('should include page parameter in URL when provided', async () => {
mockFetch.mockResolvedValueOnce({
ok: true,
json: jest.fn().mockResolvedValue(mockSuccessResponse),
});

Expand All @@ -140,6 +156,7 @@ describe('getUsernames route', () => {

it('should not include page parameter when not provided', async () => {
mockFetch.mockResolvedValueOnce({
ok: true,
json: jest.fn().mockResolvedValue(mockSuccessResponse),
});

Expand All @@ -155,6 +172,7 @@ describe('getUsernames route', () => {

it('should return the data from the CDP API with status 200', async () => {
mockFetch.mockResolvedValueOnce({
ok: true,
json: jest.fn().mockResolvedValue(mockSuccessResponse),
});

Expand All @@ -171,6 +189,7 @@ describe('getUsernames route', () => {

it('should include authorization header with bearer token', async () => {
mockFetch.mockResolvedValueOnce({
ok: true,
json: jest.fn().mockResolvedValue(mockSuccessResponse),
});

Expand All @@ -192,6 +211,7 @@ describe('getUsernames route', () => {

it('should include Content-Type header as application/json', async () => {
mockFetch.mockResolvedValueOnce({
ok: true,
json: jest.fn().mockResolvedValue(mockSuccessResponse),
});

Expand Down Expand Up @@ -241,6 +261,7 @@ describe('getUsernames route', () => {
};

mockFetch.mockResolvedValueOnce({
ok: true,
json: jest.fn().mockResolvedValue(multipleItemsResponse),
});

Expand All @@ -267,6 +288,7 @@ describe('getUsernames route', () => {
};

mockFetch.mockResolvedValueOnce({
ok: true,
json: jest.fn().mockResolvedValue(emptyResponse),
});

Expand All @@ -284,6 +306,7 @@ describe('getUsernames route', () => {

it('should construct URL with limit parameter', async () => {
mockFetch.mockResolvedValueOnce({
ok: true,
json: jest.fn().mockResolvedValue(mockSuccessResponse),
});

Expand Down
1 change: 0 additions & 1 deletion apps/web/next-env.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/// <reference types="next" />
/// <reference types="next/image-types/global" />
/// <reference path="./.next/types/routes.d.ts" />

// NOTE: This file should not be edited
// see https://nextjs.org/docs/app/api-reference/config/typescript for more information.