refactor: Reorganize imports and improve code consistency across components and API routes

This commit is contained in:
GitHub Copilot
2025-05-05 06:59:13 -04:00
parent d8a70e0f08
commit ad6693d1d7
14 changed files with 87 additions and 95 deletions

View File

@@ -1,13 +1,14 @@
import { describe, it, expect } from 'vitest';
import { GET as listAccounts } from '../pages/api/accounts/index';
import { GET as getAccount } from '../pages/api/accounts/[id]/index';
import { GET as listTransactions } from '../pages/api/accounts/[id]/transactions/index';
import type { APIContext } from 'astro';
import { describe, expect, it } from 'vitest';
import { listAccounts } from '../pages/api/accounts';
import { getAccount } from '../pages/api/accounts/[id]';
import { listTransactions } from '../pages/api/accounts/[id]/transactions';
import { createMockAPIContext } from './setup';
describe('Accounts API', () => {
describe('GET /api/accounts', () => {
it('should return all accounts', async () => {
const response = await listAccounts(createMockAPIContext() as any);
const response = await listAccounts(createMockAPIContext());
const accounts = await response.json();
expect(response.status).toBe(200);
@@ -19,7 +20,9 @@ describe('Accounts API', () => {
describe('GET /api/accounts/:id', () => {
it('should return a specific account', async () => {
const response = await getAccount(createMockAPIContext({ params: { id: '1' } }) as any);
const response = await getAccount(
createMockAPIContext({ params: { id: '1' } }) as APIContext,
);
const account = await response.json();
expect(response.status).toBe(200);
@@ -28,7 +31,9 @@ describe('Accounts API', () => {
});
it('should return 404 for non-existent account', async () => {
const response = await getAccount(createMockAPIContext({ params: { id: '999' } }) as any);
const response = await getAccount(
createMockAPIContext({ params: { id: '999' } }) as APIContext,
);
const error = await response.json();
expect(response.status).toBe(404);
@@ -38,7 +43,9 @@ describe('Accounts API', () => {
describe('GET /api/accounts/:id/transactions', () => {
it('should return transactions for an account', async () => {
const response = await listTransactions(createMockAPIContext({ params: { id: '1' } }) as any);
const response = await listTransactions(
createMockAPIContext({ params: { id: '1' } }) as APIContext,
);
const transactions = await response.json();
expect(response.status).toBe(200);
@@ -48,7 +55,7 @@ describe('Accounts API', () => {
it('should return empty array for account with no transactions', async () => {
const response = await listTransactions(
createMockAPIContext({ params: { id: '999' } }) as any
createMockAPIContext({ params: { id: '999' } }) as APIContext,
);
const transactions = await response.json();