mirror of
https://github.com/acedanger/finance.git
synced 2025-12-05 22:50:12 -08:00
66 lines
2.3 KiB
TypeScript
66 lines
2.3 KiB
TypeScript
import { describe, expect, it } from 'vitest';
|
|
import { GET as getAccount } from '../pages/api/accounts/[id]/index';
|
|
import { GET as listTransactions } from '../pages/api/accounts/[id]/transactions/index';
|
|
import { GET as listAccounts } from '../pages/api/accounts/index';
|
|
import { createMockAPIContext } from './setup';
|
|
|
|
describe('Accounts API', () => {
|
|
describe('GET /api/accounts', () => {
|
|
it('should return all accounts', async () => {
|
|
const response = await listAccounts(createMockAPIContext());
|
|
const accounts = await response.json();
|
|
|
|
expect(response.status).toBe(200);
|
|
expect(accounts).toHaveLength(2);
|
|
expect(accounts[0]).toHaveProperty('id', '1');
|
|
expect(accounts[1]).toHaveProperty('id', '2');
|
|
});
|
|
});
|
|
|
|
describe('GET /api/accounts/:id', () => {
|
|
it('should return a specific account', async () => {
|
|
const response = await getAccount(
|
|
createMockAPIContext({ params: { id: '1' } }) as APIContext,
|
|
);
|
|
const account = await response.json();
|
|
|
|
expect(response.status).toBe(200);
|
|
expect(account).toHaveProperty('id', '1');
|
|
expect(account).toHaveProperty('name', 'Test Checking');
|
|
});
|
|
|
|
it('should return 404 for non-existent account', async () => {
|
|
const response = await getAccount(
|
|
createMockAPIContext({ params: { id: '999' } }) as APIContext,
|
|
);
|
|
const error = await response.json();
|
|
|
|
expect(response.status).toBe(404);
|
|
expect(error).toHaveProperty('error', 'Account not found');
|
|
});
|
|
});
|
|
|
|
describe('GET /api/accounts/:id/transactions', () => {
|
|
it('should return transactions for an account', async () => {
|
|
const response = await listTransactions(
|
|
createMockAPIContext({ params: { id: '1' } }) as APIContext,
|
|
);
|
|
const transactions = await response.json();
|
|
|
|
expect(response.status).toBe(200);
|
|
expect(transactions).toHaveLength(1);
|
|
expect(transactions[0]).toHaveProperty('accountId', '1');
|
|
});
|
|
|
|
it('should return empty array for account with no transactions', async () => {
|
|
const response = await listTransactions(
|
|
createMockAPIContext({ params: { id: '999' } }) as APIContext,
|
|
);
|
|
const transactions = await response.json();
|
|
|
|
expect(response.status).toBe(200);
|
|
expect(transactions).toHaveLength(0);
|
|
});
|
|
});
|
|
});
|