test: cover portfolio UI API contract
This commit is contained in:
@@ -1,11 +1,12 @@
|
||||
{
|
||||
"name": "@family-budget/frontend",
|
||||
"version": "0.15.0",
|
||||
"version": "0.15.1",
|
||||
"private": true,
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"dev": "vite",
|
||||
"build": "tsc -b && vite build",
|
||||
"test:portfolio": "tsx src/api/portfolio.test.ts",
|
||||
"preview": "vite preview"
|
||||
},
|
||||
"dependencies": {
|
||||
|
||||
17
frontend/src/api/portfolio.test.ts
Normal file
17
frontend/src/api/portfolio.test.ts
Normal file
@@ -0,0 +1,17 @@
|
||||
import assert from 'node:assert/strict';
|
||||
import { getPortfolioHistory, getPortfolioOverview, getPortfolioPerformance } from './portfolio';
|
||||
|
||||
const calls: string[] = [];
|
||||
const originalFetch = globalThis.fetch;
|
||||
globalThis.fetch = async (input) => {
|
||||
calls.push(String(input));
|
||||
return new Response(JSON.stringify({ accounts: [] }), { status: 200, headers: { 'Content-Type': 'application/json' } });
|
||||
};
|
||||
|
||||
try {
|
||||
await Promise.all([getPortfolioOverview(), getPortfolioHistory(), getPortfolioPerformance()]);
|
||||
assert.deepEqual(calls.sort(), ['/api/portfolio', '/api/portfolio/history', '/api/portfolio/performance']);
|
||||
console.log('portfolio API contract: OK');
|
||||
} finally {
|
||||
globalThis.fetch = originalFetch;
|
||||
}
|
||||
Reference in New Issue
Block a user