Files
nas-tools/dashboard/frontend/tests/integration/conversations.test.js
Gan, Jimmy 01fcb53a3a
Deploy Dashboard (Dev) / deploy-dev (push) Failing after 2m0s
Run Tests / Backend Tests (push) Failing after 4m26s
Run Tests / Frontend Tests (push) Failing after 49s
Run Tests / Test Summary (push) Failing after 15s
Run Tests / Backend Tests (pull_request) Failing after 6m9s
Run Tests / Frontend Tests (pull_request) Failing after 3m54s
Run Tests / Test Summary (pull_request) Failing after 15s
feat: add comprehensive testing mechanism for dashboard features
- Add smoke test script for post-deployment verification
- Add health monitoring script with Telegram alerts
- Add backend integration tests for conversation tracker API
- Add frontend tests to verify correct API paths
- Update CI/CD workflows to enforce test failures and run smoke tests
- Add comprehensive testing documentation

This testing mechanism will catch issues like the double /api/ prefix bug
before they reach users.
2026-04-19 21:54:13 +08:00

131 lines
3.5 KiB
JavaScript

import { describe, it, expect, beforeEach, vi } from 'vitest';
import { get, post } from '../../src/lib/api.js';
describe('Conversation Tracker API Paths', () => {
beforeEach(() => {
// Mock fetch globally
global.fetch = vi.fn();
// Mock localStorage
global.localStorage = {
getItem: vi.fn(() => 'mock-token'),
setItem: vi.fn(),
removeItem: vi.fn(),
};
});
it('should call /api/conversations/dates without double prefix', async () => {
global.fetch.mockResolvedValueOnce({
ok: true,
json: async () => ['2026-04-19'],
headers: new Headers(),
});
await get('/conversations/dates');
expect(global.fetch).toHaveBeenCalledWith(
expect.stringContaining('/api/conversations/dates'),
expect.any(Object)
);
expect(global.fetch).not.toHaveBeenCalledWith(
expect.stringContaining('/api/api/'),
expect.any(Object)
);
});
it('should call /api/conversations/summary/:date correctly', async () => {
global.fetch.mockResolvedValueOnce({
ok: true,
json: async () => ({ summary: 'test' }),
headers: new Headers(),
});
await get('/conversations/summary/2026-04-19');
expect(global.fetch).toHaveBeenCalledWith(
expect.stringContaining('/api/conversations/summary/2026-04-19'),
expect.any(Object)
);
expect(global.fetch).not.toHaveBeenCalledWith(
expect.stringContaining('/api/api/'),
expect.any(Object)
);
});
it('should call /api/conversations/list correctly', async () => {
global.fetch.mockResolvedValueOnce({
ok: true,
json: async () => [],
headers: new Headers(),
});
await get('/conversations/list?date=2026-04-19');
expect(global.fetch).toHaveBeenCalledWith(
expect.stringContaining('/api/conversations/list?date=2026-04-19'),
expect.any(Object)
);
});
it('should call search endpoint correctly', async () => {
global.fetch.mockResolvedValueOnce({
ok: true,
json: async () => [],
headers: new Headers(),
});
await get('/conversations/search?q=test');
expect(global.fetch).toHaveBeenCalledWith(
expect.stringContaining('/api/conversations/search?q=test'),
expect.any(Object)
);
});
it('should call stats endpoint correctly', async () => {
global.fetch.mockResolvedValueOnce({
ok: true,
json: async () => ({ top_projects: [], top_tools: [] }),
headers: new Headers(),
});
await get('/conversations/stats');
expect(global.fetch).toHaveBeenCalledWith(
expect.stringContaining('/api/conversations/stats'),
expect.any(Object)
);
});
it('should call conversation detail endpoint correctly', async () => {
global.fetch.mockResolvedValueOnce({
ok: true,
json: async () => ({ session_id: 'test' }),
headers: new Headers(),
});
await get('/conversations/test-session-id');
expect(global.fetch).toHaveBeenCalledWith(
expect.stringContaining('/api/conversations/test-session-id'),
expect.any(Object)
);
});
it('should call trigger endpoint correctly', async () => {
global.fetch.mockResolvedValueOnce({
ok: true,
json: async () => ({ status: 'ok' }),
headers: new Headers(),
});
await post('/conversations/trigger');
expect(global.fetch).toHaveBeenCalledWith(
expect.stringContaining('/api/conversations/trigger'),
expect.objectContaining({
method: 'POST',
})
);
});
});